| 1 |
import chai from 'chai'; |
| 2 |
const { expect } = chai; |
| 3 |
import getScrollParent from '../../src/utils/getScrollParent'; |
| 4 |
|
| 5 |
describe('utils/getOffsetParent', () => { |
| 6 |
let node; |
| 7 |
|
| 8 |
beforeEach(() => { |
| 9 |
node = document.createElement('div'); |
| 10 |
}); |
| 11 |
|
| 12 |
it('element is just appended to the body', () => { |
| 13 |
document.body.appendChild(node); |
| 14 |
expect(getScrollParent(node)).to.equal(document.body); |
| 15 |
document.body.removeChild(node); |
| 16 |
}); |
| 17 |
|
| 18 |
describe('element is inside scrollable element', () => { |
| 19 |
let parent; |
| 20 |
|
| 21 |
beforeEach(() => { |
| 22 |
parent = document.createElement('div'); |
| 23 |
parent.appendChild(node); |
| 24 |
document.body.appendChild(parent); |
| 25 |
}); |
| 26 |
|
| 27 |
afterEach(() => { |
| 28 |
document.body.removeChild(parent); |
| 29 |
}); |
| 30 |
|
| 31 |
[ |
| 32 |
{ key: 'overflow', value: 'scroll' }, |
| 33 |
{ key: 'overflowX', value: 'scroll' }, |
| 34 |
{ key: 'overflowY', value: 'scroll' }, |
| 35 |
{ key: 'overflow', value: 'auto' }, |
| 36 |
{ key: 'overflowX', value: 'auto' }, |
| 37 |
{ key: 'overflowY', value: 'auto' }, |
| 38 |
].forEach(obj => { |
| 39 |
it(`${obj.key}: ${obj.value}`, () => { |
| 40 |
parent.style[obj.key] = obj.value; |
| 41 |
expect(getScrollParent(node)).to.equal(parent); |
| 42 |
}); |
| 43 |
}); |
| 44 |
}); |
| 45 |
|
| 46 |
describe('element is deep inside scrollable element', () => { |
| 47 |
let parent; |
| 48 |
|
| 49 |
beforeEach(() => { |
| 50 |
parent = document.createElement('div'); |
| 51 |
parent.innerHTML = '<div><div></div></div>'; |
| 52 |
parent.firstChild.firstChild.appendChild(node); |
| 53 |
document.body.appendChild(parent); |
| 54 |
}); |
| 55 |
|
| 56 |
afterEach(() => { |
| 57 |
document.body.removeChild(parent); |
| 58 |
}); |
| 59 |
|
| 60 |
[ |
| 61 |
{ key: 'overflow', value: 'scroll' }, |
| 62 |
{ key: 'overflowX', value: 'scroll' }, |
| 63 |
{ key: 'overflowY', value: 'scroll' }, |
| 64 |
{ key: 'overflow', value: 'auto' }, |
| 65 |
{ key: 'overflowX', value: 'auto' }, |
| 66 |
{ key: 'overflowY', value: 'auto' }, |
| 67 |
].forEach(obj => { |
| 68 |
it(`${obj.key}: ${obj.value}`, () => { |
| 69 |
parent.style[obj.key] = obj.value; |
| 70 |
expect(getScrollParent(node)).to.equal(parent); |
| 71 |
}); |
| 72 |
}); |
| 73 |
}); |
| 74 |
}); |