fix(compare): date report cards with their own inspection date, never the legacy one

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0146VHeLAWjDVE2B5uU67jCB
This commit is contained in:
Tudor
2026-07-16 14:48:17 +01:00
co-authored by Claude Fable 5
parent e00a1b38a8
commit 9773483221
6 changed files with 79 additions and 2 deletions
@@ -96,6 +96,45 @@ describe('CompareOfsted', () => {
expect(links[0]).toHaveAttribute('href', 'https://reports.ofsted.gov.uk/provider/21/1');
});
it('dates a report card with the report-card inspection date, never the legacy date', () => {
const cardSchool = school(4, 'Dated Card School');
const cardData: Record<string, ComparisonData> = {
'4': {
school_info: cardSchool,
yearly_data: [],
ofsted: ofsted({
inspection_date: '2021-10-07',
rc_inspection_date: '2026-02-03',
rc_safeguarding_met: true,
report_card: { rc_achievement: { code: 1, label: 'Exceptional' } },
}),
},
};
render(<CompareOfsted schools={[cardSchool]} data={cardData} />);
expect(screen.getByText(/3 Feb 2026/)).toBeInTheDocument();
expect(screen.queryByText(/7 Oct 2021/)).toBeNull();
expect(screen.queryByText('4+ years ago')).toBeNull();
});
it('shows an em dash when a report card has no rc_inspection_date yet', () => {
const cardSchool = school(5, 'Undated Card School');
const cardData: Record<string, ComparisonData> = {
'5': {
school_info: cardSchool,
yearly_data: [],
ofsted: ofsted({
inspection_date: '2021-10-07',
rc_inspection_date: null,
rc_safeguarding_met: true,
report_card: { rc_achievement: { code: 1, label: 'Exceptional' } },
}),
},
};
render(<CompareOfsted schools={[cardSchool]} data={cardData} />);
expect(screen.getByText('—')).toBeInTheDocument();
expect(screen.queryByText(/7 Oct 2021/)).toBeNull();
});
it('renders a per-measure mobile tag with the short school name', () => {
render(<CompareOfsted schools={schools} data={data} />);
// Each measure repeats the schools, so the short name ("Graded" from
@@ -180,10 +180,18 @@ export function CompareOfsted({
<Measure label="Inspected">
{schools.map((school, i) => {
const ofsted = data[String(school.urn)]?.ofsted;
const age = yearsSince(ofsted?.inspection_date ?? null);
// A report card is dated by its OWN inspection date. The legacy
// inspection_date belongs to an older inspection and must never
// be shown against a report card (report cards exist only from
// Nov 2025).
const dateIso =
displays[i].kind === 'report_card'
? ofsted?.rc_inspection_date ?? null
: ofsted?.inspection_date ?? null;
const age = yearsSince(dateIso);
return (
<Cell key={school.urn} school={school} index={i}>
{formatInspectionDate(ofsted?.inspection_date ?? null)}{' '}
{formatInspectionDate(dateIso)}{' '}
{age != null && age > 4 && <Chip tone="neutral">4+ years ago</Chip>}
</Cell>
);
+2
View File
@@ -79,6 +79,8 @@ export interface School {
export interface OfstedInspection {
framework: 'OEIF' | 'ReportCard' | null;
inspection_date: string | null;
/** Start date of the report-card inspection itself (Nov 2025+); null otherwise. */
rc_inspection_date?: string | null;
inspection_type: string | null;
// OEIF fields (old framework, pre-Nov 2025)
overall_effectiveness: 1 | 2 | 3 | 4 | null;