]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added tests for keyboard events for Accordion.
authorMarius Olbertz <marius.olbertz@gmail.com>
Thu, 20 Apr 2017 15:28:43 +0000 (17:28 +0200)
committerMarius Olbertz <marius.olbertz@gmail.com>
Thu, 20 Apr 2017 15:28:43 +0000 (17:28 +0200)
test/javascript/components/accordion.js

index c4837c5e383afec1ce2d1641d5068a6d8318d891..5ee78e112f04fe644fc2386866343fabb719ff4d 100644 (file)
@@ -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