feat: Add support for Frigate reviews / detections [initial PR] (#2315)
- Add support for Frigate reviews / detections. - Add support for GenAI metadata. - Significant internal refactor to more flexible "UnifiedQuery" to allow mixing cameras with simple metadata and review metadata (e.g. a timeline view of a Frigate camera with reviews, and a Reolink camera with simple metadata). - Add support for folder media as camera media. There are a few more PRs to commit prior to this going live, but commiting this for now due to the scale of the change. BREAKING CHANGE: `media_type` and `events_type` are retired under `live`, `viewer` and `timeline` configuration sections, instead media type is associated (once) with the camera under `media`.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import { ReactiveControllerHost } from 'lit';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import { CachedValueController } from '../../src/components-lib/cached-value-controller';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('CachedValueController', () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should construct', () => {
|
||||
const host = mock<ReactiveControllerHost>();
|
||||
const callback = vi.fn();
|
||||
const controller = new CachedValueController(host, 10, callback);
|
||||
|
||||
expect(controller).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should remove host', () => {
|
||||
const host = mock<ReactiveControllerHost>();
|
||||
const callback = vi.fn();
|
||||
const controller = new CachedValueController(host, 10, callback);
|
||||
|
||||
controller.removeController();
|
||||
expect(host.removeController).toBeCalled();
|
||||
});
|
||||
|
||||
it('should have timer', () => {
|
||||
const host = mock<ReactiveControllerHost>();
|
||||
const callback = vi.fn();
|
||||
const startCallback = vi.fn();
|
||||
const stopCallback = vi.fn();
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
const controller = new CachedValueController(
|
||||
host,
|
||||
10,
|
||||
callback,
|
||||
startCallback,
|
||||
stopCallback,
|
||||
);
|
||||
|
||||
controller.startTimer();
|
||||
expect(startCallback).toBeCalled();
|
||||
|
||||
callback.mockReturnValue(3);
|
||||
vi.runOnlyPendingTimers();
|
||||
expect(callback).toBeCalled();
|
||||
expect(host.requestUpdate).toBeCalled();
|
||||
expect(controller.value).toBe(3);
|
||||
|
||||
callback.mockReturnValue(4);
|
||||
vi.runOnlyPendingTimers();
|
||||
expect(callback).toBeCalled();
|
||||
expect(host.requestUpdate).toBeCalled();
|
||||
expect(controller.value).toBe(4);
|
||||
|
||||
expect(controller.hasTimer()).toBeTruthy();
|
||||
|
||||
controller.stopTimer();
|
||||
expect(stopCallback).toBeCalled();
|
||||
|
||||
callback.mockReset();
|
||||
vi.runOnlyPendingTimers();
|
||||
expect(callback).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should clear value', () => {
|
||||
const host = mock<ReactiveControllerHost>();
|
||||
const callback = vi.fn().mockReturnValue(42);
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
const controller = new CachedValueController(host, 10, callback);
|
||||
controller.startTimer();
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
expect(controller.value).equal(42);
|
||||
|
||||
controller.clearValue();
|
||||
expect(controller.value).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should connect and disconnect host', () => {
|
||||
const host = mock<ReactiveControllerHost>();
|
||||
const callback = vi.fn().mockReturnValue(43);
|
||||
const startCallback = vi.fn();
|
||||
const stopCallback = vi.fn();
|
||||
|
||||
const controller = new CachedValueController(
|
||||
host,
|
||||
10,
|
||||
callback,
|
||||
startCallback,
|
||||
stopCallback,
|
||||
);
|
||||
|
||||
controller.hostConnected();
|
||||
expect(controller.value).equal(43);
|
||||
expect(startCallback).toBeCalled();
|
||||
expect(host.requestUpdate).toBeCalled();
|
||||
|
||||
controller.hostDisconnected();
|
||||
expect(controller.value).toBeUndefined();
|
||||
expect(stopCallback).toBeCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user