From 7627b24c1e6aa5301ee3f525dd931c2852e7ff0a Mon Sep 17 00:00:00 2001 From: breaddevil Date: Sun, 4 May 2014 11:24:31 +0200 Subject: [PATCH] replace js scrollspy test for default behavior --- js/tests/unit/scrollspy.js | 54 ++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 90c95d7691..a36749f2e8 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -25,23 +25,6 @@ $(function () { ok($(document.body).bootstrapScrollspy()[0] == document.body, 'document.body returned') }) - test('should switch active class on scroll', function () { - var sectionHTML = '
', - topbarHTML = '
' + - '
' + - '
' + - '

Bootstrap

' + - '
  • Overview
  • ' + - '' + - '
    ' + - '
    ' + - '
    ', - $topbar = $(topbarHTML).bootstrapScrollspy() - - $(sectionHTML).append('#qunit-fixture') - ok($topbar.find('.active', true)) - }) - test('should only switch active class on current target', function () { var sectionHTML = '
    ' + '
    ' + @@ -78,4 +61,41 @@ $(function () { $scrollSpy.scrollTop(350); ok($section.hasClass('active'), 'Active class still on root node') }) + + test('should add the active class to the correct element', function () { + var navbarHtml = + '' + var contentHtml = + '
    ' + + '
    div 1
    ' + + '
    div 2
    ' + + '
    ' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({offset: 0, target: '.navbar'}) + + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = $content.scrollTop() + $(target).position().top + stop() + $content.one('scroll', function () { + ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + start() + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#li-1', '#div-1')) + .then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') }) + }) + })