]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
[JS-dropdown] no-reggression unit test for getPosition() 8785/head
authorDavid Epely <esion99@gmail.com>
Fri, 13 May 2016 12:52:37 +0000 (14:52 +0200)
committerDavid Epely <esion99@gmail.com>
Tue, 17 May 2016 04:50:33 +0000 (06:50 +0200)
test/javascript/components/dropdown.js

index 18c62daa5e4d14e2e8258bdac3568e09849f8f8b..7c1bdf47f78049931fb1e557b3f59daec3984727 100644 (file)
@@ -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 = '') =>
+    `<button class="${buttonClasses}" type="button" data-toggle="my-dropdown">toggle</button>`;
+  const getDropdownContainer = (dropdownClasses = '') =>
+    `<div class="${dropdownClasses}" data-dropdown id="my-dropdown">Dropdown</div>`;
 
-       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');
+    });
+  });
+});