]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
add unit test for affix-top for padding issue
authorNick O'Donoghue <nick.od@me.com>
Mon, 17 Nov 2014 00:42:55 +0000 (00:42 +0000)
committerChris Rebert <code@rebertia.com>
Tue, 18 Nov 2014 02:17:40 +0000 (18:17 -0800)
js/tests/unit/affix.js

index ef6ef74b91590b854e74da3391cba3b3a0e30df0..2e82a7dbfb18cf88df6c7f578d3f59f9b16b4f91 100644 (file)
@@ -68,4 +68,33 @@ $(function () {
       }, 16) // for testing in a browser
     }, 0)
   })
+
+  test('should affix-top when scrolling up to offset when parent has padding', function () {
+    stop()
+
+    var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">'
+        + '<div id="affixTopTarget">'
+        + '<p>Testing affix-top class is added</p>'
+        + '</div>'
+        + '<div style="height: 1000px; display: block;"/>'
+        + '</div>'
+    $(templateHTML).appendTo(document.body)
+
+    $('#affixTopTarget')
+      .bootstrapAffix({
+        offset: { top: 120, bottom: 0 }
+      })
+      .on('affixed-top.bs.affix', function () {
+        ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied')
+        start()
+      })
+
+    setTimeout(function () {
+      window.scrollTo(0, document.body.scrollHeight)
+
+      setTimeout(function () {
+        window.scroll(0, 119)
+      }, 250)
+    }, 250)
+  })
 })