Files
school_compare/nextjs-app/__tests__/support/renderSchoolDetail.tsx
T
TudorandClaude Opus 5 2437ffce42 refactor(app): move site routes into a (frontend) route group
Payload's admin panel ships its own root layout rendering html/body.
Next allows multiple root layouts only when no app/layout.tsx exists, so
the site's routes move into their own group. Route groups are invisible
to routing: every public URL is unchanged, verified against the build's
route table.

The metadata file conventions deliberately stay at the app/ root. Moving
them into the group renamed /icon.png to /icon-4usi79.png (likewise
apple-icon and opengraph-image) and dropped /robots.txt altogether,
which would have broken the /icon.png cache-control rule, the
outputFileTracingIncludes entry for the share card, and robots.txt.

darkThemeSafety reads app/globals.css off disk rather than importing it,
so it needed its own path fix — a grep for import specifiers misses it,
and it fails as an unrunnable suite rather than a failed assertion.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017YmbBhr8s7GusjDE12hrZM
2026-09-02 16:11:48 +01:00

85 lines
2.8 KiB
TypeScript

/**
* The single seam between the characterization tests and the component tree.
*
* This file is the ONLY thing the server/client split was allowed to change.
* It now renders the shell + server-sections composition that
* app/school/[slug]/page.tsx builds, instead of the old monolithic views.
* Every assertion in schoolDetail.characterization.test.tsx is unchanged —
* that is the proof the refactor preserved behaviour.
*/
import { render } from '@testing-library/react';
import type { ReactNode } from 'react';
import { ComparisonProvider } from '@/context/ComparisonProvider';
import { SchoolDetailShell } from '@/components/school/SchoolDetailShell';
import { PrimarySchoolSections } from '@/components/school/PrimarySchoolSections';
import { SecondarySchoolSections } from '@/components/school/SecondarySchoolSections';
import {
computeSchoolFlags, buildNavItems,
computeSecondaryFlags, buildSecondaryNavItems,
} from '@/lib/schoolSections';
import { nationalAveragesFixture } from './schoolFixtures';
// The shell calls useComparison(), which throws outside the provider. In the
// app this wrapper comes from app/(frontend)/layout.tsx.
function withProviders(ui: ReactNode) {
return <ComparisonProvider>{ui}</ComparisonProvider>;
}
export function renderSchoolDetail(fixture: any) {
const flags = computeSchoolFlags(fixture);
const navItems = buildNavItems(flags, {
ofsted: fixture.ofsted,
admissions: fixture.admissions,
admissionDistance: fixture.admissionDistance ?? null,
yearlyDataLength: fixture.yearlyData.length,
});
return render(
withProviders(
<SchoolDetailShell
schoolInfo={fixture.schoolInfo}
yearlyData={fixture.yearlyData}
census={fixture.census}
navItems={navItems}
>
<PrimarySchoolSections
{...fixture}
admissionDistanceHistory={fixture.admissionDistanceHistory ?? []}
nationalAvg={nationalAveragesFixture}
flags={flags}
/>
</SchoolDetailShell>,
),
);
}
export function renderSecondarySchoolDetail(fixture: any) {
const flags = computeSecondaryFlags(fixture);
const navItems = buildSecondaryNavItems(flags, {
ofsted: fixture.ofsted,
admissions: fixture.admissions,
admissionDistance: fixture.admissionDistance ?? null,
yearlyDataLength: fixture.yearlyData.length,
});
return render(
withProviders(
<SchoolDetailShell
schoolInfo={fixture.schoolInfo}
yearlyData={fixture.yearlyData}
census={fixture.census}
navItems={navItems}
>
<SecondarySchoolSections
{...fixture}
admissionsHistory={fixture.admissionsHistory ?? []}
admissionDistanceHistory={fixture.admissionDistanceHistory ?? []}
nationalAvg={nationalAveragesFixture}
flags={flags}
/>
</SchoolDetailShell>,
),
);
}