diff options
| author | Jacob <[email protected]> | 2014-07-06 21:43:48 -0700 |
|---|---|---|
| committer | Jacob <[email protected]> | 2014-07-06 21:43:48 -0700 |
| commit | b5d86ad0bd47cae4e12126d8b84ca49d6c415e5d (patch) | |
| tree | 2116392039e7a3539c44b9d34c1aca6bcda8e74a /js/tests/unit/scrollspy.js | |
| parent | 5e41a23ec5da02e67be2a67dd0c692517b3b01bd (diff) | |
| parent | 58eb8b2ae39baeb37514e5bf5ffcaf2a7c221202 (diff) | |
| download | bootstrap-b5d86ad0bd47cae4e12126d8b84ca49d6c415e5d.tar.xz bootstrap-b5d86ad0bd47cae4e12126d8b84ca49d6c415e5d.zip | |
Merge pull request #13853 from hnrch02/unit-tests-cleanup
Major unit tests cleanup
Diffstat (limited to 'js/tests/unit/scrollspy.js')
| -rw-r--r-- | js/tests/unit/scrollspy.js | 147 |
1 files changed, 77 insertions, 70 deletions
diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index d960ba71a..084e6fe6e 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -19,100 +19,107 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.scrollspy, 'scrollspy was set back to undefined (org value)') + strictEqual($.fn.scrollspy, undefined, 'scrollspy was set back to undefined (org value)') }) - test('should return element', function () { - ok($(document.body).bootstrapScrollspy()[0] == document.body, 'document.body returned') + test('should return jquery collection containing the element', function () { + var $el = $('<div/>') + var $scrollspy = $el.bootstrapScrollspy() + ok($scrollspy instanceof $, 'returns jquery collection') + strictEqual($scrollspy[0], $el[0], 'collection contains element') }) - test('should switch active class on scroll', function () { - var sectionHTML = '<div id="masthead"></div>' - $(sectionHTML).append('#qunit-fixture') - var topbarHTML = '<div class="topbar">' + - '<div class="topbar-inner">' + - '<div class="container">' + - '<h3><a href="#">Bootstrap</a></h3>' + - '<li><a href="#masthead">Overview</a></li>' + - '</ul>' + - '</div>' + - '</div>' + - '</div>' + // Does not work properly ATM, #13500 will fix this + test('should switch "active" class on scroll', function () { + var topbarHTML = '<div class="topbar">' + + '<div class="topbar-inner">' + + '<div class="container">' + + '<h3><a href="#">Bootstrap</a></h3>' + + '<li><a href="#masthead">Overview</a></li>' + + '</ul>' + + '</div>' + + '</div>' + + '</div>' var $topbar = $(topbarHTML).bootstrapScrollspy() - $(sectionHTML).append('#qunit-fixture') ok($topbar.find('.active', true)) }) - 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">' + - '<div class="container" id="ss-target">' + - '<ul class="nav">' + - '<li><a href="#masthead">Overview</a></li>' + - '<li><a href="#detail">Detail</a></li>' + - '</ul>' + - '</div>' + - '</div>' + - '</div>' + - '<div id="scrollspy-example" style="height: 100px; overflow: auto;">' + - '<div style="height: 200px;">' + - '<h4 id="masthead">Overview</h4>' + - '<p style="height: 200px">' + - 'Ad leggings keytar, brunch id art party dolor labore.' + - '</p>' + - '</div>' + - '<div style="height: 200px;">' + - '<h4 id="detail">Detail</h4>' + - '<p style="height: 200px">' + - 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.' + - '</p>' + - '</div>' + - '</div>' + - '</div>' + test('should only switch "active" class on current target', function () { + stop() + + var sectionHTML = '<div id="root" class="active">' + + '<div class="topbar">' + + '<div class="topbar-inner">' + + '<div class="container" id="ss-target">' + + '<ul class="nav">' + + '<li><a href="#masthead">Overview</a></li>' + + '<li><a href="#detail">Detail</a></li>' + + '</ul>' + + '</div>' + + '</div>' + + '</div>' + + '<div id="scrollspy-example" style="height: 100px; overflow: auto;">' + + '<div style="height: 200px;">' + + '<h4 id="masthead">Overview</h4>' + + '<p style="height: 200px">' + + 'Ad leggings keytar, brunch id art party dolor labore.' + + '</p>' + + '</div>' + + '<div style="height: 200px;">' + + '<h4 id="detail">Detail</h4>' + + '<p style="height: 200px">' + + 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.' + + '</p>' + + '</div>' + + '</div>' + + '</div>' var $section = $(sectionHTML).appendTo('#qunit-fixture') - var $scrollSpy = $section + + var $scrollspy = $section .show() .find('#scrollspy-example') .bootstrapScrollspy({ target: '#ss-target' }) - $scrollSpy.on('scroll.bs.scrollspy', function () { - ok($section.hasClass('active'), 'Active class still on root node') + $scrollspy.on('scroll.bs.scrollspy', function () { + ok($section.hasClass('active'), '"active" class still on root node') start() }) - $scrollSpy.scrollTop(350); + + $scrollspy.scrollTop(350) }) - 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>' + test('middle navigation option correctly selected when large offset is used', function () { + stop() + + 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>' var $section = $(sectionHTML).appendTo('#qunit-fixture') - var $scrollSpy = $section + 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') + $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); + + $scrollspy.scrollTop(550) }) test('should add the active class to the correct element', function () { |
