feat(admissions): add the cut-off history, map and postcode check
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m3s
PR Checks / Backend Smoke (pull_request) Successful in 7s
PR Checks / Build Backend (no push) (pull_request) Successful in 17s
PR Checks / Build Frontend (no push) (pull_request) Successful in 44s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 10s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 2m39s

Completes the last-distance-offered feature against the mockup: the
year-by-year record, the same numbers drawn over real streets, and the
reader's own address measured against them.

Serving the history
  The first cut deliberately served only the latest year, because a plain
  series would draw a trend line straight through gaps that are absences of
  publication, not of a cut-off. That reasoning is answered rather than
  abandoned: cutoffYearRows classifies every year in the span, and the chart
  breaks the line rather than interpolating across it.

  A missing year is not one fact but three. It may be unpublished; it may be
  a year the school was not oversubscribed; or there may be no record at all.
  Collapsing them into "no data" throws away the reassuring case and hides
  the important caveat, so each is stated in words in the table.

  The claim is held to what the data supports. fact_admissions.oversubscribed
  compares FIRST PREFERENCES against places, which does not establish that
  every applicant was offered one — so the copy says "places available on
  first preferences" and a test asserts the stronger claim never appears.

The trend summary is not a verdict
  It names both endpoints and their years and lets the reader conclude. It is
  withheld below four published points, and a swing under a tenth of the
  earlier figure is reported as "broadly the same" rather than dressed up as
  a direction.

The postcode check
  This is the only place on the site that answers a question about a family
  rather than a school, so most of the care went into what it refuses to say.
  postcodes.io returns a centroid covering roughly fifteen addresses, which
  against a 500 m cut-off is a fifth of the whole distance — so a margin
  inside 100 m returns "too close to call" rather than a place a family does
  not have. Unpublished years count as unknown, never as a pass. The limits
  are stated before the check is used, not revealed with the answer.

  The postcode is geocoded in the browser and never stored.

Both templates
  Banded and selective secondaries are exactly where this matters most, so
  the detail is shared. The primary page gives it a third tab; the secondary
  page is one flat panel by design and renders it inline.

Absence is explained rather than reported. A selective school's missing
figure is explained by how it admits; a consistently undersubscribed school
reads as good news.

Also makes the batch loader's test double honour ORDER BY. It was a no-op,
so "latest row per URN" was really "first row in the fixture" and the test
would have passed with the sort reversed or removed.

Verified: 214 frontend tests, 54 backend, 45/53 e2e green against staging
(the 8 cut-off journeys skip until the DAG runs). Rendered offline against
the real compiled CSS in both themes and at 390px; every new surface clears
WCAG AA, measured on composited pixels.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WDvkyqqHABm4bmth2kjAxE
This commit is contained in:
TudorandClaude Opus 5 committed 2026-08-16 13:42:06 +01:00
1 parent 5a71f54d94
commit a72323874f
24 files changed
+2067 -65

No files matched your search

