aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Robinet <[email protected]>2014-05-13 12:20:18 -0500
committerMike Robinet <[email protected]>2014-05-13 12:53:54 -0500
commitc2e94eba8da462ba8cacbc1558f7fdf6b3e28007 (patch)
treeaad65b7258c6a0aaa9b5ad32398fc1b4e844e873
parente84b0c0433509bde0b42354754372595db523e1f (diff)
downloadbootstrap-c2e94eba8da462ba8cacbc1558f7fdf6b3e28007.tar.xz
bootstrap-c2e94eba8da462ba8cacbc1558f7fdf6b3e28007.zip
Add Scrollspy maxScroll with offset test.
-rw-r--r--js/tests/unit/scrollspy.js38
1 files changed, 36 insertions, 2 deletions
diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js
index 90c95d769..9a00221fd 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 = '<div id="root" class="active">' +
'<div class="topbar">' +
'<div class="topbar-inner">' +
@@ -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 = '<div id="header" style="height: 500px;"></div>' +
+ '<nav id="navigation" class="navbar">' +
+ '<ul class="nav navbar-nav">' +
+ '<li class="active"><a id="one-link" href="#one">One</a></li>' +
+ '<li><a id="two-link" href="#two">Two</a></li>' +
+ '<li><a id="three-link" href="#three">Three</a></li>' +
+ '</ul>' +
+ '</nav>' +
+ '<div id="content" style="height: 200px; overflow-y: auto;">' +
+ '<div id="one" style="height: 500px;"></div>' +
+ '<div id="two" style="height: 300px;"></div>' +
+ '<div id="three" style="height: 10px;"></div>' +
+ '</div>',
+ $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);
})
})