]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added unit tests for trapFocus option for Dropdown.
authorMarius Olbertz <marius.olbertz@gmail.com>
Sat, 5 Nov 2016 14:40:34 +0000 (15:40 +0100)
committerMarius Olbertz <marius.olbertz@gmail.com>
Sat, 5 Nov 2016 14:40:34 +0000 (15:40 +0100)
test/javascript/components/dropdown.js

index 42f2f6cad0e51b1f1bd6ba7d1bae5ca71dcb1b80..ee0da373eb578a6cf6c4ace28417d284ff6436f4 100644 (file)
@@ -25,6 +25,37 @@ describe('Dropdown', function() {
     });
   });
 
+  describe('open()', function() {
+    it('traps focus if trapFocus option is true', function() {
+      $dropdownController = $(getDropdownController()).appendTo('body');
+      $dropdownContainer = $(getDropdownContainer()).appendTo('body');
+      plugin = new Foundation.Dropdown($dropdownContainer, {trapFocus: true});
+
+      let spy = sinon.spy(Foundation.Keyboard, 'trapFocus');
+      plugin.open();
+
+      sinon.assert.called(spy);
+      Foundation.Keyboard.trapFocus.restore();
+    });
+  });
+
+  describe('close()', function() {
+    it('releases focus if trapFocus option is true', function() {
+      $dropdownController = $(getDropdownController()).appendTo('body');
+      $dropdownContainer = $(getDropdownContainer()).appendTo('body');
+      plugin = new Foundation.Dropdown($dropdownContainer, {trapFocus: true});
+
+      // Open it first...
+      plugin.open();
+
+      let spy = sinon.spy(Foundation.Keyboard, 'releaseFocus');
+      plugin.close();
+
+      sinon.assert.called(spy);
+      Foundation.Keyboard.releaseFocus.restore();
+    });
+  });
+
   describe('getPositionClass()', function() {
     it('has no orientation', function() {
       $dropdownController = $(getDropdownController()).appendTo('body');