Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/FindHelp/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function FilterPanel({ onFilterChange }: Props) {
</select>
</div>

{category && currentCategory && currentCategory.subCategories?.length > 0 && (
{category && Array.isArray(currentCategory?.subCategories) && currentCategory.subCategories.length > 0 && (
<div>
<label htmlFor="subCategory" className="block text-sm font-medium text-gray-700 mb-1">
Subcategory
Expand Down
3 changes: 0 additions & 3 deletions src/components/FindHelp/FindHelpEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/components/FindHelpEntry.tsx
'use client';

import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -35,13 +34,11 @@ export default function FindHelpEntry() {
return (
<section className="p-4 max-w-xl mx-auto">
<h1 className="text-xl font-bold mb-4">Find Help Near You</h1>

{location && (
<p className="text-green-700 mb-4">
Location set: {location.postcode || `${location.lat}, ${location.lng}`}
</p>
)}

{fallbackVisible && (
<form onSubmit={handlePostcodeSubmit} className="flex flex-col gap-2">
<label htmlFor="postcode" className="text-sm font-medium">
Expand Down
20 changes: 3 additions & 17 deletions tests/components/FilterPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import FilterPanel from '@/components/FindHelp/FilterPanel';

// Suppress "not wrapped in act" warnings
const originalError = console.error;
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation((msg, ...args) => {
if (
typeof msg === 'string' &&
msg.includes('not wrapped in act')
) return;
if (typeof msg === 'string' && msg.includes('not wrapped in act')) return;
originalError(msg, ...args);
});
});

afterAll(() => {
(console.error as jest.Mock).mockRestore();
});

// Mock API fetch
global.fetch = jest.fn(() =>
Promise.resolve({
json: () =>
Expand Down Expand Up @@ -58,31 +52,23 @@ describe('FilterPanel', () => {
render(<FilterPanel onFilterChange={mockFilterChange} />);

const categorySelect = await screen.findByLabelText(/category/i);

// Wait for fetch to complete
await screen.findByRole('option', { name: /Foodbank/i });

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

await waitFor(() => {
const lastCall = mockFilterChange.mock.calls.at(-1)?.[0];
expect(lastCall).toEqual({
category: 'foodbank',
subCategory: ''
});
expect(lastCall).toEqual({ category: 'foodbank', subCategory: '' });
});
});

it('shows subcategory options when a category is selected', async () => {
render(<FilterPanel onFilterChange={() => {}} />);
const categorySelect = await screen.findByLabelText(/category/i);

// Wait for fetch and dropdown to stabilise
await screen.findByRole('option', { name: /Foodbank/i });

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

// Wait for subcategory options to render
expect(await screen.findByRole('option', { name: /Meals/i })).toBeInTheDocument();
expect(await screen.findByRole('option', { name: /Parcels/i })).toBeInTheDocument();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/components/FindHelpEntry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ describe('FindHelpEntry', () => {
expect(screen.getByLabelText(/enter your postcode/i)).toBeInTheDocument();
});

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

it('renders nothing for location status initially', () => {
it('does not show location status initially', () => {
renderWithContext(<FindHelpEntry />);
expect(screen.queryByText(/Location set:/i)).not.toBeInTheDocument();
});
Expand Down
4 changes: 1 addition & 3 deletions tests/components/FindHelpResults.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ describe('FindHelpResults', () => {
expect(screen.getByText(/Health Clinic/i)).toBeInTheDocument();
});

it('renders "Show map" button and toggles map', () => {
it('toggles map view when "Show map" is clicked', () => {
render(<FindHelpResults />);
const toggle = screen.getByRole('button', { name: /show map/i });
expect(toggle).toBeInTheDocument();

fireEvent.click(toggle);
expect(screen.getByText(/Debug Log/i)).toBeInTheDocument();
});
Expand Down
1 change: 0 additions & 1 deletion tests/components/MapView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { render, screen } from '@testing-library/react';
import MapView from '@/components/FindHelp/MapView';
import { LocationProvider } from '@/contexts/LocationContext';

// ✅ Mock Leaflet and React-Leaflet
jest.mock('leaflet');
jest.mock('leaflet/dist/leaflet.css', () => {});
jest.mock('react-leaflet', () => ({
Expand Down