feat(utils): add buildOfstedListBadge helper and fetchNationalAverages

- Add ofsted_framework field to School type
- Add OfstedListBadge interface and buildOfstedListBadge pure function to utils.ts
- Add fetchNationalAverages API function that calls GET /api/national-averages
- Add test suite for buildOfstedListBadge (all 6 new tests pass)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tudor Sitaru
2026-04-13 13:52:05 +01:00
parent 6d02d366ce
commit 8a6758b591
4 changed files with 107 additions and 0 deletions
+46
View File
@@ -570,3 +570,49 @@ export function buildSchoolSummary(
return parts.join(', ') + '.';
}
// ─── List-level Ofsted badge ──────────────────────────────────────────────────
export interface OfstedListBadge {
/** Display text for the badge (e.g. "Outstanding · 2023", "Report Card · 2025") */
label: string;
/** CSS module class key — one of: ofsted1 | ofsted2 | ofsted3 | ofsted4 | ofstedRc | ofstedPending */
cssClass: string;
}
/**
* Build the Ofsted badge for a school card in the list/map view.
* Three states:
* - OEIF school (ofsted_grade set): grade word + year, colour-keyed
* - ReportCard school (ofsted_framework === 'ReportCard'): "Report Card · YYYY" in purple
* - No inspection: "Not yet inspected" in grey
*/
export function buildOfstedListBadge(school: {
ofsted_grade?: number | null;
ofsted_date?: string | null;
ofsted_framework?: string | null;
}): OfstedListBadge {
const year = school.ofsted_date
? new Date(school.ofsted_date).getFullYear()
: null;
const yearStr = year ? ` · ${year}` : '';
if (school.ofsted_grade) {
const labels: Record<number, string> = {
1: 'Outstanding',
2: 'Good',
3: 'Req. Improvement',
4: 'Inadequate',
};
return {
label: `${labels[school.ofsted_grade]}${yearStr}`,
cssClass: `ofsted${school.ofsted_grade}`,
};
}
if (school.ofsted_framework === 'ReportCard') {
return { label: `Report Card${yearStr}`, cssClass: 'ofstedRc' };
}
return { label: 'Not yet inspected', cssClass: 'ofstedPending' };
}