From 6c70c70f637267ca109f44ff63f564892ece42bf Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sun, 17 Sep 2017 04:30:37 -0300 Subject: fix(scrollspy): Spying on nested navs fails to activate for .nav-link's inside nav-item's (#23967) * fix(scrollspy): Handle nested navs when nav-link inside nav-item * [scrolspy] Find only child .nav-link's inside .nav-item * [scrollspyt] Add tests for nested navs with nav-link inside nav-item * fix troy-o's in test --- js/tests/unit/scrollspy.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'js/tests') diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 96cf54eef..7bdeb4a8d 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -360,6 +360,47 @@ $(function () { testActiveElements() }) + + QUnit.test('should add the active class correctly when there are nested elements (nav nav-item markup)', function (assert) { + assert.expect(6) + var times = 0 + var done = assert.async() + var navbarHtml = '' + + var contentHtml = '
' + + '
' + + '
div 2
' + + '
' + + '
' + + $(navbarHtml).appendTo('#qunit-fixture') + + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ offset: 0, target: '#navigation' }) + + function testActiveElements() { + if (++times > 3) { return done() } + + $content.one('scroll', function () { + assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class') + assert.ok($('#a-2').hasClass('active'), 'nav item for inner element has "active" class') + testActiveElements() + }) + + $content.scrollTop($content.scrollTop() + 10) + } + + testActiveElements() + }) + QUnit.test('should add the active class correctly when there are nested elements (list-group markup)', function (assert) { assert.expect(6) var times = 0 -- cgit v1.2.3