diff options
| author | Alejandro Mendoza <[email protected]> | 2023-04-30 15:31:26 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-01 00:31:26 +0300 |
| commit | a06c2e6b5f8cd3debdd8b9bd2765681aba8680ad (patch) | |
| tree | 1abfff4f2a3f0fe98051151dafbee968a5520807 /js/tests/unit/scrollspy.spec.js | |
| parent | 27954217168f5293391a7f672bec69d5b27ca4dd (diff) | |
| download | bootstrap-a06c2e6b5f8cd3debdd8b9bd2765681aba8680ad.tar.xz bootstrap-a06c2e6b5f8cd3debdd8b9bd2765681aba8680ad.zip | |
Fix scrollspy and accented anchor links (#38502)
Diffstat (limited to 'js/tests/unit/scrollspy.spec.js')
| -rw-r--r-- | js/tests/unit/scrollspy.spec.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js index 070448c17..ecbd9522c 100644 --- a/js/tests/unit/scrollspy.spec.js +++ b/js/tests/unit/scrollspy.spec.js @@ -940,5 +940,39 @@ describe('ScrollSpy', () => { }, 100) link.click() }) + + it('should smoothscroll to observable with anchor link that contains a french word as id', done => { + fixtureEl.innerHTML = [ + '<nav id="navBar" class="navbar">', + ' <ul class="nav">', + ' <li class="nav-item"><a id="li-jsm-1" class="nav-link" href="#présentation">div 1</a></li>', + ' </ul>', + '</nav>', + '<div class="content" data-bs-target="#navBar" style="overflow-y: auto">', + ' <div id="présentation">div 1</div>', + '</div>' + ].join('') + + const div = fixtureEl.querySelector('.content') + const link = fixtureEl.querySelector('[href="#présentation"]') + const observable = fixtureEl.querySelector('#présentation') + const clickSpy = getElementScrollSpy(div) + // eslint-disable-next-line no-new + new ScrollSpy(div, { + offset: 1, + smoothScroll: true + }) + + setTimeout(() => { + if (div.scrollTo) { + expect(clickSpy).toHaveBeenCalledWith({ top: observable.offsetTop - div.offsetTop, behavior: 'smooth' }) + } else { + expect(clickSpy).toHaveBeenCalledWith(observable.offsetTop - div.offsetTop) + } + + done() + }, 100) + link.click() + }) }) }) |
