From 6ddeb2bcaf13941b4a969a83c49b341cc132c830 Mon Sep 17 00:00:00 2001 From: Marius Olbertz Date: Thu, 20 Apr 2017 17:28:43 +0200 Subject: [PATCH] Added tests for keyboard events for Accordion. --- test/javascript/components/accordion.js | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) 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 -- 2.47.3