forked from blakeblackshear/frigate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e729bd5
commit 53288d3
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
web/src/components/__tests__/AutoUpdatingCameraImage.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |