ungleich-staticcms/assets/u/static/popper.js-1.16.0/packages/popper/tests/unit/getScrollParent.js
Nico Schottelius 16fb2bb919 import popper.js
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
2019-12-31 01:21:21 +01:00

74 lines
2 KiB
JavaScript

import chai from 'chai';
const { expect } = chai;
import getScrollParent from '../../src/utils/getScrollParent';
describe('utils/getOffsetParent', () => {
let node;
beforeEach(() => {
node = document.createElement('div');
});
it('element is just appended to the body', () => {
document.body.appendChild(node);
expect(getScrollParent(node)).to.equal(document.body);
document.body.removeChild(node);
});
describe('element is inside scrollable element', () => {
let parent;
beforeEach(() => {
parent = document.createElement('div');
parent.appendChild(node);
document.body.appendChild(parent);
});
afterEach(() => {
document.body.removeChild(parent);
});
[
{ key: 'overflow', value: 'scroll' },
{ key: 'overflowX', value: 'scroll' },
{ key: 'overflowY', value: 'scroll' },
{ key: 'overflow', value: 'auto' },
{ key: 'overflowX', value: 'auto' },
{ key: 'overflowY', value: 'auto' },
].forEach(obj => {
it(`${obj.key}: ${obj.value}`, () => {
parent.style[obj.key] = obj.value;
expect(getScrollParent(node)).to.equal(parent);
});
});
});
describe('element is deep inside scrollable element', () => {
let parent;
beforeEach(() => {
parent = document.createElement('div');
parent.innerHTML = '<div><div></div></div>';
parent.firstChild.firstChild.appendChild(node);
document.body.appendChild(parent);
});
afterEach(() => {
document.body.removeChild(parent);
});
[
{ key: 'overflow', value: 'scroll' },
{ key: 'overflowX', value: 'scroll' },
{ key: 'overflowY', value: 'scroll' },
{ key: 'overflow', value: 'auto' },
{ key: 'overflowX', value: 'auto' },
{ key: 'overflowY', value: 'auto' },
].forEach(obj => {
it(`${obj.key}: ${obj.value}`, () => {
parent.style[obj.key] = obj.value;
expect(getScrollParent(node)).to.equal(parent);
});
});
});
});