From c2e94eba8da462ba8cacbc1558f7fdf6b3e28007 Mon Sep 17 00:00:00 2001 From: Mike Robinet Date: Tue, 13 May 2014 12:20:18 -0500 Subject: [PATCH] Add Scrollspy maxScroll with offset test. --- js/tests/unit/scrollspy.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 90c95d7691..9a00221fd8 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -42,7 +42,8 @@ $(function () { ok($topbar.find('.active', true)) }) - test('should only switch active class on current target', function () { + asyncTest('should only switch active class on current target', function () { + expect(1); var sectionHTML = '
' + '
' + '
' + @@ -75,7 +76,40 @@ $(function () { .find('#scrollspy-example') .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 = '' + + '' + + '
' + + '
' + + '
' + + '
' + + '
', + $section = $(sectionHTML).appendTo('#qunit-fixture'), + $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); }) })