UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

43 lines (42 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require(".."); const createElement_spec_1 = require("../test-helpers/createElement.spec"); describe('getPositionedParent', () => { it('should return the first position relative parent (no nesting)', () => { const element = (0, createElement_spec_1.createElement)('div', { position: 'absolute' }); const parent = (0, createElement_spec_1.createElement)('div', { position: 'relative' }); parent.appendChild(element); expect((0, __1.getPositionedParent)(element)).toEqual(parent); }); it('should return the first position relative parent (nested)', () => { const element = (0, createElement_spec_1.createElement)('div', { position: 'absolute' }, false); const parent = (0, createElement_spec_1.createElement)('div', {}, false); const grandparent = (0, createElement_spec_1.createElement)('div', { position: 'relative' }); parent.appendChild(element); grandparent.appendChild(parent); expect((0, __1.getPositionedParent)(element)).toEqual(grandparent); }); it('should return the first position absolute parent (no nesting)', () => { const element = (0, createElement_spec_1.createElement)('div', { position: 'absolute' }); const parent = (0, createElement_spec_1.createElement)('div', { position: 'absolute' }); parent.appendChild(element); expect((0, __1.getPositionedParent)(element)).toEqual(parent); }); it('should return the first position absolute parent (nested)', () => { const element = (0, createElement_spec_1.createElement)('div', { position: 'absolute' }, false); const parent = (0, createElement_spec_1.createElement)('div', {}, false); const grandparent = (0, createElement_spec_1.createElement)('div', { position: 'absolute' }); parent.appendChild(element); grandparent.appendChild(parent); expect((0, __1.getPositionedParent)(element)).toEqual(grandparent); }); it('should return the document element if no parent has a position', () => { const element = (0, createElement_spec_1.createElement)('div', {}, false); const parent = (0, createElement_spec_1.createElement)('div', {}, false); const grandparent = (0, createElement_spec_1.createElement)('div'); parent.appendChild(element); grandparent.appendChild(parent); expect((0, __1.getPositionedParent)(element)).toEqual(document.documentElement); }); });