summaryrefslogtreecommitdiffstats
path: root/js/tests/unit/scrollspy.spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tests/unit/scrollspy.spec.js')
-rw-r--r--js/tests/unit/scrollspy.spec.js42
1 files changed, 37 insertions, 5 deletions
diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js
index c7951e6..ecbd952 100644
--- a/js/tests/unit/scrollspy.spec.js
+++ b/js/tests/unit/scrollspy.spec.js
@@ -1,8 +1,6 @@
-import ScrollSpy from '../../src/scrollspy'
-
-/** Test helpers */
-import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
-import EventHandler from '../../src/dom/event-handler'
+import EventHandler from '../../src/dom/event-handler.js'
+import ScrollSpy from '../../src/scrollspy.js'
+import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
describe('ScrollSpy', () => {
let fixtureEl
@@ -942,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()
+ })
})
})