From: Marius Olbertz Date: Sat, 5 Nov 2016 14:40:34 +0000 (+0100) Subject: Added unit tests for trapFocus option for Dropdown. X-Git-Tag: v6.3-rc1~6^2~2^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb6e768efccd8926a44f0aafc65f809d3193d87b;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Added unit tests for trapFocus option for Dropdown. --- diff --git a/test/javascript/components/dropdown.js b/test/javascript/components/dropdown.js index 42f2f6cad..ee0da373e 100644 --- a/test/javascript/components/dropdown.js +++ b/test/javascript/components/dropdown.js @@ -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');