Complete carousel refactor.

Reduces one layer of DOM nesting for simplication, uses the latest Embla
version, unittests for everything.
This commit is contained in:
Dermot Duffy
2023-09-04 16:25:32 -07:00
parent 48ece1e154
commit e830db1a77
56 changed files with 3561 additions and 1950 deletions
+28 -5
View File
@@ -1,27 +1,29 @@
import { describe, it, expect, vi, afterAll } from 'vitest';
import { afterAll, describe, expect, it, vi } from 'vitest';
import { FrigateCardError } from '../../src/types';
import {
allPromises,
arrayify,
arrayMove,
arrayify,
contentsChanged,
dayToDate,
dispatchFrigateCardEvent,
errorToConsole,
isTruthy,
formatDate,
formatDateAndTime,
getChildrenFromElement,
getDurationString,
isHTMLElement,
isHoverableDevice,
isSuperset,
isTruthy,
isValidDate,
prettifyTitle,
runWhenIdleIfSupported,
setify,
setOrRemoveAttribute,
setify,
sleep,
isHTMLElement,
} from '../../src/utils/basic';
import { createSlot, createSlotHost } from '../test-utils';
// @vitest-environment jsdom
describe('dispatchFrigateCardEvent', () => {
@@ -183,6 +185,11 @@ describe('getDurationString', () => {
const end = new Date(2023, 3, 14, 15, 37, 20);
expect(getDurationString(start, end)).toBe('2h 2m 20s');
});
it('should return very short duration', () => {
const start = new Date(2023, 3, 14, 13, 35, 10);
const end = new Date(2023, 3, 14, 13, 35, 12);
expect(getDurationString(start, end)).toBe('2s');
});
});
describe('allPromises', () => {
@@ -268,3 +275,19 @@ describe('isHTMLElement', () => {
expect(isHTMLElement(svgElement)).toBeFalsy();
});
});
describe('getChildrenFromElement', () => {
it('should return children for simple parent', () => {
const children = [document.createElement('div'), document.createElement('div')];
const parent = document.createElement('div');
children.forEach((child) => parent.appendChild(child));
expect(getChildrenFromElement(parent)).toEqual(children);
});
it('should return children for slot', () => {
const children = [document.createElement('div'), document.createElement('div')];
const slot = createSlot();
createSlotHost({ slot: slot, children: children });
expect(getChildrenFromElement(slot)).toEqual(children);
});
});