]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
test: add unit tests for the Orbit implicit/explicit active slide label moving 11434/head
authorNicolas Coden <nicolas@ncoden.fr>
Sun, 5 Aug 2018 15:48:48 +0000 (17:48 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sun, 5 Aug 2018 15:48:48 +0000 (17:48 +0200)
test/javascript/components/orbit.js

index 6cd15ba5031a6fc2fad9fcffd3be544811c41f3f..9a1a4584053c349305abc5b5439bc3aee4cc968f 100644 (file)
@@ -19,7 +19,10 @@ describe('Orbit', function() {
       </li>
     </ul>
     <nav class="orbit-bullets">
-      <button class="is-active" data-slide="0"><span class="show-for-sr">First slide details.</span><span class="show-for-sr">Current Slide</span></button>
+      <button class="is-active" data-slide="0">
+        <span class="show-for-sr">First slide details.</span>
+        <span class="show-for-sr" data-slide-active-label>Current Slide</span>
+      </button>
       <button data-slide="1"><span class="show-for-sr">Second slide details.</span></button>
       <button data-slide="2"><span class="show-for-sr">Third slide details.</span></button>
       <button data-slide="3"><span class="show-for-sr">Fourth slide details.</span></button>
@@ -141,7 +144,7 @@ describe('Orbit', function() {
   });
 
   describe('updateBullets()', function() {
-    it('updates the bullets', function() {
+    it('updates the active bullet', function() {
       $html = $(template).appendTo('body');
       plugin = new Foundation.Orbit($html, {});
 
@@ -150,6 +153,41 @@ describe('Orbit', function() {
       $html.find('.orbit-bullets [data-slide]').eq(0).should.not.have.class('is-active');
       $html.find('.orbit-bullets [data-slide]').eq(1).should.have.class('is-active');
     });
+
+    it('moves the explicit active slide label to the active bullet', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Orbit($html, {});
+
+      plugin.changeSlide(true);
+
+      $html.find('.orbit-bullets [data-slide]').eq(0).children('span').length.should.equal(1);
+      $html.find('.orbit-bullets [data-slide]').eq(1).children('span').length.should.equal(2);
+    });
+
+    it('moves the implicit active slide label to the active bullet', function() {
+      $html = $(template).appendTo('body');
+      // Remove the explicit attribute to make this test
+      // The "implicit" active slide label is the exceeding `span` element
+      $html.find('[data-slide-active-label]').removeAttr('data-slide-active-label');
+      plugin = new Foundation.Orbit($html, {});
+
+      plugin.changeSlide(true);
+
+      $html.find('.orbit-bullets [data-slide]').eq(0).children('span').length.should.equal(1);
+      $html.find('.orbit-bullets [data-slide]').eq(1).children('span').length.should.equal(2);
+    });
+
+    it('moves nothing if there is no implicit active slide label', function() {
+      $html = $(template).appendTo('body');
+      // Remove the active slide label to make this test
+      $html.find('[data-slide-active-label]').remove();
+      plugin = new Foundation.Orbit($html, {});
+
+      plugin.changeSlide(true);
+
+      $html.find('.orbit-bullets [data-slide]').eq(0).children('span').length.should.equal(1);
+      $html.find('.orbit-bullets [data-slide]').eq(1).children('span').length.should.equal(1);
+    });
   });
 
   describe('events()', function() {
@@ -217,4 +255,4 @@ describe('Orbit', function() {
       sinon.assert.calledWith(spy, false);
     });
   });
-});
\ No newline at end of file
+});