From f9b61ff8349c1380521cf71b0067569d9f54552d Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Sat, 28 Apr 2018 17:54:55 +0200 Subject: [PATCH] chore: clean focus after tests involving focus See https://github.com/zurb/foundation-sites/issues/11074 --- test/javascript/components/accordion.js | 5 +++-- test/javascript/components/drilldown.js | 7 ++++--- test/javascript/components/dropdown.js | 1 + test/javascript/components/dropdownMenu.js | 1 + test/javascript/components/offcanvas.js | 3 ++- test/javascript/components/reveal.js | 1 + test/javascript/util/keyboard.js | 4 ++++ 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/javascript/components/accordion.js b/test/javascript/components/accordion.js index 5ee78e112..362a8fef1 100644 --- a/test/javascript/components/accordion.js +++ b/test/javascript/components/accordion.js @@ -27,6 +27,7 @@ describe('Accordion', function() { afterEach(function() { plugin.destroy(); + document.activeElement.blur(); $html.remove(); }); @@ -139,7 +140,7 @@ 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'); @@ -186,4 +187,4 @@ describe('Accordion', function() { $html.find('.accordion-content').eq(1).should.have.attr('aria-hidden', 'false'); }); }); -}); \ No newline at end of file +}); diff --git a/test/javascript/components/drilldown.js b/test/javascript/components/drilldown.js index 7c13921a1..d3e83187e 100644 --- a/test/javascript/components/drilldown.js +++ b/test/javascript/components/drilldown.js @@ -28,6 +28,7 @@ describe('Drilldown Menu', function() { afterEach(function() { plugin.destroy(); + document.activeElement.blur(); $html.remove(); }); @@ -177,7 +178,7 @@ describe('Drilldown Menu', function() { // Open one first plugin._show($html.find('li.is-drilldown-submenu-parent').eq(2)); - + $html.one('closed.zf.drilldown', function() { $html.find('ul[data-submenu].is-active').each(function() { // Checking with .be.hidden is not possible because they don't have display: block but z-index: -1 @@ -310,7 +311,7 @@ describe('Drilldown Menu', function() { $html.find('> li:nth-child(1) > a').focus() .trigger(window.mockKeyboardEvent('ARROW_RIGHT')); - + setTimeout(function() { // Timeout to make sure transition has ended $html.find('> li:nth-child(1) > ul > li[data-is-parent-link] a')[0].should.be.equal(document.activeElement); done(); @@ -329,4 +330,4 @@ describe('Drilldown Menu', function() { $html.find('> li:nth-child(1) > ul').should.have.class('is-closing'); }); }); -}); \ No newline at end of file +}); diff --git a/test/javascript/components/dropdown.js b/test/javascript/components/dropdown.js index 9f7696a24..e0331b060 100644 --- a/test/javascript/components/dropdown.js +++ b/test/javascript/components/dropdown.js @@ -17,6 +17,7 @@ describe('Dropdown', function() { afterEach(function() { plugin.destroy(); + document.activeElement.blur(); $dropdownController.remove(); $dropdownContainer.remove(); }); diff --git a/test/javascript/components/dropdownMenu.js b/test/javascript/components/dropdownMenu.js index bd91d8dd5..e98885520 100644 --- a/test/javascript/components/dropdownMenu.js +++ b/test/javascript/components/dropdownMenu.js @@ -42,6 +42,7 @@ describe('Dropdown Menu', function () { afterEach(function () { plugin.destroy(); + document.activeElement.blur(); $html.remove(); }); diff --git a/test/javascript/components/offcanvas.js b/test/javascript/components/offcanvas.js index c6fb3e4e1..12526d8ba 100644 --- a/test/javascript/components/offcanvas.js +++ b/test/javascript/components/offcanvas.js @@ -34,6 +34,7 @@ describe('Off Canvas', function() { afterEach(function() { plugin.destroy(); + document.activeElement.blur(); $html.remove(); }); @@ -252,7 +253,7 @@ describe('Off Canvas', function() { plugin.toggle(); }); }); - + describe('keyboard events', function() { it('closes Off Canvas on ESCAPE', function(done) { $html = $(template).appendTo('body'); diff --git a/test/javascript/components/reveal.js b/test/javascript/components/reveal.js index 5e38b431b..1c20797a8 100644 --- a/test/javascript/components/reveal.js +++ b/test/javascript/components/reveal.js @@ -10,6 +10,7 @@ describe('Reveal', function() { afterEach(function() { plugin.destroy(); + document.activeElement.blur(); $html.remove(); }); diff --git a/test/javascript/util/keyboard.js b/test/javascript/util/keyboard.js index ecec0f520..836c69a0c 100644 --- a/test/javascript/util/keyboard.js +++ b/test/javascript/util/keyboard.js @@ -19,6 +19,10 @@ describe('Keyboard util', function() { 'ARROW_DOWN': 40 }; + afterEach(function() { + document.activeElement.blur(); + }); + it('exists on the Foundation API', function() { (window.Foundation.Keyboard).should.be.an('object'); }); -- 2.47.2