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

58 lines
1.4 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { NavigateAction } from '../../../../src/card-controller/actions/actions/navigate';
import { createCardAPI } from '../../../test-utils';
// @vitest-environment jsdom
describe('should handle navigate action', () => {
it('should handle navigate action', async () => {
const handler = vi.fn();
window.addEventListener('location-changed', handler);
const action = new NavigateAction(
{},
{
action: 'navigate',
navigation_path: '/path',
},
{},
);
const historyLength = history.length;
await action.execute(createCardAPI());
expect(history.length).toBe(historyLength + 1);
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: { replace: false },
}),
);
});
it('should handle navigate action that replaces', async () => {
const handler = vi.fn();
window.addEventListener('location-changed', handler);
const action = new NavigateAction(
{},
{
action: 'navigate',
navigation_path: '/path',
navigation_replace: true,
},
{},
);
const historyLength = history.length;
await action.execute(createCardAPI());
expect(history.length).toBe(historyLength);
expect(handler).toBeCalledWith(
expect.objectContaining({
detail: { replace: true },
}),
);
});
});