Skip to content

Commit

Permalink
Merge branch 'breaddevil-replace-scrollspy-default-behavior-test'
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Jul 6, 2014
2 parents 279c461 + b19719e commit cb19f4f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions js/tests/unit/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,41 @@ $(function () {
})
$scrollSpy.scrollTop(550);
})

test('should add the active class to the correct element', function () {
var navbarHtml =
'<div class="navbar">' +
'<ul class="nav">' +
'<li id="li-1"><a href="#div-1">div 1</a></li>' +
'<li id="li-2"><a href="#div-2">div 2</a></li>' +
'</ul>' +
'</div>'
var contentHtml =
'<div class="content" style="overflow: auto; height: 50px">' +
'<div id="div-1" style="height: 100px; padding: 0; margin: 0">div 1</div>' +
'<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' +
'</div>'

$(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') })
})

})

0 comments on commit cb19f4f

Please sign in to comment.