import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import { addClassIfElementExists, canScrollUp, canScrollDown, parseBooleanDataAttributes, isElementVisible, getParents, getParentByTagName, setAttributes, } from '~/lib/utils/dom_utils'; const TEST_MARGIN = 5; describe('DOM Utils', () => { describe('addClassIfElementExists', () => { const className = 'biology'; const fixture = `
hello world';
expect(getParents(el.querySelector('mark'))).toEqual([
el.querySelector('strong'),
el.querySelector('span'),
el.querySelector('p'),
el,
]);
});
});
describe('getParentByTagName', () => {
const el = document.createElement('div');
el.innerHTML = ' hello world';
it.each`
tagName | parent
${'strong'} | ${el.querySelector('strong')}
${'span'} | ${el.querySelector('span')}
${'p'} | ${el.querySelector('p')}
${'pre'} | ${undefined}
`('gets a parent by tag name', ({ tagName, parent }) => {
expect(getParentByTagName(el.querySelector('mark'), tagName)).toBe(parent);
});
});
describe('setAttributes', () => {
it('sets multiple attribues on element', () => {
const div = document.createElement('div');
setAttributes(div, { class: 'test', title: 'another test' });
expect(div.getAttribute('class')).toBe('test');
expect(div.getAttribute('title')).toBe('another test');
});
});
});