diff options
| author | fat <[email protected]> | 2014-07-06 14:11:23 -0700 |
|---|---|---|
| committer | fat <[email protected]> | 2014-07-06 14:11:23 -0700 |
| commit | b19719ea1af17aafc18cd2dd8963a95498cb1d20 (patch) | |
| tree | a2e052994f65bd7819c0967bb538eaa874cea1a2 /js | |
| parent | c08e275000330db6d8883de6af2243216cc79837 (diff) | |
| parent | 7627b24c1e6aa5301ee3f525dd931c2852e7ff0a (diff) | |
| download | bootstrap-b19719ea1af17aafc18cd2dd8963a95498cb1d20.tar.xz bootstrap-b19719ea1af17aafc18cd2dd8963a95498cb1d20.zip | |
Merge branch 'replace-scrollspy-default-behavior-test' of git://github.com/breaddevil/bootstrap into breaddevil-replace-scrollspy-default-behavior-test
Conflicts:
js/tests/unit/scrollspy.js
Diffstat (limited to 'js')
| -rw-r--r-- | js/tests/unit/scrollspy.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 2ec51fc24..a66868768 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -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') }) + }) + }) |
