mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
test(web): routes/Cameras
This commit is contained in:
parent
7314572d97
commit
d8b80f0fe9
43
web/src/routes/__tests__/Cameras.test.jsx
Normal file
43
web/src/routes/__tests__/Cameras.test.jsx
Normal file
@ -0,0 +1,43 @@
|
||||
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';
|
||||
|
||||
jest.mock('../../api/baseUrl');
|
||||
|
||||
describe('Cameras Route', () => {
|
||||
let useConfigMock;
|
||||
|
||||
beforeEach(() => {
|
||||
useConfigMock = jest.spyOn(Api, 'useConfig').mockImplementation(() => ({
|
||||
data: {
|
||||
cameras: {
|
||||
front: { name: 'front', objects: { track: ['taco', 'cat', 'dog'] } },
|
||||
side: { name: 'side', objects: { track: ['taco', 'cat', 'dog'] } },
|
||||
},
|
||||
},
|
||||
status: 'loaded',
|
||||
}));
|
||||
jest.spyOn(Api, 'useApiHost').mockImplementation(() => 'http://base-url.local:5000');
|
||||
jest.spyOn(CameraImage, 'default').mockImplementation(() => <div data-testid="camera-image" />);
|
||||
});
|
||||
|
||||
test('shows an ActivityIndicator if not yet loaded', async () => {
|
||||
useConfigMock.mockReturnValueOnce(() => ({ status: 'loading' }));
|
||||
render(<Cameras />);
|
||||
expect(screen.queryByLabelText('Loading…')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('shows cameras', async () => {
|
||||
render(<Cameras />);
|
||||
|
||||
expect(screen.queryByLabelText('Loading…')).not.toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByText('front')).toBeInTheDocument();
|
||||
expect(screen.queryByText('front').closest('a')).toHaveAttribute('href', '/cameras/front');
|
||||
|
||||
expect(screen.queryByText('side')).toBeInTheDocument();
|
||||
expect(screen.queryByText('side').closest('a')).toHaveAttribute('href', '/cameras/side');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user