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,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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user