Complete carousel refactor.
Reduces one layer of DOM nesting for simplication, uses the latest Embla version, unittests for everything.
This commit is contained in:
@@ -59,7 +59,7 @@ describe('RecordingSegmentsCache', () => {
|
||||
start: now,
|
||||
end: add(now, { hours: 1 }),
|
||||
};
|
||||
const badRange = { start: sub(now, { hours: 1 }), end: now };
|
||||
const pastRange = { start: sub(now, { hours: 1 }), end: now };
|
||||
const createSegment = (date: Date, id: string): RecordingSegment => {
|
||||
return {
|
||||
start_time: date.getTime() / 1000,
|
||||
@@ -89,7 +89,7 @@ describe('RecordingSegmentsCache', () => {
|
||||
});
|
||||
it('should not get for other range', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
expect(cache.get('camera-1', badRange)).toBeNull();
|
||||
expect(cache.get('camera-1', pastRange)).toBeNull();
|
||||
});
|
||||
|
||||
it('should have coverage when added', () => {
|
||||
@@ -102,7 +102,7 @@ describe('RecordingSegmentsCache', () => {
|
||||
});
|
||||
it('should not have coverage for other range', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
expect(cache.hasCoverage('camera-1', badRange)).toBeFalsy();
|
||||
expect(cache.hasCoverage('camera-1', pastRange)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should be empty when cleared', () => {
|
||||
@@ -114,11 +114,11 @@ describe('RecordingSegmentsCache', () => {
|
||||
|
||||
it('should get size', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
expect(cache.getSize("camera-1")).toBe(3);
|
||||
expect(cache.getSize('camera-1')).toBe(3);
|
||||
});
|
||||
it('should not size for other camera', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
expect(cache.getSize("camera-2")).toBeNull();
|
||||
expect(cache.getSize('camera-2')).toBeNull();
|
||||
});
|
||||
|
||||
it('should return cameraIDs', () => {
|
||||
@@ -127,6 +127,24 @@ describe('RecordingSegmentsCache', () => {
|
||||
expect(sortBy(cache.getCameraIDs())).toEqual(sortBy(['camera-1', 'camera-2']));
|
||||
});
|
||||
|
||||
it('should add segments to existing range', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
cache.add('camera-1', range, [
|
||||
createSegment(add(now, { seconds: 15 }), 'segment-2.5'),
|
||||
]);
|
||||
expect(cache.get('camera-1', range)?.length).toBe(4);
|
||||
});
|
||||
it('should not get segments that are outside range', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
expect(cache.get('camera-1', range)?.length).toBe(3);
|
||||
// Add a segment before and after the desired range.
|
||||
cache.add('camera-1', range, [
|
||||
createSegment(sub(now, { seconds: 15 }), 'segment-0'),
|
||||
createSegment(add(range.end, { seconds: 10 }), 'segment-4'),
|
||||
]);
|
||||
expect(cache.get('camera-1', range)?.length).toBe(3);
|
||||
});
|
||||
|
||||
it('should remove expired matches', () => {
|
||||
cache.add('camera-1', range, segments);
|
||||
cache.expireMatches('camera-1', (segment) => segment === segments[0]);
|
||||
|
||||
@@ -100,6 +100,11 @@ describe('CameraManagerEngineFactory.getEngineForCamera()', () => {
|
||||
Engine.Frigate,
|
||||
);
|
||||
});
|
||||
it('should get no engine from config with insufficient details', async () => {
|
||||
const config = createCameraConfig({});
|
||||
expect(await createFactory().getEngineForCamera(createHASS(), config)).toBeNull();
|
||||
});
|
||||
|
||||
it('should throw error on invalid entity', async () => {
|
||||
const config = createCameraConfig({ engine: 'auto', camera_entity: 'camera.foo' });
|
||||
const entityRegistryManager = new EntityRegistryManager(new EntityCache());
|
||||
|
||||
@@ -135,6 +135,7 @@ describe('compressRanges', () => {
|
||||
compressRanges([
|
||||
{ start: now, end: nowPlusOne },
|
||||
{ start: nowPlusOne, end: nowPlusTwo },
|
||||
{ start: now, end: nowPlusOne },
|
||||
]),
|
||||
).toEqual([{ start: now, end: nowPlusTwo }]);
|
||||
});
|
||||
@@ -162,4 +163,8 @@ describe('compressRanges', () => {
|
||||
];
|
||||
expect(compressRanges(input)).toEqual([{ start: 1, end: 3 }]);
|
||||
});
|
||||
|
||||
it('should return nothing with no input', () => {
|
||||
expect(compressRanges([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user