forked from Github/frigate
feat(web): detect, clips, snapshots toggles
This commit is contained in:
committed by
Blake Blackshear
parent
e399790442
commit
b6ba6459fb
@@ -1,8 +1,9 @@
|
||||
import { h } from 'preact';
|
||||
import * as Api from '../../api';
|
||||
import Cameras from '../Cameras';
|
||||
import * as CameraImage from '../../components/CameraImage';
|
||||
import { render, screen } from '@testing-library/preact';
|
||||
import * as Mqtt from '../../api/mqtt';
|
||||
import Cameras from '../Cameras';
|
||||
import { fireEvent, render, screen } from '@testing-library/preact';
|
||||
|
||||
describe('Cameras Route', () => {
|
||||
let useConfigMock;
|
||||
@@ -19,6 +20,7 @@ describe('Cameras Route', () => {
|
||||
}));
|
||||
jest.spyOn(Api, 'useApiHost').mockImplementation(() => 'http://base-url.local:5000');
|
||||
jest.spyOn(CameraImage, 'default').mockImplementation(() => <div data-testid="camera-image" />);
|
||||
jest.spyOn(Mqtt, 'useMqtt').mockImplementation(() => ({ value: { payload: 'OFF' }, send: jest.fn() }));
|
||||
});
|
||||
|
||||
test('shows an ActivityIndicator if not yet loaded', async () => {
|
||||
@@ -38,4 +40,35 @@ describe('Cameras Route', () => {
|
||||
expect(screen.queryByText('side')).toBeInTheDocument();
|
||||
expect(screen.queryByText('side').closest('a')).toHaveAttribute('href', '/cameras/side');
|
||||
});
|
||||
|
||||
test('buttons toggle detect, clips, and snapshots', async () => {
|
||||
const sendDetect = jest.fn();
|
||||
const sendClips = jest.fn();
|
||||
const sendSnapshots = jest.fn();
|
||||
jest.spyOn(Mqtt, 'useDetectState').mockImplementation(() => {
|
||||
return { payload: 'ON', send: sendDetect };
|
||||
});
|
||||
jest.spyOn(Mqtt, 'useClipsState').mockImplementation(() => {
|
||||
return { payload: 'OFF', send: sendClips };
|
||||
});
|
||||
jest.spyOn(Mqtt, 'useSnapshotsState').mockImplementation(() => {
|
||||
return { payload: 'ON', send: sendSnapshots };
|
||||
});
|
||||
|
||||
render(<Cameras />);
|
||||
|
||||
fireEvent.click(screen.getAllByLabelText('Toggle detect off')[0]);
|
||||
expect(sendDetect).toHaveBeenCalledWith('OFF');
|
||||
expect(sendDetect).toHaveBeenCalledTimes(1);
|
||||
|
||||
fireEvent.click(screen.getAllByLabelText('Toggle snapshots off')[0]);
|
||||
expect(sendSnapshots).toHaveBeenCalledWith('OFF');
|
||||
|
||||
fireEvent.click(screen.getAllByLabelText('Toggle clips on')[0]);
|
||||
expect(sendClips).toHaveBeenCalledWith('ON');
|
||||
|
||||
expect(sendDetect).toHaveBeenCalledTimes(1);
|
||||
expect(sendSnapshots).toHaveBeenCalledTimes(1);
|
||||
expect(sendClips).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user