]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added unittest for keyboard events for Dropdown.
authorMarius Olbertz <marius.olbertz@gmail.com>
Tue, 10 Oct 2017 16:37:30 +0000 (18:37 +0200)
committerMarius Olbertz <marius.olbertz@gmail.com>
Tue, 10 Oct 2017 16:37:30 +0000 (18:37 +0200)
test/javascript/components/dropdown.js

index 608ce0087969acbd60185adc0b3a9744d8f72df5..9162635c9251c3746b646d12252fa0e0b340c545 100644 (file)
@@ -97,4 +97,34 @@ describe('Dropdown', function() {
       }, 2);
     });
   });
+
+  describe('keyboard events', function () {
+    it('opens Dropdown on SPACE', function() {
+      $dropdownController = $(getDropdownController()).appendTo('body');
+      $dropdownContainer = $(getDropdownContainer()).appendTo('body');
+      plugin = new Foundation.Dropdown($dropdownContainer, {});
+      $dropdownController.focus()
+        .trigger(window.mockKeyboardEvent('SPACE'));
+
+      $dropdownContainer.should.be.visible;
+    });
+    it('focuses Dropdown on SPACE', function() {
+      $dropdownController = $(getDropdownController()).appendTo('body');
+      $dropdownContainer = $(getDropdownContainer()).appendTo('body');
+      plugin = new Foundation.Dropdown($dropdownContainer, {});
+      $dropdownController.focus()
+        .trigger(window.mockKeyboardEvent('SPACE'));
+
+      document.activeElement.should.be.equal($dropdownContainer[0]);
+    });
+    it('does not focus Dropdown when anchor is an input', function() {
+      $dropdownController = $('<input type="text" data-toggle="my-dropdown">').appendTo('body');
+      $dropdownContainer = $(getDropdownContainer()).appendTo('body');
+      plugin = new Foundation.Dropdown($dropdownContainer, {});
+      $dropdownController.focus()
+        .trigger(window.mockKeyboardEvent('SPACE'));
+
+      document.activeElement.should.be.equal($dropdownController[0]);
+    });
+  })
 });