@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
78 lines (77 loc) • 3.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
describe('getScrollParent', () => {
it('should get the scroll parent for an element with scrolling on the x and y axis', () => {
const { parent, child } = createScrollElements(true, true);
expect((0, __1.getScrollParent)(child)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the x axis', () => {
const { parent, child } = createScrollElements(true, false);
expect((0, __1.getScrollParent)(child)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the y axis', () => {
const { parent, child } = createScrollElements(false, true);
expect((0, __1.getScrollParent)(child)).toEqual(parent);
});
it('should get the scroll parent for an element that smaller than the scroll area', () => {
const { parent, child } = createScrollElements(false, false);
expect((0, __1.getScrollParent)(child)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the x and y axis', () => {
const { parent, child } = createScrollElements(true, true);
expect((0, __1.getScrollParent)(child, false)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the x axis', () => {
const { parent, child } = createScrollElements(true, false);
expect((0, __1.getScrollParent)(child, false)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the y axis', () => {
const { parent, child } = createScrollElements(false, true);
expect((0, __1.getScrollParent)(child, false)).toEqual(parent);
});
it('should get the scroll parent for an element that smaller than the scroll area', () => {
const { parent, child } = createScrollElements(false, false);
expect((0, __1.getScrollParent)(child, false)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the x and y axis', () => {
const { parent, child } = createScrollElements(true, true);
expect((0, __1.getScrollParent)(child, true, false)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the x axis', () => {
const { parent, child } = createScrollElements(true, false);
expect((0, __1.getScrollParent)(child, true, false)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the y axis', () => {
const { parent, child } = createScrollElements(false, true);
expect((0, __1.getScrollParent)(child, true, false)).toEqual(parent);
});
it('should get the scroll parent for an element that smaller than the scroll area', () => {
const { parent, child } = createScrollElements(false, false);
expect((0, __1.getScrollParent)(child, true, false)).toEqual(parent);
});
it('should get the scroll parent for an element with scrolling on the x and y axis', () => {
const { child } = createScrollElements(true, true, true);
expect((0, __1.getScrollParent)(child)).toEqual(document.body);
});
it('should return null when null provided as element', () => {
expect((0, __1.getScrollParent)(null)).toEqual(null);
});
});
function createScrollElements(x, y, noScroll) {
const child = document.createElement('div');
const parent = document.createElement('div');
if (!noScroll) {
parent.style.overflow = 'auto';
}
parent.style.width = '200px';
parent.style.height = '200px';
child.style.width = x ? '400px' : '100px';
child.style.height = y ? '400px' : '100px';
parent.append(child);
document.body.append(parent);
return {
parent,
child,
};
}