|
1 | | -import { render, screen, fireEvent, waitFor, act } from '@testing-library/react'; |
| 1 | +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; |
2 | 2 | import FilterPanel from '@/components/FindHelp/FilterPanel'; |
3 | 3 |
|
4 | | -// Suppress "not wrapped in act" warnings |
5 | 4 | const originalError = console.error; |
6 | 5 | beforeAll(() => { |
7 | 6 | jest.spyOn(console, 'error').mockImplementation((msg, ...args) => { |
8 | | - if ( |
9 | | - typeof msg === 'string' && |
10 | | - msg.includes('not wrapped in act') |
11 | | - ) return; |
| 7 | + if (typeof msg === 'string' && msg.includes('not wrapped in act')) return; |
12 | 8 | originalError(msg, ...args); |
13 | 9 | }); |
14 | 10 | }); |
15 | | - |
16 | 11 | afterAll(() => { |
17 | 12 | (console.error as jest.Mock).mockRestore(); |
18 | 13 | }); |
19 | 14 |
|
20 | | -// Mock API fetch |
21 | 15 | global.fetch = jest.fn(() => |
22 | 16 | Promise.resolve({ |
23 | 17 | json: () => |
@@ -58,31 +52,23 @@ describe('FilterPanel', () => { |
58 | 52 | render(<FilterPanel onFilterChange={mockFilterChange} />); |
59 | 53 |
|
60 | 54 | const categorySelect = await screen.findByLabelText(/category/i); |
61 | | - |
62 | | - // Wait for fetch to complete |
63 | 55 | await screen.findByRole('option', { name: /Foodbank/i }); |
64 | 56 |
|
65 | 57 | fireEvent.change(categorySelect, { target: { value: 'foodbank' } }); |
66 | 58 |
|
67 | 59 | await waitFor(() => { |
68 | 60 | const lastCall = mockFilterChange.mock.calls.at(-1)?.[0]; |
69 | | - expect(lastCall).toEqual({ |
70 | | - category: 'foodbank', |
71 | | - subCategory: '' |
72 | | - }); |
| 61 | + expect(lastCall).toEqual({ category: 'foodbank', subCategory: '' }); |
73 | 62 | }); |
74 | 63 | }); |
75 | 64 |
|
76 | 65 | it('shows subcategory options when a category is selected', async () => { |
77 | 66 | render(<FilterPanel onFilterChange={() => {}} />); |
78 | 67 | const categorySelect = await screen.findByLabelText(/category/i); |
79 | | - |
80 | | - // Wait for fetch and dropdown to stabilise |
81 | 68 | await screen.findByRole('option', { name: /Foodbank/i }); |
82 | 69 |
|
83 | 70 | fireEvent.change(categorySelect, { target: { value: 'foodbank' } }); |
84 | 71 |
|
85 | | - // Wait for subcategory options to render |
86 | 72 | expect(await screen.findByRole('option', { name: /Meals/i })).toBeInTheDocument(); |
87 | 73 | expect(await screen.findByRole('option', { name: /Parcels/i })).toBeInTheDocument(); |
88 | 74 | }); |
|
0 commit comments