mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-07-26 13:47:03 +02:00
test(web): App
This commit is contained in:
parent
c12aec7c8f
commit
3348f04889
@ -20,3 +20,5 @@ beforeEach(() => {
|
|||||||
throw new Error(`Unexpected fetch to ${url}, ${JSON.stringify(opts)}`);
|
throw new Error(`Unexpected fetch to ${url}, ${JSON.stringify(opts)}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jest.mock('../src/env');
|
||||||
|
@ -14,7 +14,7 @@ export default function App() {
|
|||||||
return (
|
return (
|
||||||
<DarkModeProvider>
|
<DarkModeProvider>
|
||||||
<DrawerProvider>
|
<DrawerProvider>
|
||||||
<div className="w-full">
|
<div data-testid="app" className="w-full">
|
||||||
<AppBar />
|
<AppBar />
|
||||||
{status !== FetchStatus.LOADED ? (
|
{status !== FetchStatus.LOADED ? (
|
||||||
<div className="flex flex-grow-1 min-h-screen justify-center items-center">
|
<div className="flex flex-grow-1 min-h-screen justify-center items-center">
|
||||||
|
@ -2,6 +2,7 @@ import { h, Fragment } from 'preact';
|
|||||||
import LinkedLogo from './components/LinkedLogo';
|
import LinkedLogo from './components/LinkedLogo';
|
||||||
import { Match } from 'preact-router/match';
|
import { Match } from 'preact-router/match';
|
||||||
import { memo } from 'preact/compat';
|
import { memo } from 'preact/compat';
|
||||||
|
import { ENV } from './env';
|
||||||
import { useConfig } from './api';
|
import { useConfig } from './api';
|
||||||
import { useMemo } from 'preact/hooks';
|
import { useMemo } from 'preact/hooks';
|
||||||
import NavigationDrawer, { Destination, Separator } from './components/NavigationDrawer';
|
import NavigationDrawer, { Destination, Separator } from './components/NavigationDrawer';
|
||||||
@ -30,7 +31,7 @@ export default function Sidebar() {
|
|||||||
<Destination href="/debug" text="Debug" />
|
<Destination href="/debug" text="Debug" />
|
||||||
<Separator />
|
<Separator />
|
||||||
<div className="flex flex-grow" />
|
<div className="flex flex-grow" />
|
||||||
{import.meta.env.MODE !== 'production' ? (
|
{ENV !== 'production' ? (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Destination href="/styleguide" text="Style Guide" />
|
<Destination href="/styleguide" text="Style Guide" />
|
||||||
<Separator />
|
<Separator />
|
||||||
|
2
web/src/__mocks__/env.js
Normal file
2
web/src/__mocks__/env.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export const ENV = 'test';
|
||||||
|
export const API_HOST = 'http://base-url.local:5000';
|
27
web/src/__tests__/App.test.jsx
Normal file
27
web/src/__tests__/App.test.jsx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
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 +0,0 @@
|
|||||||
export const baseUrl = 'http://base-url.local:5000';
|
|
@ -2,8 +2,6 @@ import { h } from 'preact';
|
|||||||
import { ApiProvider, useFetch, useApiHost } from '..';
|
import { ApiProvider, useFetch, useApiHost } from '..';
|
||||||
import { render, screen } from '@testing-library/preact';
|
import { render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
jest.mock('../baseUrl');
|
|
||||||
|
|
||||||
describe('useApiHost', () => {
|
describe('useApiHost', () => {
|
||||||
test('is set from the baseUrl', async () => {
|
test('is set from the baseUrl', async () => {
|
||||||
function Test() {
|
function Test() {
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export const baseUrl = import.meta.env.SNOWPACK_PUBLIC_API_HOST || window.baseUrl || '';
|
import { API_HOST } from '../env';
|
||||||
|
export const baseUrl = API_HOST || window.baseUrl || '';
|
||||||
|
@ -4,8 +4,6 @@ import * as Hooks from '../../hooks';
|
|||||||
import CameraImage from '../CameraImage';
|
import CameraImage from '../CameraImage';
|
||||||
import { render, screen } from '@testing-library/preact';
|
import { render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
jest.mock('../../api/baseUrl');
|
|
||||||
|
|
||||||
describe('CameraImage', () => {
|
describe('CameraImage', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(Api, 'useConfig').mockImplementation(() => {
|
jest.spyOn(Api, 'useConfig').mockImplementation(() => {
|
||||||
|
2
web/src/env.js
Normal file
2
web/src/env.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export const ENV = import.meta.env.MODE;
|
||||||
|
export const API_HOST = import.meta.env.SNOWPACK_PUBLIC_API_HOST;
|
@ -5,8 +5,6 @@ import * as Context from '../../context';
|
|||||||
import Camera from '../Camera';
|
import Camera from '../Camera';
|
||||||
import { fireEvent, render, screen } from '@testing-library/preact';
|
import { fireEvent, render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
jest.mock('../../api/baseUrl');
|
|
||||||
|
|
||||||
describe('Camera Route', () => {
|
describe('Camera Route', () => {
|
||||||
let mockUsePersistence, mockSetOptions;
|
let mockUsePersistence, mockSetOptions;
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ import Cameras from '../Cameras';
|
|||||||
import * as CameraImage from '../../components/CameraImage';
|
import * as CameraImage from '../../components/CameraImage';
|
||||||
import { render, screen } from '@testing-library/preact';
|
import { render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
jest.mock('../../api/baseUrl');
|
|
||||||
|
|
||||||
describe('Cameras Route', () => {
|
describe('Cameras Route', () => {
|
||||||
let useConfigMock;
|
let useConfigMock;
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ import * as Api from '../../api';
|
|||||||
import Debug from '../Debug';
|
import Debug from '../Debug';
|
||||||
import { render, screen } from '@testing-library/preact';
|
import { render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
jest.mock('../../api/baseUrl');
|
|
||||||
|
|
||||||
describe('Debug Route', () => {
|
describe('Debug Route', () => {
|
||||||
let useStatsMock;
|
let useStatsMock;
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ import * as Api from '../../api';
|
|||||||
import Event from '../Event';
|
import Event from '../Event';
|
||||||
import { render, screen } from '@testing-library/preact';
|
import { render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
jest.mock('../../api/baseUrl');
|
|
||||||
|
|
||||||
describe('Event Route', () => {
|
describe('Event Route', () => {
|
||||||
let useEventMock;
|
let useEventMock;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user