fix(ofsted): badge and compare read the grade still in force
Search badges date a grade by the inspection that awarded or confirmed it (ofsted_grade_date) and say 'Inspected · year' when the latest inspection gave no grade. ofstedDisplay's kinds become graded / confirmed / no_overall_grade, read from current_grade rather than a carried-forward overall_effectiveness. lib/ofstedStatus.ts holds the two sentences the school and compare pages share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a9e3a6a700
commit
a42c586cc8
7 files changed
+179
-52
No files matched your search
@@ -114,16 +114,13 @@ describe('ofstedDisplay', () => {
|
||||
expect(d.kind).toBe('report_card');
|
||||
});
|
||||
|
||||
it('distinguishes graded from carried-forward grades', () => {
|
||||
const graded = ofstedDisplay(
|
||||
ofsted({ overall_effectiveness: 1, grade_source: 'graded' }),
|
||||
);
|
||||
expect(graded).toMatchObject({ kind: 'graded', gradeLabel: 'Outstanding', carriedForward: false });
|
||||
|
||||
const carried = ofstedDisplay(
|
||||
ofsted({ overall_effectiveness: 2, grade_source: 'ungraded_carried_forward' }),
|
||||
);
|
||||
expect(carried).toMatchObject({ kind: 'carried_forward', gradeLabel: 'Good', carriedForward: true });
|
||||
it('distinguishes a graded grade from a confirmed one', () => {
|
||||
expect(ofstedDisplay(ofsted({ current_grade: { grade: 1, date: '2019-10-09', basis: 'graded' },
|
||||
latest_visit: { date: '2025-02-05', kind: 'ungraded', outcome: 'Some aspects not as strong' } })))
|
||||
.toMatchObject({ kind: 'graded', gradeLabel: 'Outstanding', gradeDate: '2019-10-09' });
|
||||
expect(ofstedDisplay(ofsted({ current_grade: { grade: 2, date: '2024-07-18', basis: 'confirmed' },
|
||||
latest_visit: { date: '2024-07-18', kind: 'ungraded', outcome: 'School remains Good' } })))
|
||||
.toMatchObject({ kind: 'confirmed', gradeLabel: 'Good' });
|
||||
});
|
||||
|
||||
it('handles missing data', () => {
|
||||
@@ -131,11 +128,11 @@ describe('ofstedDisplay', () => {
|
||||
expect(ofstedDisplay(ofsted({})).kind).toBe('none');
|
||||
});
|
||||
|
||||
it('identifies transitional inspections without overall grades', () => {
|
||||
const transitional = ofstedDisplay(
|
||||
ofsted({ overall_effectiveness: null, inspection_date: '2024-11-05' }),
|
||||
);
|
||||
expect(transitional.kind).toBe('transitional');
|
||||
it('has no overall grade when the latest inspection gave none', () => {
|
||||
// Rabbsfarm: the graded inspection's own overall is null, so no grade is
|
||||
// in force even though an older ungraded visit said "remains Good".
|
||||
expect(ofstedDisplay(ofsted({ current_grade: null, overall_effectiveness: null,
|
||||
latest_visit: { date: '2025-06-17', kind: 'graded', outcome: null } })).kind).toBe('no_overall_grade');
|
||||
});
|
||||
|
||||
it('uses the four legacy grade words', () => {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { gradeSourceLine, latestVisitLine, showLatestVisitLine } from '@/lib/ofstedStatus';
|
||||
import type { OfstedInspection } from '@/lib/types';
|
||||
|
||||
const base = { report_card: {} } as unknown as OfstedInspection;
|
||||
|
||||
describe('gradeSourceLine', () => {
|
||||
it('names the graded inspection and its date', () => {
|
||||
expect(gradeSourceLine({ grade: 2, date: '2016-07-06', basis: 'graded' }))
|
||||
.toBe('Graded inspection, 6 July 2016');
|
||||
});
|
||||
it('names the ungraded visit that confirmed it', () => {
|
||||
expect(gradeSourceLine({ grade: 2, date: '2023-03-14', basis: 'confirmed' }))
|
||||
.toBe('Confirmed at an ungraded inspection, 14 March 2023');
|
||||
});
|
||||
});
|
||||
|
||||
describe('latestVisitLine', () => {
|
||||
it('prints the ungraded outcome', () => {
|
||||
expect(latestVisitLine({ date: '2024-11-13', kind: 'ungraded', outcome: 'Standards maintained' }))
|
||||
.toBe('Ungraded inspection, 13 November 2024: Standards maintained');
|
||||
});
|
||||
it('prints a graded visit without an outcome', () => {
|
||||
expect(latestVisitLine({ date: '2025-06-17', kind: 'graded', outcome: null }))
|
||||
.toBe('Graded inspection, 17 June 2025');
|
||||
});
|
||||
});
|
||||
|
||||
describe('showLatestVisitLine', () => {
|
||||
it('shows a later visit than the one the grade came from', () => {
|
||||
expect(showLatestVisitLine({ ...base,
|
||||
current_grade: { grade: 2, date: '2020-03-03', basis: 'graded' },
|
||||
latest_visit: { date: '2025-05-21', kind: 'ungraded', outcome: 'Standards maintained' } })).toBe(true);
|
||||
});
|
||||
it('hides it when the visit is the grade’s own source', () => {
|
||||
expect(showLatestVisitLine({ ...base,
|
||||
current_grade: { grade: 2, date: '2024-07-18', basis: 'confirmed' },
|
||||
latest_visit: { date: '2024-07-18', kind: 'ungraded', outcome: 'School remains Good' } })).toBe(false);
|
||||
});
|
||||
it('shows an ungraded outcome when there is no grade', () => {
|
||||
expect(showLatestVisitLine({ ...base, current_grade: null,
|
||||
latest_visit: { date: '2024-11-13', kind: 'ungraded', outcome: 'Standards maintained' } })).toBe(true);
|
||||
});
|
||||
it('hides it for a graded visit with no grade (the title already dates it)', () => {
|
||||
expect(showLatestVisitLine({ ...base, current_grade: null,
|
||||
latest_visit: { date: '2025-06-17', kind: 'graded', outcome: null } })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -147,23 +147,37 @@ describe('ofstedLegacyAreas', () => {
|
||||
|
||||
describe('buildOfstedListBadge', () => {
|
||||
it('returns grade word + year for OEIF Outstanding', () => {
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: 1, ofsted_date: '2023-11-15', ofsted_framework: 'OEIF' });
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: 1, ofsted_grade_date: '2023-11-15', ofsted_date: '2023-11-15', ofsted_framework: 'OEIF' });
|
||||
expect(badge.label).toBe('Outstanding · 2023');
|
||||
expect(badge.cssClass).toBe('ofsted1');
|
||||
});
|
||||
|
||||
it('returns grade word for each OEIF grade', () => {
|
||||
expect(buildOfstedListBadge({ ofsted_grade: 2, ofsted_date: '2022-05-01' }).label).toBe('Good · 2022');
|
||||
expect(buildOfstedListBadge({ ofsted_grade: 3, ofsted_date: '2021-01-01' }).label).toBe('Req. Improvement · 2021');
|
||||
expect(buildOfstedListBadge({ ofsted_grade: 4, ofsted_date: '2020-03-01' }).label).toBe('Inadequate · 2020');
|
||||
expect(buildOfstedListBadge({ ofsted_grade: 2, ofsted_grade_date: '2022-05-01' }).label).toBe('Good · 2022');
|
||||
expect(buildOfstedListBadge({ ofsted_grade: 3, ofsted_grade_date: '2021-01-01' }).label).toBe('Req. Improvement · 2021');
|
||||
expect(buildOfstedListBadge({ ofsted_grade: 4, ofsted_grade_date: '2020-03-01' }).label).toBe('Inadequate · 2020');
|
||||
});
|
||||
|
||||
it('returns grade word without year when date is missing', () => {
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: 2, ofsted_date: null });
|
||||
it('prints a grade without a year when its date is missing', () => {
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: 2, ofsted_grade_date: null, ofsted_date: '2025-01-01' });
|
||||
expect(badge.label).toBe('Good');
|
||||
expect(badge.cssClass).toBe('ofsted2');
|
||||
});
|
||||
|
||||
it('dates a grade by the inspection that awarded it, not the latest visit', () => {
|
||||
// Washwood Heath: Good from a March 2020 graded inspection; latest visit
|
||||
// an ungraded one in May 2025 (audit M1).
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: 2, ofsted_grade_date: '2020-03-03', ofsted_date: '2025-05-21' });
|
||||
expect(badge.label).toBe('Good · 2020');
|
||||
});
|
||||
|
||||
it('shows Inspected for a latest inspection that gave no grade (Rabbsfarm)', () => {
|
||||
// Audit C1: this used to read "Good · 2025", from a 2020 ungraded visit.
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_grade_date: null, ofsted_date: '2025-06-17' });
|
||||
expect(badge.label).toBe('Inspected · 2025');
|
||||
expect(badge.cssClass).toBe('ofstedInspected');
|
||||
});
|
||||
|
||||
it('returns a Report Card badge when ofsted_rc_date is present', () => {
|
||||
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_rc_date: '2026-02-03' });
|
||||
expect(badge.label).toBe('Report Card · 2026');
|
||||
|
||||
Reference in new issue
Block a user