Files
advanced-camera-card/tests/card-controller/actions/actions/more-info.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

81 lines
2.0 KiB
TypeScript

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();
});
});