feat(admissions): publish the latest cut-off only, holding history back
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m4s
PR Checks / Backend Smoke (pull_request) Successful in 7s
PR Checks / Build Backend (no push) (pull_request) Successful in 16s
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) Failing after 3m17s

Earlier years are to become a paid feature, so they stop being published.

The load-bearing part is that this is a change to the API, not only to the
page. /api/schools/{urn} is public and unauthenticated: leaving
admission_distance_history in the payload while declining to render it would
have handed the whole record to anyone who opened the network tab. It is
withheld at the source, and the page follows.

Nothing changes upstream. The tap, the plausibility band and
fact_admission_distance are untouched and still load every published year, so
restoring history for entitled callers is a change to one function in
data_loader rather than a re-collection.

What the reader now gets is the latest figure on the Admissions tile, and a
Distance section that answers the question the number alone cannot: whether
their own address falls inside it. Retitled to "How far away are you?", which
is what it now does — the previous title described a record that is no longer
there.

Removed with the history: the trend chart, the year-by-year table, the
per-year verdict strip, the trend summary and the coverage note, along with
their CSS. The section goes from 743px to 417px.

One consequence worth naming. A run of years used to soften a single close
call — a home just outside one year's cut-off was usually inside another. With
one year published, the "too close to call" band is the entire safety margin
between a parent and a place they do not have, so the verdict now names its
year, and the three outcomes are tinted apart rather than distinguished by
wording alone.

The existing stylesheet test earned its keep here: the three verdict classes
were referenced before they were written, and it caught them. Unstyled, a
"beyond the cut-off" result would have been indistinguishable from an "inside"
one — the exact failure the longhand class map was written to prevent.

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-20 18:44:57 +01:00
1 parent 50b599a09b
commit c9a1892bfb
20 files changed
+382 -1215

No files matched your search

+51 -60
View File
@@ -1226,21 +1226,13 @@ const CUTOFF_CANDIDATE_URNS = [
101099, 100553, 102574, 100769, // mixed
];
async function schoolWithCutoff(page: Page, minPublishedYears = 1) {
async function schoolWithCutoff(page: Page) {
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) 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 { urn, distance: body.admission_distance, phase: body.school_info?.phase };
}
return null;
}
@@ -1317,91 +1309,90 @@ test('no school page shows an implausible cut-off distance', async ({ page }) =>
// ── 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');
test('the public API serves the latest cut-off only', async ({ page }) => {
/*
* Earlier years are held back as a paid feature. This endpoint is public and
* unauthenticated, so withholding them in the UI alone would be decoration:
* anyone could read the history out of the network tab. The mart still holds
* every year — this asserts what leaves the process, not what was collected.
*/
let checked = 0;
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) continue;
checked += 1;
expect(body, `URN ${urn} still exposes a cut-off history`)
.not.toHaveProperty('admission_distance_history');
}
test.skip(checked === 0, 'no cut-off distances available to check yet');
});
test('a school page shows no year-by-year cut-off record', async ({ page }) => {
const found = await schoolWithCutoff(page);
test.skip(found === null, 'no school in the sample has a published cut-off yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#admissions')).toBeVisible({ timeout: 15_000 });
// Its own section on both templates, not a third tab inside Admissions —
// stacking a view that tall in the admissions viewport sized the whole card
// to it and left the default view mostly blank.
await expect(page.locator('#distance')).toBeVisible();
// The render side of the same rule, so a future component cannot put the
// history back without the API.
await expect(page.getByText(/Last distance offered, by year/)).toHaveCount(0);
await expect(page.getByText(/too few to read as a trend/)).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Distance' })).toHaveCount(0);
// Every published year must appear as a row.
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');
test('the postcode check answers for the published year, and names it', async ({ page }) => {
const found = await schoolWithCutoff(page);
test.skip(found === null, 'no school in the sample has a published cut-off yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#distance')).toBeVisible({ timeout: 15_000 });
const section = page.locator('#distance');
// Needs coordinates as well as a figure; not every school has both.
test.skip(await section.count() === 0, 'this school has no distance section');
await expect(section).toBeVisible({ timeout: 15_000 });
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('#distance')).toBeVisible({ timeout: 15_000 });
const input = page.getByLabel('Your postcode');
await expect(input).toBeVisible();
await input.fill('SW1A 1AA');
await page.getByLabel('Your postcode').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/);
// A verdict without its year is a number a parent cannot place.
await expect(result).toContainText(new RegExp(`September ${found!.distance.year}`));
await expect(result).toContainText(/inside|beyond|too close/);
}
});
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');
const found = await schoolWithCutoff(page);
test.skip(found === null, 'no school in the sample has a published cut-off yet');
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#distance')).toBeVisible({ timeout: 15_000 });
const section = page.locator('#distance');
test.skip(await section.count() === 0, 'this school has no distance section');
await expect(section).toBeVisible({ timeout: 15_000 });
const caveat = page.getByText(/Distance is the last criterion applied/);
await expect(caveat).toBeVisible();
await expect(caveat).toContainText(/not a catchment boundary/);
await expect(caveat).toContainText(/walking route/);
// One caveat for the section, not the three paragraphs it replaced.
await expect(caveat).toHaveCount(1);
});
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');
const found = await schoolWithCutoff(page);
test.skip(found === null, 'no school in the sample has a published cut-off yet');
await page.setViewportSize({ width: 390, height: 844 });
await page.goto(`/school/${found!.urn}`);
await expect(page.locator('#distance')).toBeVisible({ timeout: 15_000 });
const section = page.locator('#distance');
test.skip(await section.count() === 0, 'this school has no distance section');
await expect(section).toBeVisible({ timeout: 15_000 });
// 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);
@@ -1422,7 +1413,7 @@ test('no single section dominates the height of a school page', async ({ page })
* a reader actually sees is one section wildly out of proportion with its
* neighbours, so that is what this asserts.
*/
const found = await schoolWithCutoff(page, 2);
const found = await schoolWithCutoff(page);
test.skip(found === null, 'no school in the sample has 2+ published cut-off years yet');
await page.goto(`/school/${found!.urn}`);