fix: Substantially reduce cases where errors block whole card (#1764)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { LiveController } from '../../../src/components-lib/live/live-controller';
|
||||
import { dispatchMessageEvent } from '../../../src/components/message';
|
||||
import { dispatchExistingMediaLoadedInfoAsEvent } from '../../../src/utils/media-info';
|
||||
import {
|
||||
IntersectionObserverMock,
|
||||
callIntersectionHandler,
|
||||
@@ -26,7 +26,7 @@ describe('LiveController', () => {
|
||||
const host = createLitElement();
|
||||
const parent = createParent({ children: [host] });
|
||||
const eventListener = vi.fn();
|
||||
parent.addEventListener('frigate-card:message', eventListener);
|
||||
parent.addEventListener('frigate-card:media:loaded', eventListener);
|
||||
|
||||
const controller = new LiveController(host);
|
||||
expect(host.addController).toBeCalled();
|
||||
@@ -34,12 +34,13 @@ describe('LiveController', () => {
|
||||
controller.hostConnected();
|
||||
|
||||
callIntersectionHandler(false);
|
||||
dispatchMessageEvent(host, 'message', 'info');
|
||||
|
||||
dispatchExistingMediaLoadedInfoAsEvent(host, createMediaLoadedInfo());
|
||||
|
||||
expect(eventListener).toBeCalledTimes(0);
|
||||
|
||||
controller.hostDisconnected();
|
||||
dispatchMessageEvent(host, 'message', 'info');
|
||||
dispatchExistingMediaLoadedInfoAsEvent(host, createMediaLoadedInfo());
|
||||
|
||||
expect(eventListener).toBeCalledTimes(1);
|
||||
});
|
||||
@@ -92,70 +93,6 @@ describe('LiveController', () => {
|
||||
|
||||
host.dispatchEvent(createMediaLoadedInfoEvent(mediaLoadedInfo));
|
||||
expect(eventListener).toBeCalledTimes(2);
|
||||
|
||||
callIntersectionHandler(false);
|
||||
dispatchMessageEvent(host, 'message', 'info');
|
||||
callIntersectionHandler(true);
|
||||
expect(eventListener).toBeCalledTimes(2);
|
||||
|
||||
controller.clearMessageReceived();
|
||||
callIntersectionHandler(true);
|
||||
expect(eventListener).toBeCalledTimes(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should correctly allow updates', () => {
|
||||
it('when not in background', () => {
|
||||
const controller = new LiveController(createLitElement());
|
||||
expect(controller.shouldUpdate()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('when in background without message', () => {
|
||||
const host = createLitElement();
|
||||
const controller = new LiveController(host);
|
||||
controller.hostConnected();
|
||||
|
||||
callIntersectionHandler(false);
|
||||
|
||||
expect(controller.shouldUpdate()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('when in background with message', () => {
|
||||
const host = createLitElement();
|
||||
const controller = new LiveController(host);
|
||||
controller.hostConnected();
|
||||
|
||||
callIntersectionHandler(false);
|
||||
dispatchMessageEvent(host, 'message', 'info');
|
||||
|
||||
expect(controller.shouldUpdate()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle message', () => {
|
||||
const host = createLitElement();
|
||||
const parent = createParent({ children: [host] });
|
||||
const eventListener = vi.fn();
|
||||
parent.addEventListener('frigate-card:message', eventListener);
|
||||
|
||||
const controller = new LiveController(host);
|
||||
controller.hostConnected();
|
||||
|
||||
callIntersectionHandler(false);
|
||||
expect(controller.isInBackground()).toBeTruthy();
|
||||
|
||||
const firstRenderEpoch = controller.getRenderEpoch();
|
||||
|
||||
dispatchMessageEvent(host, 'message', 'info');
|
||||
expect(eventListener).toBeCalledTimes(0);
|
||||
|
||||
const secondRenderEpoch = controller.getRenderEpoch();
|
||||
expect(secondRenderEpoch).not.toBe(firstRenderEpoch);
|
||||
|
||||
callIntersectionHandler(true);
|
||||
|
||||
dispatchMessageEvent(host, 'message', 'info');
|
||||
expect(eventListener).toBeCalledTimes(1);
|
||||
expect(controller.getRenderEpoch()).toBe(secondRenderEpoch);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { expect, it, vi } from 'vitest';
|
||||
import { dispatchLiveErrorEvent } from '../../../../src/components-lib/live/utils/dispatch-live-error';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
it('should dispatch live error event', () => {
|
||||
const element = document.createElement('div');
|
||||
const handler = vi.fn();
|
||||
element.addEventListener('frigate-card:live:error', handler);
|
||||
|
||||
dispatchLiveErrorEvent(element);
|
||||
expect(handler).toBeCalled();
|
||||
});
|
||||
Reference in New Issue
Block a user