+114 -4
View File
@@ -1226,14 +1226,21 @@ const CUTOFF_CANDIDATE_URNS = [
101099, 100553, 102574, 100769, // mixed
];
async function schoolWithCutoff(page: Page) {
async function schoolWithCutoff(page: Page, minPublishedYears = 1) {
for (const urn of CUTOFF_CANDIDATE_URNS) {
const res = await page.request.get(`/api/schools/${urn}`);
if (!res.ok()) continue;
const body = await res.json();
if (body?.admission_distance?.distance_m != null) {
return { urn, distance: body.admission_distance, phase: body.school_info?.phase };
}
if (body?.admission_distance?.distance_m == null) continue;
const published = (body.admission_distance_history ?? [])
.filter((h: { distance_m?: number | null }) => h.distance_m != null);
if (published.length < minPublishedYears) continue;
return {
urn,
distance: body.admission_distance,
history: published,
phase: body.school_info?.phase,
};
}
return null;
}
@@ -1307,3 +1314,106 @@ test('no school page shows an implausible cut-off distance', async ({ page }) =>
}
test.skip(checked === 0, 'no cut-off distances available to check yet');
});
// ── The Distance view, map and postcode check ────────────────────────────
test('a school with several published years gets the Distance view', async ({ page }) => {
const found = await schoolWithCutoff(page, 2);
test.skip(found === null, 'no school in the sample has 2+ published cut-off years yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#admissions')).toBeVisible({ timeout: 15_000 });
const isSecondary = /secondary/i.test(found!.phase ?? '');
if (!isSecondary) {
// Primary pages carry a segmented control; the detail sits behind it.
const distanceTab = page.getByRole('button', { name: 'Distance' });
await expect(distanceTab).toBeVisible();
await distanceTab.click();
await expect(distanceTab).toHaveAttribute('aria-pressed', 'true');
}
// Every published year must appear as a row, whichever template rendered it.
for (const h of found!.history as { year: number }[]) {
await expect(page.getByRole('rowheader', { name: String(h.year) })).toBeVisible();
}
});
test('the year table never leaves a gap unexplained', async ({ page }) => {
// A blank row would tell a parent nothing; each gap must name its reason.
const found = await schoolWithCutoff(page, 2);
test.skip(found === null, 'no school in the sample has 2+ published cut-off years yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#admissions')).toBeVisible({ timeout: 15_000 });
if (!/secondary/i.test(found!.phase ?? '')) {
await page.getByRole('button', { name: 'Distance' }).click();
}
const statuses = await page.locator('[class*="cutoffPill"]').allTextContents();
expect(statuses.length).toBeGreaterThan(0);
for (const s of statuses) {
expect(s.trim(), 'every row carries a status').not.toBe('');
}
// The stronger claim the data cannot support must never appear.
await expect(page.getByText(/every applicant was offered/i)).toHaveCount(0);
});
test('the postcode check answers with a distance and per-year verdicts', async ({ page }) => {
const found = await schoolWithCutoff(page, 2);
test.skip(found === null, 'no school in the sample has 2+ published cut-off years yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#admissions')).toBeVisible({ timeout: 15_000 });
if (!/secondary/i.test(found!.phase ?? '')) {
await page.getByRole('button', { name: 'Distance' }).click();
}
const input = page.getByLabel('Your postcode');
await expect(input).toBeVisible();
await input.fill('SW1A 1AA');
await page.getByRole('button', { name: 'Check' }).click();
// Either a verdict or a plain error — never a silent no-op.
const result = page.getByRole('status');
const error = page.getByRole('alert');
await expect(result.or(error)).toBeVisible({ timeout: 20_000 });
if (await result.isVisible()) {
await expect(result).toContainText(/mile|m\b/);
}
});
test('the postcode check states its limits before it is used', async ({ page }) => {
// The caveat is not revealed with the answer — it is there while the parent
// is deciding whether to trust the answer at all.
const found = await schoolWithCutoff(page, 2);
test.skip(found === null, 'no school in the sample has 2+ published cut-off years yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#admissions')).toBeVisible({ timeout: 15_000 });
if (!/secondary/i.test(found!.phase ?? '')) {
await page.getByRole('button', { name: 'Distance' }).click();
}
await expect(page.getByText(/An indication only/)).toBeVisible();
await expect(page.getByText(/not a catchment boundary/)).toBeVisible();
});
test('the distance section never scrolls the page sideways', async ({ page }) => {
const found = await schoolWithCutoff(page, 2);
test.skip(found === null, 'no school in the sample has 2+ published cut-off years yet');
await page.setViewportSize({ width: 390, height: 844 });
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#admissions')).toBeVisible({ timeout: 15_000 });
if (!/secondary/i.test(found!.phase ?? '')) {
await page.getByRole('button', { name: 'Distance' }).click();
}
// The year table is deliberately wider than a phone; its own wrapper has to
// absorb that, or the whole page slides under the reader's thumb.
const overflow = await page.evaluate(() =>
document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(overflow, 'page must not scroll horizontally').toBeLessThanOrEqual(1);
});