mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
test(web): AutoUpdatingCameraImage
This commit is contained in:
parent
e729bd52aa
commit
53288d361c
@ -4,7 +4,7 @@ import { useCallback, useState } from 'preact/hooks';
|
|||||||
|
|
||||||
const MIN_LOAD_TIMEOUT_MS = 200;
|
const MIN_LOAD_TIMEOUT_MS = 200;
|
||||||
|
|
||||||
export default function AutoUpdatingCameraImage({ camera, searchParams, showFps = true }) {
|
export default function AutoUpdatingCameraImage({ camera, searchParams = '', showFps = true }) {
|
||||||
const [key, setKey] = useState(Date.now());
|
const [key, setKey] = useState(Date.now());
|
||||||
const [fps, setFps] = useState(0);
|
const [fps, setFps] = useState(0);
|
||||||
|
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
import { h } from 'preact';
|
||||||
|
import AutoUpdatingCameraImage from '../AutoUpdatingCameraImage';
|
||||||
|
import { screen, render } from '@testing-library/preact';
|
||||||
|
|
||||||
|
let mockOnload;
|
||||||
|
jest.mock('../CameraImage', () => {
|
||||||
|
function CameraImage({ onload, searchParams }) {
|
||||||
|
mockOnload = () => {
|
||||||
|
onload();
|
||||||
|
};
|
||||||
|
return <div data-testid="camera-image">{searchParams}</div>;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
__esModule: true,
|
||||||
|
default: CameraImage,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('AutoUpdatingCameraImage', () => {
|
||||||
|
let dateNowSpy;
|
||||||
|
beforeEach(() => {
|
||||||
|
dateNowSpy = jest.spyOn(Date, 'now').mockReturnValue(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shows FPS by default', async () => {
|
||||||
|
render(<AutoUpdatingCameraImage camera="tacos" />);
|
||||||
|
expect(screen.queryByText('Displaying at 0fps')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not show FPS if turned off', async () => {
|
||||||
|
render(<AutoUpdatingCameraImage camera="tacos" showFps={false} />);
|
||||||
|
expect(screen.queryByText('Displaying at 0fps')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('on load, sets a new cache key to search params', async () => {
|
||||||
|
dateNowSpy.mockReturnValueOnce(100).mockReturnValueOnce(200).mockReturnValueOnce(300);
|
||||||
|
render(<AutoUpdatingCameraImage camera="tacos" searchParams="foo" />);
|
||||||
|
mockOnload();
|
||||||
|
jest.runAllTimers();
|
||||||
|
expect(screen.queryByText('cache=100&foo')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user