mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
remove unused insertBefore function from dom utils
This commit is contained in:
parent
87f37ab8d4
commit
efa5092502
2 changed files with 0 additions and 45 deletions
|
@ -5,7 +5,6 @@ import {
|
||||||
escapeCss,
|
escapeCss,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
hideEl,
|
hideEl,
|
||||||
insertBefore,
|
|
||||||
makeEl,
|
makeEl,
|
||||||
onLeftClick,
|
onLeftClick,
|
||||||
removeEl,
|
removeEl,
|
||||||
|
@ -297,46 +296,6 @@ describe('DOM Utilities', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('insertBefore', () => {
|
|
||||||
it('should insert the new element before the existing element', () => {
|
|
||||||
const mockParent = document.createElement('p');
|
|
||||||
const mockExisingElement = document.createElement('span');
|
|
||||||
mockParent.appendChild(mockExisingElement);
|
|
||||||
const mockNewElement = document.createElement('strong');
|
|
||||||
|
|
||||||
insertBefore(mockExisingElement, mockNewElement);
|
|
||||||
|
|
||||||
expect(mockParent.children).toHaveLength(2);
|
|
||||||
expect(mockParent.children[0].tagName).toBe('STRONG');
|
|
||||||
expect(mockParent.children[1].tagName).toBe('SPAN');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should insert between two elements', () => {
|
|
||||||
const mockParent = document.createElement('p');
|
|
||||||
const mockFirstExisingElement = document.createElement('span');
|
|
||||||
const mockSecondExisingElement = document.createElement('em');
|
|
||||||
mockParent.appendChild(mockFirstExisingElement);
|
|
||||||
mockParent.appendChild(mockSecondExisingElement);
|
|
||||||
const mockNewElement = document.createElement('strong');
|
|
||||||
|
|
||||||
insertBefore(mockSecondExisingElement, mockNewElement);
|
|
||||||
|
|
||||||
expect(mockParent.children).toHaveLength(3);
|
|
||||||
expect(mockParent.children[0].tagName).toBe('SPAN');
|
|
||||||
expect(mockParent.children[1].tagName).toBe('STRONG');
|
|
||||||
expect(mockParent.children[2].tagName).toBe('EM');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should NOT fail if there is no parent', () => {
|
|
||||||
const mockParent = document.createElement('p');
|
|
||||||
const mockNewElement = document.createElement('em');
|
|
||||||
|
|
||||||
expect(() => {
|
|
||||||
insertBefore(mockParent, mockNewElement);
|
|
||||||
}).not.toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('onLeftClick', () => {
|
describe('onLeftClick', () => {
|
||||||
let cleanup: VoidFunction | undefined;
|
let cleanup: VoidFunction | undefined;
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,6 @@ export function makeEl<Tag extends keyof HTMLElementTagNameMap>(tag: Tag, attr?:
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function insertBefore(existingElement: HTMLElement, newElement: HTMLElement) {
|
|
||||||
existingElement.parentNode?.insertBefore(newElement, existingElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onLeftClick(callback: (e: MouseEvent) => boolean | void, context: Pick<GlobalEventHandlers, 'addEventListener' | 'removeEventListener'> = document): VoidFunction {
|
export function onLeftClick(callback: (e: MouseEvent) => boolean | void, context: Pick<GlobalEventHandlers, 'addEventListener' | 'removeEventListener'> = document): VoidFunction {
|
||||||
const handler: typeof callback = event => {
|
const handler: typeof callback = event => {
|
||||||
if (event.button === 0) callback(event);
|
if (event.button === 0) callback(event);
|
||||||
|
|
Loading…
Reference in a new issue