]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added unit tests for trapFocus option for Offcanvas.
authorMarius Olbertz <marius.olbertz@gmail.com>
Sat, 5 Nov 2016 14:40:34 +0000 (15:40 +0100)
committerMarius Olbertz <marius.olbertz@gmail.com>
Sat, 5 Nov 2016 14:41:09 +0000 (15:41 +0100)
test/javascript/components/offcanvas.js

index 6df80d2ef353af6fc50fbe3e6cefd08ca521c7bd..3e940169e068ef771144be8d8acb629f3da63b77 100644 (file)
@@ -133,6 +133,21 @@ describe('Off Canvas', function() {
       plugin.open();
     });
 
+    it('traps focus if trapFocus option is true', function(done) {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {trapFocus: true});
+
+      let spy = sinon.spy(Foundation.Keyboard, 'trapFocus');
+
+      $html.one(Foundation.transitionend($html), function() {
+        sinon.assert.called(spy);
+        Foundation.Keyboard.trapFocus.restore();
+        done();
+      });
+
+      plugin.open();
+    });
+
 
     it('fires opened.zf.offcanvas event', function(done) {
       $html = $(template).appendTo('body');
@@ -185,8 +200,6 @@ describe('Off Canvas', function() {
       $html = $(template).appendTo('body');
       plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {});
 
-      
-
       $html.one(Foundation.transitionend($html), function() {
         $html.one('closed.zf.offcanvas', function() {
           done();
@@ -198,6 +211,23 @@ describe('Off Canvas', function() {
       // Open it first
       plugin.open();
     });
+
+    it('releases focus if trapFocus option is true', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {trapFocus: true});
+
+      $html.one(Foundation.transitionend($html), function() {
+        let spy = sinon.spy(Foundation.Keyboard, 'releaseFocus');
+
+        plugin.close();
+
+        sinon.assert.called(spy);
+        Foundation.Keyboard.releaseFocus.restore();
+      });
+
+      // Open it first...
+      plugin.open();
+    });
   });
 
   describe('toggle()', function() {