aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit/dom/manipulator.spec.js
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2021-07-29 09:14:40 +0300
committerGitHub <[email protected]>2021-07-29 09:14:40 +0300
commitef5336373fc2431b3d1d37cde85cd262210a1dc6 (patch)
treee325fb4c5532b464d05780c731d0f118f2a88d7f /js/tests/unit/dom/manipulator.spec.js
parent62edf07d7491684fe67a9c1e9439ed2bd10ca741 (diff)
parentc6c0bbb0b67fe89b55740a63fd10d4ad79044970 (diff)
downloadbootstrap-main-fod-simpler-table-structure.tar.xz
bootstrap-main-fod-simpler-table-structure.zip
Merge branch 'main' into main-fod-simpler-table-structuremain-fod-simpler-table-structure
Diffstat (limited to 'js/tests/unit/dom/manipulator.spec.js')
-rw-r--r--js/tests/unit/dom/manipulator.spec.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/js/tests/unit/dom/manipulator.spec.js b/js/tests/unit/dom/manipulator.spec.js
index 3d91e6f74..4f8e40067 100644
--- a/js/tests/unit/dom/manipulator.spec.js
+++ b/js/tests/unit/dom/manipulator.spec.js
@@ -119,6 +119,60 @@ describe('Manipulator', () => {
expect(offset.top).toEqual(jasmine.any(Number))
expect(offset.left).toEqual(jasmine.any(Number))
})
+
+ it('should return offset relative to attached element\'s offset', () => {
+ const top = 500
+ const left = 1000
+
+ fixtureEl.innerHTML = `<div style="position:absolute;top:${top}px;left:${left}px"></div>`
+
+ const div = fixtureEl.querySelector('div')
+ const offset = Manipulator.offset(div)
+ const fixtureOffset = Manipulator.offset(fixtureEl)
+
+ expect(offset).toEqual({
+ top: fixtureOffset.top + top,
+ left: fixtureOffset.left + left
+ })
+ })
+
+ it('should not change offset when viewport is scrolled', done => {
+ const top = 500
+ const left = 1000
+ const scrollY = 200
+ const scrollX = 400
+
+ fixtureEl.innerHTML = `<div style="position:absolute;top:${top}px;left:${left}px"></div>`
+
+ const div = fixtureEl.querySelector('div')
+ const offset = Manipulator.offset(div)
+
+ // append an element that forces scrollbars on the window so we can scroll
+ const { defaultView: win, body } = fixtureEl.ownerDocument
+ const forceScrollBars = document.createElement('div')
+ forceScrollBars.style.cssText = 'position:absolute;top:5000px;left:5000px;width:1px;height:1px'
+ body.appendChild(forceScrollBars)
+
+ const scrollHandler = () => {
+ expect(window.pageYOffset).toBe(scrollY)
+ expect(window.pageXOffset).toBe(scrollX)
+
+ const newOffset = Manipulator.offset(div)
+
+ expect(newOffset).toEqual({
+ top: offset.top,
+ left: offset.left
+ })
+
+ win.removeEventListener('scroll', scrollHandler)
+ body.removeChild(forceScrollBars)
+ win.scrollTo(0, 0)
+ done()
+ }
+
+ win.addEventListener('scroll', scrollHandler)
+ win.scrollTo(scrollX, scrollY)
+ })
})
describe('position', () => {