Files
advanced-camera-card/tests/card-controller/actions/actions/ptz-multi.test.ts
T
Dermot Duffy cc376a8be1 feat: Rename the card to advanced-camera-card (#1873)
Whilst the Frigate support in this card is the best among camera
engines, the name incorrectly suggests that Frigate is a requirement.
Instead, to broaden the appeal, change to more camera agnostic name.
This does not suggest any change in priority, role or support for
Frigate.

This change is likely to be bug prone, due to the size of the rename --
the code contains 1500+ references to "Frigate" most of which make sense
to rename, some which do not, all of which needed human assessment.

- Closes #1298


BREAKING CHANGE: References to `frigate-card` in all kinds of
configuration need to be updated to `advanced-camera-card`. An automated
config upgrade should take care of the majority of usecases (click `Edit
-> Upgrade -> Save`), though may not be perfect.
2025-02-06 19:32:32 -08:00

151 lines
4.2 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { Capabilities } from '../../../../src/camera-manager/capabilities';
import { PTZMultiAction } from '../../../../src/card-controller/actions/actions/ptz-multi';
import {
createCameraManager,
createCardAPI,
createStore,
createView,
} from '../../../test-utils';
describe('should handle ptz multi action', () => {
describe.each([
['with explicit target_id', 'camera.office'],
['without explicit target_id', null],
])('%s', async (_testTitle: string, targetID: string | null) => {
it('should use real ptz when camera has ptz support', async () => {
const api = createCardAPI();
vi.mocked(api.getViewManager().getView).mockReturnValue(
createView({
camera: 'camera.office',
}),
);
const store = createStore([
{
cameraID: 'camera.office',
capabilities: new Capabilities({ ptz: { left: ['relative'] } }),
},
]);
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager(store));
const action = new PTZMultiAction(
{},
{
action: 'fire-dom-event',
advanced_camera_card_action: 'ptz_multi',
ptz_action: 'left',
...(targetID && { target_id: targetID }),
},
);
await action.execute(api);
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
'camera.office',
'left',
{
phase: undefined,
preset: undefined,
},
);
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
});
it('should use digital ptz when camera does not have ptz support', async () => {
const api = createCardAPI();
vi.mocked(api.getViewManager().getView).mockReturnValue(
createView({
camera: 'camera.office',
}),
);
const store = createStore([
{
cameraID: 'camera.office',
},
]);
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager(store));
const action = new PTZMultiAction(
{},
{
action: 'fire-dom-event',
advanced_camera_card_action: 'ptz_multi',
ptz_action: 'right',
...(targetID && { target_id: targetID }),
},
);
await action.execute(api);
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenLastCalledWith({
zoom: {
'camera.office': {
observed: undefined,
requested: expect.objectContaining({
pan: {
x: 55,
y: 50,
},
zoom: 1,
}),
},
},
});
});
});
it('should do nothing without a view or explicit target_id', async () => {
const api = createCardAPI();
const store = createStore([
{
cameraID: 'camera.office',
},
]);
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager(store));
const action = new PTZMultiAction(
{},
{
action: 'fire-dom-event',
advanced_camera_card_action: 'ptz_multi',
ptz_action: 'right',
},
);
await action.execute(api);
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
});
it('should do nothing with a media-less view without an explicit target_id', async () => {
const api = createCardAPI();
vi.mocked(api.getViewManager().getView).mockReturnValue(
createView({
view: 'timeline',
}),
);
const store = createStore([
{
cameraID: 'camera.office',
},
]);
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager(store));
const action = new PTZMultiAction(
{},
{
action: 'fire-dom-event',
advanced_camera_card_action: 'ptz_multi',
ptz_action: 'right',
},
);
await action.execute(api);
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
});
});