2026-02-02 20:34:35 +00:00
|
|
|
/**
|
|
|
|
|
* SchoolCard Component Tests
|
|
|
|
|
*/
|
|
|
|
|
|
2026-03-05 13:00:34 +00:00
|
|
|
import '@testing-library/jest-dom';
|
2026-02-02 20:34:35 +00:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
|
|
|
import { SchoolCard } from '@/components/SchoolCard';
|
|
|
|
|
import type { School } from '@/lib/types';
|
|
|
|
|
|
2026-03-05 13:00:34 +00:00
|
|
|
const mockSchool = {
|
2026-02-02 20:34:35 +00:00
|
|
|
urn: 100001,
|
|
|
|
|
school_name: 'Test Primary School',
|
|
|
|
|
local_authority: 'Westminster',
|
|
|
|
|
school_type: 'Academy',
|
|
|
|
|
address: '123 Test Street',
|
|
|
|
|
postcode: 'SW1A 1AA',
|
|
|
|
|
latitude: 51.5074,
|
|
|
|
|
longitude: -0.1278,
|
|
|
|
|
rwm_expected_pct: 75.5,
|
|
|
|
|
prev_rwm_expected_pct: 70.0,
|
2026-03-05 13:00:34 +00:00
|
|
|
} as School;
|
2026-02-02 20:34:35 +00:00
|
|
|
|
|
|
|
|
describe('SchoolCard', () => {
|
|
|
|
|
it('renders school information correctly', () => {
|
|
|
|
|
render(<SchoolCard school={mockSchool} />);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Test Primary School')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Westminster')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Academy')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('75.5%')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('links to school detail page', () => {
|
|
|
|
|
render(<SchoolCard school={mockSchool} />);
|
|
|
|
|
|
|
|
|
|
const link = screen.getByRole('link', { name: /test primary school/i });
|
|
|
|
|
expect(link).toHaveAttribute('href', '/school/100001');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onAddToCompare when Add to Compare button is clicked', () => {
|
|
|
|
|
const mockAddToCompare = jest.fn();
|
|
|
|
|
render(<SchoolCard school={mockSchool} onAddToCompare={mockAddToCompare} />);
|
|
|
|
|
|
|
|
|
|
const addButton = screen.getByText('Add to Compare');
|
|
|
|
|
fireEvent.click(addButton);
|
|
|
|
|
|
|
|
|
|
expect(mockAddToCompare).toHaveBeenCalledWith(mockSchool);
|
|
|
|
|
expect(mockAddToCompare).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not render Add to Compare button when handler not provided', () => {
|
|
|
|
|
render(<SchoolCard school={mockSchool} />);
|
|
|
|
|
|
|
|
|
|
expect(screen.queryByText('Add to Compare')).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('displays trend indicator for positive change', () => {
|
|
|
|
|
render(<SchoolCard school={mockSchool} />);
|
|
|
|
|
|
|
|
|
|
// Should show upward trend (75.5 > 70.0)
|
2026-03-05 13:00:34 +00:00
|
|
|
expect(screen.getByTitle('Previous year: 70.0%')).toBeInTheDocument();
|
2026-02-02 20:34:35 +00:00
|
|
|
});
|
|
|
|
|
});
|