test: pin school detail behaviour before refactor
14 characterization tests covering Ofsted (both OEIF and Report Card layouts), KS2 results with the England delta, KS4 Attainment 8 / Progress 8 / EBacc, all-through dual rendering, special-school comparison suppression (PR #70), the admissions year/trend toggle, and conditional section rendering. All rendering goes through renderSchoolDetail(), the single seam the server/client split is allowed to change. The assertions must survive the refactor unmodified. Excludes __tests__/support from testMatch: it holds fixtures and helpers, not suites, and the glob was failing them as empty test files. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* The single seam between the characterization tests and the component tree.
|
||||
*
|
||||
* Task 7 of the server/client split rewrites the bodies of these functions to
|
||||
* render the new shell + server-sections composition. Nothing else in the test
|
||||
* suite may change — the characterization assertions passing unmodified across
|
||||
* that rewrite is the proof that behaviour was preserved.
|
||||
*
|
||||
* National averages are currently fetched client-side via useEffect, so this
|
||||
* helper stubs global.fetch. Once they arrive as a server-supplied prop the
|
||||
* stub goes away; the tests use findBy* queries so they pass either way.
|
||||
*/
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { SchoolDetailView } from '@/components/SchoolDetailView';
|
||||
import { SecondarySchoolDetailView } from '@/components/SecondarySchoolDetailView';
|
||||
import { ComparisonProvider } from '@/context/ComparisonProvider';
|
||||
import { nationalAveragesFixture } from './schoolFixtures';
|
||||
|
||||
// Both views call useComparison(), which throws outside the provider. In the
|
||||
// app this wrapper comes from app/layout.tsx.
|
||||
function withProviders(ui: ReactNode) {
|
||||
return <ComparisonProvider>{ui}</ComparisonProvider>;
|
||||
}
|
||||
|
||||
function stubNationalAveragesFetch() {
|
||||
global.fetch = jest.fn((url: any) =>
|
||||
String(url).includes('national-averages')
|
||||
? Promise.resolve({ ok: true, json: () => Promise.resolve(nationalAveragesFixture) })
|
||||
: Promise.resolve({ ok: false, json: () => Promise.resolve({}) }),
|
||||
) as unknown as typeof fetch;
|
||||
}
|
||||
|
||||
export function renderSchoolDetail(fixture: any) {
|
||||
stubNationalAveragesFetch();
|
||||
return render(withProviders(<SchoolDetailView {...fixture} />));
|
||||
}
|
||||
|
||||
export function renderSecondarySchoolDetail(fixture: any) {
|
||||
stubNationalAveragesFetch();
|
||||
return render(withProviders(<SecondarySchoolDetailView {...fixture} />));
|
||||
}
|
||||
Reference in New Issue
Block a user