Skip to content

Commit

Permalink
test(web): routes/Cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong authored and blakeblackshear committed Feb 20, 2021
1 parent 7314572 commit d8b80f0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions web/src/routes/__tests__/Cameras.test.jsx
Original file line number Diff line number Diff line change
@@ -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:https://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');
});
});

0 comments on commit d8b80f0

Please sign in to comment.