From: fat Date: Sun, 6 Jul 2014 21:11:23 +0000 (-0700) Subject: Merge branch 'replace-scrollspy-default-behavior-test' of git://github.com/breaddevil... X-Git-Tag: v3.3.0~388^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b19719ea1af17aafc18cd2dd8963a95498cb1d20;p=thirdparty%2Fbootstrap.git 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 --- b19719ea1af17aafc18cd2dd8963a95498cb1d20 diff --cc js/tests/unit/scrollspy.js index 2ec51fc243,a36749f2e8..a668687687 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@@ -71,47 -51,51 +71,84 @@@ $(function () '

' + '' + '' + - '', - $section = $(sectionHTML).appendTo('#qunit-fixture'), - $scrollSpy = $section + '' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + var $scrollSpy = $section .show() .find('#scrollspy-example') - .bootstrapScrollspy({target: '#ss-target'}) + .bootstrapScrollspy({ target: '#ss-target' }) + $scrollSpy.on('scroll.bs.scrollspy', function () { + ok($section.hasClass('active'), 'Active class still on root node') + start() + }) $scrollSpy.scrollTop(350); - ok($section.hasClass('active'), 'Active class still on root node') + }) + + asyncTest('middle navigation option correctly selected when large offset is used', function () { + expect(3); + var sectionHTML = '' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + var $scrollSpy = $section + .show() + .filter('#content') + $scrollSpy.bootstrapScrollspy({ target: '#navigation', offset: $scrollSpy.position().top }) + + $scrollSpy.on('scroll.bs.scrollspy', function () { + ok(!$section.find('#one-link').parent().hasClass('active'), 'Active class removed from first section') + ok($section.find('#two-link').parent().hasClass('active'), 'Active class on middle section') + ok(!$section.find('#three-link').parent().hasClass('active'), 'Active class not on last section') + start() + }) + $scrollSpy.scrollTop(550); }) + + 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') }) + }) + })