diff --git a/website/src/__mocks__/react-feather.tsx b/website/src/__mocks__/react-feather.tsx index dc9445cc11..fec1475806 100644 --- a/website/src/__mocks__/react-feather.tsx +++ b/website/src/__mocks__/react-feather.tsx @@ -3,7 +3,9 @@ import type { ComponentType } from 'react'; import * as feather from 'react-feather'; module.exports = mapValues(feather, (_component, name) => { - const MockComponent = jest.fn(() =>
); + const MockComponent = jest.fn((props) => ( + + )); (MockComponent as ComponentType).displayName = name; return MockComponent; }); diff --git a/website/src/test-utils/mockDom.ts b/website/src/test-utils/mockDom.ts index 8e773852d4..9c8b575424 100644 --- a/website/src/test-utils/mockDom.ts +++ b/website/src/test-utils/mockDom.ts @@ -1,3 +1,4 @@ +const nativeScroll = window.scroll; const nativeScrollTo = window.scrollTo; const nativePerformance = window.performance; const nativeMatchMedia = window.matchMedia; @@ -5,6 +6,7 @@ const nativeScrollIntoView = Element.prototype.scrollIntoView; export function mockDom() { // Mock some of the DOM environment functions that are missing from JSDom + window.scroll = jest.fn(); window.scrollTo = jest.fn(); if (!window.performance) { @@ -23,6 +25,7 @@ export function mockDom() { } export function mockDomReset() { + window.scroll = nativeScroll; window.scrollTo = nativeScrollTo; // @ts-expect-error We insist diff --git a/website/src/views/components/SearchBox.test.tsx b/website/src/views/components/SearchBox.test.tsx index 6268718b23..db0a82ab3f 100644 --- a/website/src/views/components/SearchBox.test.tsx +++ b/website/src/views/components/SearchBox.test.tsx @@ -1,48 +1,154 @@ -import { shallow } from 'enzyme'; -import SearchBox from './SearchBox'; +import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import SearchBox, { Props } from './SearchBox'; + +const SOME_TEXT = 'existing'; + +const defaultProps: Props = { + throttle: 0, + isLoading: false, + value: SOME_TEXT, + onChange: jest.fn(), + onSearch: jest.fn(), +}; describe(SearchBox, () => { - test('should match snapshot', () => { - expect( - shallow( -Select a venue on the left to see its timetable
+eg. incorrect building outline, missing walkways
+e.g. incorrect building outline, missing walkways
We don't have data for this venue.
+We don't have data for this venue.
-- {location.roomName} ({venue}) - {location.floor != null && ( - <> - {' '} - is on {floorName(location.floor)} - > - )} - . -
- - {position ? ( + return ( +
+ {location.roomName} ({venue})
+ {location.floor != null && (
<>
-
- See a problem?{' '}
-
We don't have the location of this venue, sorry :(
-
+ See a problem?{' '}
+
We don't have the location of this venue, sorry :(
+Select a venue on the left to see its timetable
-