Files
advanced-camera-card/tests/card-controller/actions/actions/custom.test.ts
T
Dermot Duffy 75ae7720d3 fix: Confirmations should apply to all actions (#1959)
This also refactors how generic HA actions are handled, and improves
typing of actions.


[skip ci]
2025-03-15 14:32:48 -07:00

38 lines
973 B
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { CustomAction } from '../../../../src/card-controller/actions/actions/custom';
import { createCardAPI } from '../../../test-utils';
// @vitest-environment jsdom
describe('CustomAction', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('should open the URL in a new window', async () => {
const handler = vi.fn();
const element = document.createElement('div');
element.addEventListener('ll-custom', handler);
const api = createCardAPI();
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
const action = new CustomAction(
{},
{
action: 'fire-dom-event' as const,
foo: 'bar',
1: 2,
},
{},
);
await action.execute(api);
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: { action: 'fire-dom-event', foo: 'bar', 1: 2 },
}),
);
});
});