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:
Dermot Duffy
2025-03-15 14:32:48 -07:00
committed by GitHub
parent a79ffa6edc
commit 75ae7720d3
90 changed files with 1332 additions and 854 deletions
@@ -0,0 +1,80 @@
import { describe, expect, it, vi } from 'vitest';
import { MoreInfoAction } from '../../../../src/card-controller/actions/actions/more-info';
import { createCardAPI } from '../../../test-utils';
// @vitest-environment jsdom
describe('should handle more-info action', () => {
it('should handle more-info with entity in action', async () => {
const handler = vi.fn();
const element = document.createElement('div');
element.addEventListener('hass-more-info', handler);
const api = createCardAPI();
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
const action = new MoreInfoAction(
{},
{
action: 'more-info',
entity: 'light.office',
},
{},
);
await action.execute(api);
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: { entityId: 'light.office' },
}),
);
});
it('should handle more-info with entity in auxilliary config', async () => {
const handler = vi.fn();
const element = document.createElement('div');
element.addEventListener('hass-more-info', handler);
const api = createCardAPI();
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
const action = new MoreInfoAction(
{},
{
action: 'more-info',
},
{
entity: 'light.office',
},
);
await action.execute(api);
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: { entityId: 'light.office' },
}),
);
});
it('should take no action with any entity', async () => {
const handler = vi.fn();
const element = document.createElement('div');
element.addEventListener('hass-more-info', handler);
const api = createCardAPI();
vi.mocked(api.getCardElementManager().getElement).mockReturnValue(element);
const action = new MoreInfoAction(
{},
{
action: 'more-info',
},
{},
);
await action.execute(api);
expect(handler).not.toBeCalled();
});
});