Skip to content

Commit 1cf5ab1

Browse files
authored
Merge pull request #17 from James-Cross/clean-up-more-files
fix: Improve type safety in FilterPanel and update test descriptions …
2 parents a2f208a + 2eb98a8 commit 1cf5ab1

File tree

6 files changed

+7
-27
lines changed

6 files changed

+7
-27
lines changed

src/components/FindHelp/FilterPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default function FilterPanel({ onFilterChange }: Props) {
7878
</select>
7979
</div>
8080

81-
{category && currentCategory && currentCategory.subCategories?.length > 0 && (
81+
{category && Array.isArray(currentCategory?.subCategories) && currentCategory.subCategories.length > 0 && (
8282
<div>
8383
<label htmlFor="subCategory" className="block text-sm font-medium text-gray-700 mb-1">
8484
Subcategory

src/components/FindHelp/FindHelpEntry.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/components/FindHelpEntry.tsx
21
'use client';
32

43
import { useEffect, useState } from 'react';
@@ -35,13 +34,11 @@ export default function FindHelpEntry() {
3534
return (
3635
<section className="p-4 max-w-xl mx-auto">
3736
<h1 className="text-xl font-bold mb-4">Find Help Near You</h1>
38-
3937
{location && (
4038
<p className="text-green-700 mb-4">
4139
Location set: {location.postcode || `${location.lat}, ${location.lng}`}
4240
</p>
4341
)}
44-
4542
{fallbackVisible && (
4643
<form onSubmit={handlePostcodeSubmit} className="flex flex-col gap-2">
4744
<label htmlFor="postcode" className="text-sm font-medium">

tests/components/FilterPanel.test.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
1+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
22
import FilterPanel from '@/components/FindHelp/FilterPanel';
33

4-
// Suppress "not wrapped in act" warnings
54
const originalError = console.error;
65
beforeAll(() => {
76
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;
128
originalError(msg, ...args);
139
});
1410
});
15-
1611
afterAll(() => {
1712
(console.error as jest.Mock).mockRestore();
1813
});
1914

20-
// Mock API fetch
2115
global.fetch = jest.fn(() =>
2216
Promise.resolve({
2317
json: () =>
@@ -58,31 +52,23 @@ describe('FilterPanel', () => {
5852
render(<FilterPanel onFilterChange={mockFilterChange} />);
5953

6054
const categorySelect = await screen.findByLabelText(/category/i);
61-
62-
// Wait for fetch to complete
6355
await screen.findByRole('option', { name: /Foodbank/i });
6456

6557
fireEvent.change(categorySelect, { target: { value: 'foodbank' } });
6658

6759
await waitFor(() => {
6860
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: '' });
7362
});
7463
});
7564

7665
it('shows subcategory options when a category is selected', async () => {
7766
render(<FilterPanel onFilterChange={() => {}} />);
7867
const categorySelect = await screen.findByLabelText(/category/i);
79-
80-
// Wait for fetch and dropdown to stabilise
8168
await screen.findByRole('option', { name: /Foodbank/i });
8269

8370
fireEvent.change(categorySelect, { target: { value: 'foodbank' } });
8471

85-
// Wait for subcategory options to render
8672
expect(await screen.findByRole('option', { name: /Meals/i })).toBeInTheDocument();
8773
expect(await screen.findByRole('option', { name: /Parcels/i })).toBeInTheDocument();
8874
});

tests/components/FindHelpEntry.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ describe('FindHelpEntry', () => {
1717
expect(screen.getByLabelText(/enter your postcode/i)).toBeInTheDocument();
1818
});
1919

20-
it('renders "Use My Location" button', () => {
20+
it('renders continue button', () => {
2121
renderWithContext(<FindHelpEntry />);
2222
expect(screen.getByRole('button', { name: /continue/i })).toBeInTheDocument();
2323
});
2424

25-
it('renders nothing for location status initially', () => {
25+
it('does not show location status initially', () => {
2626
renderWithContext(<FindHelpEntry />);
2727
expect(screen.queryByText(/Location set:/i)).not.toBeInTheDocument();
2828
});

tests/components/FindHelpResults.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ describe('FindHelpResults', () => {
3939
expect(screen.getByText(/Health Clinic/i)).toBeInTheDocument();
4040
});
4141

42-
it('renders "Show map" button and toggles map', () => {
42+
it('toggles map view when "Show map" is clicked', () => {
4343
render(<FindHelpResults />);
4444
const toggle = screen.getByRole('button', { name: /show map/i });
45-
expect(toggle).toBeInTheDocument();
46-
4745
fireEvent.click(toggle);
4846
expect(screen.getByText(/Debug Log/i)).toBeInTheDocument();
4947
});

tests/components/MapView.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { render, screen } from '@testing-library/react';
22
import MapView from '@/components/FindHelp/MapView';
33
import { LocationProvider } from '@/contexts/LocationContext';
44

5-
// ✅ Mock Leaflet and React-Leaflet
65
jest.mock('leaflet');
76
jest.mock('leaflet/dist/leaflet.css', () => {});
87
jest.mock('react-leaflet', () => ({

0 commit comments

Comments
 (0)