From 38324157cb2a99efb033ef7e7f6318bbd4c303f0 Mon Sep 17 00:00:00 2001 From: David Epely Date: Fri, 13 May 2016 14:52:37 +0200 Subject: [PATCH] [JS-dropdown] no-reggression unit test for getPosition() --- test/javascript/components/dropdown.js | 65 ++++++++++++++++++++------ 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/test/javascript/components/dropdown.js b/test/javascript/components/dropdown.js index 18c62daa5..7c1bdf47f 100644 --- a/test/javascript/components/dropdown.js +++ b/test/javascript/components/dropdown.js @@ -1,20 +1,55 @@ describe('Dropdown', function() { - var plugin; - var $html; + let plugin; + let $dropdownController; + let $dropdownContainer; - // afterEach(function() { - // plugin.destroy(); - // $html.remove(); - // }); + const getDropdownController = (buttonClasses = '') => + ``; + const getDropdownContainer = (dropdownClasses = '') => + `
Dropdown
`; - describe('constructor()', function() { - // it('', function() { - // $html = $('').appendTo('body'); - // plugin = new Foundation.Dropdown($html, {}); + afterEach(function() { + plugin.destroy(); + $dropdownController.remove(); + $dropdownContainer.remove(); + }); - // plugin.$element.should.be.an('object'); - // plugin.options.should.be.an('object'); - // }); - }); + describe('constructor()', function() { + it('stores the element & plugin options', function() { + $dropdownController = $(getDropdownController()).appendTo('body'); + $dropdownContainer = $(getDropdownContainer()).appendTo('body'); + plugin = new Foundation.Dropdown($dropdownContainer, {}); -}); \ No newline at end of file + plugin.$element.should.be.an('object'); + plugin.options.should.be.an('object'); + }); + }); + + describe('getPositionClass()', function() { + it('has no orientation', function() { + $dropdownController = $(getDropdownController()).appendTo('body'); + $dropdownContainer = $(getDropdownContainer()).appendTo('body'); + plugin = new Foundation.Dropdown($dropdownContainer, {}); + + plugin.getPositionClass().trim().should.equal(''); + }); + + it('has vertical position', function() { + $dropdownController = $(getDropdownController()).appendTo('body'); + $dropdownContainer = $(getDropdownContainer('custom-style-before bottom custom-style-after')) + .appendTo('body'); + plugin = new Foundation.Dropdown($dropdownContainer, {}); + + plugin.getPositionClass().trim().should.equal('bottom'); + }); + + it('has horizontal position', function() { + $dropdownController = $(getDropdownController('custom-style-before float-right custom-style-after')) + .appendTo('body'); + $dropdownContainer = $(getDropdownContainer()).appendTo('body'); + plugin = new Foundation.Dropdown($dropdownContainer, {}); + + plugin.getPositionClass().trim().should.equal('right'); + }); + }); +}); -- 2.47.2