From: Marius Olbertz Date: Tue, 10 Oct 2017 16:37:30 +0000 (+0200) Subject: Added unittest for keyboard events for Dropdown. X-Git-Tag: v6.6.0~3^2~301^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87c3d4f01;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Added unittest for keyboard events for Dropdown. --- 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]); + }); + }) });