]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added tests for keyboard events for Slider.
authorMarius Olbertz <marius.olbertz@gmail.com>
Wed, 19 Apr 2017 18:25:24 +0000 (20:25 +0200)
committerMarius Olbertz <marius.olbertz@gmail.com>
Wed, 19 Apr 2017 18:25:24 +0000 (20:25 +0200)
test/javascript/components/slider.js

index ffca592fccd743af13948d8d00901def627be8ae..f0ff93ee89ff9c96f3970e978fc83d05ef0099aa 100644 (file)
@@ -163,14 +163,77 @@ describe('Slider', function() {
 
       plugin.$handle.should.have.attr('aria-valuenow', plugin.$handle.attr('aria-valuemin'));
     });
-    it('sets value to maximum using END', function() {
+    it('increases value by step size on ARROW_RIGHT', function() {
       $html = $(template).appendTo('body');
-      plugin = new Foundation.Slider($html, {});
+      plugin = new Foundation.Slider($html, {
+        initialStart: 10,
+        step: 1
+      });
+
+      plugin.$handle.focus()
+        .trigger(window.mockKeyboardEvent('ARROW_RIGHT'));
+
+      plugin.$handle.should.have.attr('aria-valuenow', (10 + 1).toString());
+    });
+    it('increases value by step size on ARROW_UP', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {
+        initialStart: 10,
+        step: 1
+      });
+
+      plugin.$handle.focus()
+        .trigger(window.mockKeyboardEvent('ARROW_UP'));
+
+      plugin.$handle.should.have.attr('aria-valuenow', (10 + 1).toString());
+    });
+    it('decreases value by step size on ARROW_LEFT', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {
+        initialStart: 10,
+        step: 1
+      });
+
+      plugin.$handle.focus()
+        .trigger(window.mockKeyboardEvent('ARROW_LEFT'));
+
+      plugin.$handle.should.have.attr('aria-valuenow', (10 - 1).toString());
+    });
+    it('decreases value by step size on ARROW_DOWN', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {
+        initialStart: 10,
+        step: 1
+      });
+
+      plugin.$handle.focus()
+        .trigger(window.mockKeyboardEvent('ARROW_DOWN'));
+
+      plugin.$handle.should.have.attr('aria-valuenow', (10 - 1).toString());
+    });
+    it('decreases value by step size times 10 on SHIFT_AARROW_RIGHT', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {
+        initialStart: 10,
+        step: 1
+      });
+
+      plugin.$handle.focus()
+        .trigger(window.mockKeyboardEvent('ARROW_RIGHT', {shift: true}));
+
+      plugin.$handle.should.have.attr('aria-valuenow', (10 + 1 * 10).toString());
+    });
+    it('decreases value by step size times 10 on SHIFT_ARROW_LEFT', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {
+        initialStart: 10,
+        step: 1
+      });
 
       plugin.$handle.focus()
-        .trigger(window.mockKeyboardEvent('END'));
+        .trigger(window.mockKeyboardEvent('ARROW_LEFT', {shift: true}));
 
-      plugin.$handle.should.have.attr('aria-valuenow', plugin.$handle.attr('aria-valuemax'));
+      plugin.$handle.should.have.attr('aria-valuenow', (10 - 1 * 10).toString());
     });
   });
 });
\ No newline at end of file