From 87c3d4f0134203494178777d622b8fbb440401a8 Mon Sep 17 00:00:00 2001 From: Marius Olbertz Date: Tue, 10 Oct 2017 18:37:30 +0200 Subject: [PATCH] Added unittest for keyboard events for Dropdown. --- test/javascript/components/dropdown.js | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/javascript/components/dropdown.js b/test/javascript/components/dropdown.js index 608ce0087..9162635c9 100644 --- a/test/javascript/components/dropdown.js +++ b/test/javascript/components/dropdown.js @@ -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 = $('').appendTo('body'); + $dropdownContainer = $(getDropdownContainer()).appendTo('body'); + plugin = new Foundation.Dropdown($dropdownContainer, {}); + $dropdownController.focus() + .trigger(window.mockKeyboardEvent('SPACE')); + + document.activeElement.should.be.equal($dropdownController[0]); + }); + }) }); -- 2.47.2