feat: Add custom reload action to reload dashboard (#2217)

- Closes: #2215

---------

Co-authored-by: Felipe Santos <felipecassiors@gmail.com>
This commit is contained in:
Dermot Duffy
2025-10-14 07:37:50 -07:00
committed by GitHub
co-authored by Felipe Santos
parent 7edaac079e
commit 1f41781a84
6 changed files with 61 additions and 0 deletions
@@ -0,0 +1,29 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { mock } from 'vitest-mock-extended';
import { ReloadAction } from '../../../../src/card-controller/actions/actions/reload';
import { createCardAPI } from '../../../test-utils';
// @vitest-environment jsdom
describe('should handle reload action', async () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('should handle reload action', async () => {
const api = createCardAPI();
const action = new ReloadAction(
{},
{
action: 'fire-dom-event',
advanced_camera_card_action: 'reload',
},
);
const location: Location & { origin: string } = mock<Location>();
vi.spyOn(window, 'location', 'get').mockReturnValue(location);
await action.execute(api);
expect(location.reload).toBeCalledTimes(1);
});
});
@@ -27,6 +27,7 @@ import { PTZAction } from '../../../src/card-controller/actions/actions/ptz';
import { PTZControlsAction } from '../../../src/card-controller/actions/actions/ptz-controls';
import { PTZDigitalAction } from '../../../src/card-controller/actions/actions/ptz-digital';
import { PTZMultiAction } from '../../../src/card-controller/actions/actions/ptz-multi';
import { ReloadAction } from '../../../src/card-controller/actions/actions/reload';
import { ScreenshotAction } from '../../../src/card-controller/actions/actions/screenshot';
import { SleepAction } from '../../../src/card-controller/actions/actions/sleep';
import { StatusBarAction } from '../../../src/card-controller/actions/actions/status-bar';
@@ -186,6 +187,7 @@ describe('ActionFactory', () => {
},
InternalCallbackAction,
],
[{ advanced_camera_card_action: 'reload' as const }, ReloadAction],
])(
'advanced_camera_card_action: $advanced_camera_card_action',
(action: Partial<ActionConfig>, classObject: object) => {