Fix card-wide actions.

This commit is contained in:
Dermot Duffy
2024-04-07 21:18:55 -07:00
parent 43406b21e6
commit 9c9548afc8
3 changed files with 52 additions and 10 deletions
+22 -4
View File
@@ -14,7 +14,7 @@ import {
frigateCardHandleActionConfig,
getActionConfigGivenAction,
} from '../../src/utils/action.js';
import { ActionsManager } from '../../src/card-controller/actions-manager';
import { ActionsManager, Interaction } from '../../src/card-controller/actions-manager';
import {
createCardAPI,
createConfig,
@@ -165,7 +165,9 @@ describe('ActionsManager.handleInteraction', () => {
};
vi.mocked(getActionConfigGivenAction).mockReturnValue(actionForThisInteraction);
manager.handleInteraction('tap');
manager.handleInteractionEvent(
new CustomEvent<Interaction>('event', { detail: { action: 'tap' } }),
);
expect(frigateCardHandleActionConfig).toBeCalledWith(
element,
@@ -176,13 +178,29 @@ describe('ActionsManager.handleInteraction', () => {
);
});
it('should not handle interaction', () => {
it('should not handle interaction without hass', () => {
const api = createCardAPI();
const manager = new ActionsManager(api);
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(null);
// No values of hass.
manager.handleInteraction('tap');
manager.handleInteractionEvent(
new CustomEvent<Interaction>('event', { detail: { action: 'tap' } }),
);
expect(frigateCardHandleActionConfig).not.toBeCalledWith();
});
it('should not handle malformed interaction', () => {
const api = createCardAPI();
const manager = new ActionsManager(api);
manager.handleInteractionEvent(
new CustomEvent<Interaction>('event', {
// Malformed interaction type.
detail: { action: 'double_finger_snap' } as unknown as Interaction,
}),
);
expect(frigateCardHandleActionConfig).not.toBeCalledWith();
});
});