forked from Github/frigate
switch to vite
This commit is contained in:
@@ -1,25 +1,17 @@
|
||||
import { h } from 'preact';
|
||||
import * as Api from '../api';
|
||||
import * as IDB from 'idb-keyval';
|
||||
import * as PreactRouter from 'preact-router';
|
||||
import App from '../App';
|
||||
import { render, screen } from '@testing-library/preact';
|
||||
import { render, screen } from 'testing-library';
|
||||
|
||||
describe('App', () => {
|
||||
let mockUseConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(IDB, 'get').mockImplementation(() => Promise.resolve(undefined));
|
||||
jest.spyOn(IDB, 'set').mockImplementation(() => Promise.resolve(true));
|
||||
mockUseConfig = jest.spyOn(Api, 'useConfig').mockImplementation(() => ({
|
||||
data: { cameras: { front: { name: 'front', objects: { track: ['taco', 'cat', 'dog'] } } } },
|
||||
}));
|
||||
jest.spyOn(Api, 'useApiHost').mockImplementation(() => 'http://base-url.local:5000');
|
||||
jest.spyOn(PreactRouter, 'Router').mockImplementation(() => <div data-testid="router" />);
|
||||
});
|
||||
|
||||
test('shows a loading indicator while loading', async () => {
|
||||
mockUseConfig.mockReturnValue({ status: 'loading' });
|
||||
render(<App />);
|
||||
await screen.findByTestId('app');
|
||||
expect(screen.queryByLabelText('Loading…')).toBeInTheDocument();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { h } from 'preact';
|
||||
import * as Context from '../context';
|
||||
import AppBar from '../AppBar';
|
||||
import { fireEvent, render, screen } from '@testing-library/preact';
|
||||
import { fireEvent, render, screen } from 'testing-library';
|
||||
|
||||
describe('AppBar', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1,40 +1,17 @@
|
||||
import { h } from 'preact';
|
||||
import * as Api from '../api';
|
||||
import * as Context from '../context';
|
||||
import Sidebar from '../Sidebar';
|
||||
import { render, screen } from '@testing-library/preact';
|
||||
import { render, screen } from 'testing-library';
|
||||
|
||||
describe('Sidebar', () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(Api, 'useConfig').mockImplementation(() => ({
|
||||
data: {
|
||||
cameras: {
|
||||
front: { name: 'front', objects: { track: ['taco', 'cat', 'dog'] }, record: { enabled: true } },
|
||||
side: { name: 'side', objects: { track: ['taco', 'cat', 'dog'] }, record: { enabled: false } },
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jest.spyOn(Context, 'useDrawer').mockImplementation(() => ({ showDrawer: true, setShowDrawer: () => {} }));
|
||||
});
|
||||
|
||||
test('does not render cameras by default', async () => {
|
||||
render(<Sidebar />);
|
||||
const { findByText } = render(<Sidebar />);
|
||||
await findByText('Cameras');
|
||||
expect(screen.queryByRole('link', { name: 'front' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'side' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('render cameras if in camera route', async () => {
|
||||
window.history.replaceState({}, 'Cameras', '/cameras/front');
|
||||
render(<Sidebar />);
|
||||
expect(screen.queryByRole('link', { name: 'front' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'side' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('render cameras if in record route', async () => {
|
||||
window.history.replaceState({}, 'Front Recordings', '/recording/front');
|
||||
render(<Sidebar />);
|
||||
expect(screen.queryByRole('link', { name: 'front' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'side' })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user