From: Marius Olbertz Date: Thu, 20 Apr 2017 15:28:43 +0000 (+0200) Subject: Added tests for keyboard events for Accordion. X-Git-Tag: v6.4.0-rc1~50^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ddeb2bcaf13941b4a969a83c49b341cc132c830;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Added tests for keyboard events for Accordion. --- diff --git a/test/javascript/components/accordion.js b/test/javascript/components/accordion.js index c4837c5e3..5ee78e112 100644 --- a/test/javascript/components/accordion.js +++ b/test/javascript/components/accordion.js @@ -139,4 +139,51 @@ describe('Accordion', function() { $html.find('.accordion-content').eq(0).should.have.attr('aria-hidden', 'false'); }); }); + + describe('keyboard events', function() { + it('opens next panel on ARROW_DOWN', function() { + $html = $(template).appendTo('body'); + plugin = new Foundation.Accordion($html, {}); + + $html.find('.accordion-title').eq(0).focus() + .trigger(window.mockKeyboardEvent('ARROW_DOWN')); + + $html.find('.accordion-content').eq(1).should.be.visible; + $html.find('.accordion-content').eq(1).should.have.attr('aria-hidden', 'false'); + // Check if focus was moved + $html.find('.accordion-title').eq(1)[0].should.be.equal(document.activeElement); + }); + it('opens previous panel on ARROW_UP', function() { + $html = $(template).appendTo('body'); + plugin = new Foundation.Accordion($html, {}); + + $html.find('.accordion-title').eq(2).focus() + .trigger(window.mockKeyboardEvent('ARROW_UP')); + + $html.find('.accordion-content').eq(1).should.be.visible; + $html.find('.accordion-content').eq(1).should.have.attr('aria-hidden', 'false'); + // Check if focus was moved + $html.find('.accordion-title').eq(1)[0].should.be.equal(document.activeElement); + }); + it('opens related panel on ENTER', function() { + $html = $(template).appendTo('body'); + plugin = new Foundation.Accordion($html, {}); + + $html.find('.accordion-title').eq(1).focus() + .trigger(window.mockKeyboardEvent('ENTER')); + + $html.find('.accordion-content').eq(1).should.be.visible; + $html.find('.accordion-content').eq(1).should.have.attr('aria-hidden', 'false'); + }); + it('opens related panel on SPACE', function() { + $html = $(template).appendTo('body'); + plugin = new Foundation.Accordion($html, {}); + + $html.find('.accordion-title').eq(1).focus() + .trigger(window.mockKeyboardEvent('SPACE')); + + $html.find('.accordion-content').eq(1).should.be.visible; + $html.find('.accordion-content').eq(1).should.have.attr('aria-hidden', 'false'); + }); + }); }); \ No newline at end of file