diff --git a/frontend/src/__tests__/components/Sidebar/SearchBar.test.tsx b/frontend/src/__tests__/components/Sidebar/SearchBar.test.tsx index 551239dc..c9e6daca 100644 --- a/frontend/src/__tests__/components/Sidebar/SearchBar.test.tsx +++ b/frontend/src/__tests__/components/Sidebar/SearchBar.test.tsx @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import {describe, test, expect, vi, afterEach} from 'vitest'; -import {act, cleanup, render, screen, waitFor} from '@testing-library/react'; +import {describe, test, expect, afterEach} from 'vitest'; +import {act, cleanup, render, screen} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import i18n from '../../../util/i18nForTests'; @@ -15,28 +15,6 @@ import {Store} from '../../../store'; import {selectDistrict} from '../../../store/DataSelectionSlice'; describe('SearchBar', () => { - // We mock fetch to return two entries for searchable districts. - const fetch = vi.fn().mockImplementation(() => { - return Promise.resolve({ - json: () => { - return Promise.resolve([ - { - RS: '09771', - GEN: 'Aichach-Friedberg', - BEZ: 'LK', - }, - { - RS: '12345', - GEN: 'Test District', - BEZ: 'Test Type', - }, - ]); - }, - }); - }); - - vi.stubGlobal('fetch', fetch); - test('countyList loaded correctly', async () => { render( @@ -46,8 +24,6 @@ describe('SearchBar', () => { ); - await waitFor(() => expect(fetch).toHaveBeenCalled()); - await screen.findByPlaceholderText('germany'); await userEvent.click(screen.getByPlaceholderText('germany')); @@ -69,8 +45,6 @@ describe('SearchBar', () => { ); - await waitFor(() => expect(fetch).toHaveBeenCalled()); - act(() => { Store.dispatch(selectDistrict({ags: '12345', name: 'Test District', type: 'Test Type'})); }); @@ -87,8 +61,6 @@ describe('SearchBar', () => { ); - await waitFor(() => expect(fetch).toHaveBeenCalled()); - await userEvent.type(screen.getByPlaceholderText('germany'), 'Aic{Enter}'); await screen.findByDisplayValue('Aichach-Friedberg (BEZ.LK)'); @@ -108,8 +80,6 @@ describe('SearchBar', () => { ); - await waitFor(() => expect(fetch).toHaveBeenCalled()); - await userEvent.type(screen.getByPlaceholderText('germany'), '{ArrowDown}{Enter}'); await screen.findByDisplayValue('Test District (BEZ.Test Type)'); diff --git a/frontend/src/__tests__/mocks/handlers.ts b/frontend/src/__tests__/mocks/handlers.ts index bdcfcec1..319b4d78 100644 --- a/frontend/src/__tests__/mocks/handlers.ts +++ b/frontend/src/__tests__/mocks/handlers.ts @@ -42,4 +42,18 @@ export default [ }, }); }), + http.get('/assets/lk_germany_reduced_list.json', () => { + return HttpResponse.json([ + { + RS: '09771', + GEN: 'Aichach-Friedberg', + BEZ: 'LK', + }, + { + RS: '12345', + GEN: 'Test District', + BEZ: 'Test Type', + }, + ]); + }), ];