PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m5s
PR Checks / Backend Smoke (pull_request) Successful in 8s
PR Checks / Build Backend (no push) (pull_request) Successful in 13s
PR Checks / Build Frontend (no push) (pull_request) Successful in 45s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 11s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 1m59s
The admissions card measured 1503px on a live school page — half the height of every section put together, and nearly three times the next largest — with its default view rendering as four tiles adrift in about 1080px of blank card. The cause was a layout trick meeting content it was never sized for. The admissions views are stacked in one grid cell so switching them never shifts layout, and the hidden ones keep their box: only visibility is dropped. That works while the views are comparable. The distance view added in #102 carries a chart, a table and a map, came to 1402px against the tile grid's 316px, and pinned every other view to its height — including the one that renders by default, which nobody had clicked. Rather than only unpinning it, the detail moves out. Every other topic on the page is a section with a nav entry, and "how close did we need to live, and would we have got in?" is a topic, not a variant reading of the intake figures. The headline number stays on the Admissions tile where the intake story is; the record behind it now lives in a Distance section directly below. admissions 1503px -> 554px distance new -> 743px (median section on the page is ~528px) Three further changes, each of which also makes the content better rather than only shorter: * The map renders on request. Before a postcode is entered it is a circle drawn round a school, and it costs a Leaflet bundle and 240px to say so; a successful check opens it automatically, which is the point at which it starts answering something. Map height 320px -> 240px. * The chart appears only at the four published years that let the summary state a direction. Below that we already refuse to call the series a trend, and a line through three points asserts one regardless of what the sentence beneath it admits. The table carries those years anyway, with the reasons a line cannot show. * Three caveat paragraphs become one. They said walking-route twice and made the same point about priorities in two voices. It now sits in CutoffDistanceDetail rather than inside the check, so it still renders for a school with coordinates missing, where there is a table but no map and no check. The new e2e guard asserts no section exceeds 2.5x the median section height. Measuring the card's internals cannot catch this: the tile grid is flex: 1, so it absorbs the stretch and every box still looks full. The first version of this test targeted an arbitrary primary, passed against the live bug, and proved nothing; pointed at a school that actually holds cut-off history it fails on staging with "#admissions is 1459px against a 526px median". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDvkyqqHABm4bmth2kjAxE
162 lines
6.3 KiB
TypeScript
162 lines
6.3 KiB
TypeScript
/**
|
|
* The postcode check.
|
|
*
|
|
* This is the one place on the site that answers a question about a specific
|
|
* family rather than about a school, so the tests here are mostly about what it
|
|
* refuses to say: no verdict without a published figure, and no verdict at all
|
|
* when the margin is inside the error of a postcode centroid.
|
|
*/
|
|
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
import { CutoffMapPanel } from '@/components/school/CutoffMapPanel';
|
|
import { cutoffYearRows, CUTOFF_UNCERTAINTY_M } from '@/components/school/lastDistanceOffered';
|
|
import type { School, SchoolAdmissionDistance } from '@/lib/types';
|
|
|
|
// Leaflet needs a real layout box and network tiles; neither exists in jsdom.
|
|
// The panel's logic is independent of it, so the map is stubbed out.
|
|
jest.mock('@/components/LeafletCutoffMapInner', () => ({
|
|
__esModule: true,
|
|
default: () => <div data-testid="cutoff-map" />,
|
|
}));
|
|
|
|
const mockGeocode = jest.fn();
|
|
jest.mock('@/lib/api', () => ({
|
|
...jest.requireActual('@/lib/api'),
|
|
geocodePostcode: (pc: string) => mockGeocode(pc),
|
|
}));
|
|
|
|
const SCHOOL = { urn: 100010, school_name: 'Test Primary', latitude: 51.5, longitude: -0.12 } as School;
|
|
|
|
const d = (year: number, distance_m: number): SchoolAdmissionDistance => ({
|
|
year, distance_m, route_count: 1, la_name: 'Camden', distance_unit_raw: 'miles',
|
|
});
|
|
|
|
/** A point due north of the school, `metres` away. 1° latitude ≈ 111,320 m. */
|
|
function northOf(metres: number) {
|
|
return { latitude: SCHOOL.latitude! + metres / 111_320, longitude: SCHOOL.longitude! };
|
|
}
|
|
|
|
function renderPanel(history: SchoolAdmissionDistance[], admissions: { year: number; oversubscribed?: boolean }[] = []) {
|
|
return render(
|
|
<CutoffMapPanel schoolInfo={SCHOOL} rows={cutoffYearRows(history, admissions)} />,
|
|
);
|
|
}
|
|
|
|
async function check(postcode: string) {
|
|
fireEvent.change(screen.getByLabelText('Your postcode'), { target: { value: postcode } });
|
|
fireEvent.click(screen.getByRole('button', { name: 'Check' }));
|
|
}
|
|
|
|
beforeEach(() => mockGeocode.mockReset());
|
|
|
|
describe('CutoffMapPanel', () => {
|
|
it('renders nothing without a published figure to draw', () => {
|
|
const { container } = renderPanel([]);
|
|
expect(container).toBeEmptyDOMElement();
|
|
});
|
|
|
|
it('renders nothing when the school has no coordinates', () => {
|
|
const { container } = render(
|
|
<CutoffMapPanel
|
|
schoolInfo={{ ...SCHOOL, latitude: null, longitude: null } as School}
|
|
rows={cutoffYearRows([d(2024, 800)])}
|
|
/>,
|
|
);
|
|
expect(container).toBeEmptyDOMElement();
|
|
});
|
|
|
|
it('rejects a malformed postcode without calling the geocoder', async () => {
|
|
renderPanel([d(2024, 800)]);
|
|
await check('not a postcode');
|
|
|
|
expect(await screen.findByRole('alert')).toHaveTextContent(/does not look like a UK postcode/);
|
|
expect(mockGeocode).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('reports a home clearly inside every published year', async () => {
|
|
mockGeocode.mockResolvedValue(northOf(200));
|
|
renderPanel([d(2022, 1000), d(2024, 800)]);
|
|
await check('SE23 3NA');
|
|
|
|
expect(await screen.findByRole('status')).toHaveTextContent(/inside the cut-off in all 2 years/);
|
|
});
|
|
|
|
it('reports a home clearly outside every published year', async () => {
|
|
mockGeocode.mockResolvedValue(northOf(5000));
|
|
renderPanel([d(2022, 1000), d(2024, 800)]);
|
|
await check('SE23 3NA');
|
|
|
|
expect(await screen.findByRole('status')).toHaveTextContent(/outside the cut-off in every year/);
|
|
});
|
|
|
|
it('declines to call a result that sits inside the measurement error', async () => {
|
|
// The home is nominally inside 2024's 800 m cut-off, but only by half the
|
|
// uncertainty band — which a postcode centroid cannot resolve.
|
|
mockGeocode.mockResolvedValue(northOf(800 - CUTOFF_UNCERTAINTY_M / 2));
|
|
renderPanel([d(2024, 800)]);
|
|
await check('SE23 3NA');
|
|
|
|
const result = await screen.findByRole('status');
|
|
expect(result).toHaveTextContent(/too close to call/);
|
|
expect(result).not.toHaveTextContent(/inside the cut-off in all/);
|
|
});
|
|
|
|
it('counts an unpublished year as unknown rather than as a pass', async () => {
|
|
mockGeocode.mockResolvedValue(northOf(200));
|
|
renderPanel([d(2022, 1000), d(2024, 800)], [{ year: 2023, oversubscribed: false }]);
|
|
await check('SE23 3NA');
|
|
|
|
const result = await screen.findByRole('status');
|
|
expect(result).toHaveTextContent(/inside the cut-off in all 2 years/);
|
|
expect(result).toHaveTextContent(/no published figure/);
|
|
});
|
|
|
|
it('surfaces a postcode the geocoder cannot find', async () => {
|
|
mockGeocode.mockResolvedValue(null);
|
|
renderPanel([d(2024, 800)]);
|
|
await check('ZZ99 9ZZ');
|
|
|
|
expect(await screen.findByRole('alert')).toHaveTextContent(/could not find that postcode/);
|
|
});
|
|
|
|
it('recovers from a geocoder failure instead of leaving a stale verdict', async () => {
|
|
mockGeocode.mockResolvedValue(northOf(200));
|
|
renderPanel([d(2024, 800)]);
|
|
await check('SE23 3NA');
|
|
await screen.findByRole('status');
|
|
|
|
mockGeocode.mockRejectedValue(new Error('network'));
|
|
await check('SE23 3NB');
|
|
|
|
await waitFor(() => expect(screen.queryByRole('status')).not.toBeInTheDocument());
|
|
expect(screen.getByRole('alert')).toHaveTextContent(/Something went wrong/);
|
|
});
|
|
|
|
it('does not carry the caveat itself', () => {
|
|
// It moved to CutoffDistanceDetail so it renders once per section, and so
|
|
// it still appears for a school with no coordinates (no map, no check).
|
|
// Asserting its absence here is what stops the old three-paragraph stutter
|
|
// creeping back.
|
|
renderPanel([d(2024, 800)]);
|
|
expect(screen.queryByText(/Distance is the last criterion/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('keeps the map behind a request until there is a reason to show it', async () => {
|
|
renderPanel([d(2024, 800)]);
|
|
expect(screen.queryByTestId('cutoff-map')).not.toBeInTheDocument();
|
|
|
|
// A successful check is that reason: the rings only answer a question once
|
|
// there is a home to sit beside them.
|
|
mockGeocode.mockResolvedValue(northOf(200));
|
|
await check('SE23 3NA');
|
|
await screen.findByRole('status');
|
|
expect(screen.getByTestId('cutoff-map')).toBeInTheDocument();
|
|
});
|
|
|
|
it('can also show the map without a postcode, on request', () => {
|
|
renderPanel([d(2024, 800)]);
|
|
fireEvent.click(screen.getByRole('button', { name: /Show these distances on a map/ }));
|
|
expect(screen.getByTestId('cutoff-map')).toBeInTheDocument();
|
|
});
|
|
});
|