]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add a unit test to check if the carousel do not cycle when its parent isn't visible
authorJohann-S <johann.servoire@gmail.com>
Thu, 17 Aug 2017 16:29:15 +0000 (18:29 +0200)
committerJohann-S <johann.servoire@gmail.com>
Thu, 17 Aug 2017 16:48:14 +0000 (17:48 +0100)
js/tests/unit/carousel.js

index cef4615761fc810c690de46365e17b610d376dad..b110fbd65d1c192f453071a8717e33cab85dd82c 100644 (file)
@@ -879,4 +879,43 @@ $(function () {
       }, 80)
     }, 80)
   })
+
+  QUnit.test('Should not go to the next item when the parent of the carousel is not visible', function (assert) {
+    assert.expect(2)
+    var done = assert.async()
+    var html = '<div id="parent" style="display: none;">'
+             + '  <div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">'
+             + '    <div class="carousel-inner">'
+             + '      <div id="firstItem" class="carousel-item active">'
+             + '        <img alt="">'
+             + '      </div>'
+             + '      <div class="carousel-item">'
+             + '        <img alt="">'
+             + '      </div>'
+             + '      <div class="carousel-item">'
+             + '        <img alt="">'
+             + '      </div>'
+             + '    <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a>'
+             + '    <a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a>'
+             + '  </div>'
+             + '</div>'
+    var $html = $(html)
+    $html.appendTo('#qunit-fixture')
+    var $parent = $html.find('#parent')
+    var $carousel = $html.find('#myCarousel')
+    $carousel.bootstrapCarousel()
+    var $firstItem = $('#firstItem')
+
+    setTimeout(function () {
+      assert.ok($firstItem.hasClass('active'))
+      $carousel.bootstrapCarousel('dispose')
+      $parent.attr('style', 'visibility: hidden;')
+      $carousel.bootstrapCarousel()
+
+      setTimeout(function () {
+        assert.ok($firstItem.hasClass('active'))
+        done()
+      }, 80)
+    }, 80)
+  })
 })