From 9ba6054140261c2dee3da20665d575ff97915a04 Mon Sep 17 00:00:00 2001 From: Paul Armstrong Date: Sun, 14 Feb 2021 07:10:34 -0800 Subject: [PATCH] test(web): Sidebar --- web/src/__tests__/Sidebar.test.jsx | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 web/src/__tests__/Sidebar.test.jsx diff --git a/web/src/__tests__/Sidebar.test.jsx b/web/src/__tests__/Sidebar.test.jsx new file mode 100644 index 000000000..a2098f898 --- /dev/null +++ b/web/src/__tests__/Sidebar.test.jsx @@ -0,0 +1,33 @@ +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'; + +describe('Sidebar', () => { + beforeEach(() => { + jest.spyOn(Api, 'useConfig').mockImplementation(() => ({ + data: { + cameras: { + front: { name: 'front', objects: { track: ['taco', 'cat', 'dog'] } }, + side: { name: 'side', objects: { track: ['taco', 'cat', 'dog'] } }, + }, + }, + })); + + jest.spyOn(Context, 'useDrawer').mockImplementation(() => ({ showDrawer: true, setShowDrawer: () => {} })); + }); + + test('does not render cameras by default', async () => { + render(); + 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(); + expect(screen.queryByRole('link', { name: 'front' })).toBeInTheDocument(); + expect(screen.queryByRole('link', { name: 'side' })).toBeInTheDocument(); + }); +});