refactor: Refactor internal error / info message components (#1842)

This commit is contained in:
Dermot Duffy
2025-01-20 15:26:53 -08:00
committed by GitHub
parent 99fe613811
commit faa5ec3eec
19 changed files with 421 additions and 252 deletions
@@ -0,0 +1,47 @@
import { expect, it, vi } from 'vitest';
import { dispatchFrigateCardErrorEvent } from '../../../src/components-lib/message/dispatch';
import { FrigateCardError } from '../../../src/types';
// @vitest-environment jsdom
it('should ignore non-error', () => {
const element = document.createElement('div');
const handler = vi.fn();
element.addEventListener('frigate-card:message', handler);
dispatchFrigateCardErrorEvent(element, 'NOT_FRIGATE_EVENT');
expect(handler).not.toBeCalled();
});
it('should dispatch error', () => {
const element = document.createElement('div');
const handler = vi.fn();
element.addEventListener('frigate-card:message', handler);
dispatchFrigateCardErrorEvent(element, new Error('ERROR'));
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: expect.objectContaining({
message: 'ERROR',
}),
}),
);
});
it('should dispatch error with context', () => {
const element = document.createElement('div');
const handler = vi.fn();
element.addEventListener('frigate-card:message', handler);
dispatchFrigateCardErrorEvent(element, new FrigateCardError('ERROR', 'CONTEXT'));
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: expect.objectContaining({
message: 'ERROR',
context: 'CONTEXT',
}),
}),
);
});