fix: Confirmations should apply to all actions (#1959)
This also refactors how generic HA actions are handled, and improves typing of actions. [skip ci]
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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 },
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user