/** * The facts the school header and the search rows print: a type in the search * filter's terms, and flags only for what applies. */ import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts'; import type { School } from '@/lib/types'; const school = (over: Partial): School => ({ urn: 1, school_name: 'Test School', ...over }) as School; const labels = (over: Partial) => schoolFlags(school(over)).map((f) => f.label); describe('schoolTypeLabel', () => { it.each([ ['state', 'State school'], ['independent', 'Independent school'], ['special', 'Special school (SEND)'], ['post16', 'Sixth form or college'], ['alternative', 'Alternative provision'], ])("names the %s group in the search filter's terms", (type_group, label) => { expect(schoolTypeLabel(school({ type_group, school_type: 'Academy converter' }))).toBe(label); }); it("prints the register's own name for a type in no group", () => { expect(schoolTypeLabel(school({ type_group: null, school_type: 'Secure units' }))).toBe('Secure units'); }); it('returns null when there is no type at all', () => { expect(schoolTypeLabel(school({}))).toBeNull(); }); }); describe('schoolFlags', () => { it('flags nothing for a mixed, non-faith, non-selective state school', () => { expect(labels({ type_group: 'state', gender: 'Mixed', admissions_policy: 'Non-selective', religious_denomination: 'None', nursery_provision: 'No Nursery Classes', has_sixth_form: false, phase: 'Secondary', })).toEqual([]); }); it('lists who-can-apply flags first, then what the school offers, in a fixed order', () => { expect(labels({ type_group: 'independent', admissions_policy: 'Selective', gender: 'Boys', religious_denomination: 'Christian', nursery_provision: 'Has Nursery Classes', has_sixth_form: true, phase: 'All-through', })).toEqual(['Fee-paying', 'Selective', "Boys' school", 'Christian', 'Nursery class', 'Sixth form']); }); it('marks who-can-apply flags as conditions and offers as provision', () => { const kinds = Object.fromEntries( schoolFlags(school({ admissions_policy: 'Selective', has_sixth_form: true, phase: 'Secondary' })) .map((f) => [f.label, f.kind]), ); expect(kinds).toEqual({ Selective: 'condition', 'Sixth form': 'provision' }); }); it('never prints Non-selective, and never a no-faith value', () => { expect(labels({ admissions_policy: 'Non-selective', religious_denomination: 'Does not apply' })).toEqual([]); expect(labels({ admissions_policy: 'Not applicable', religious_denomination: 'None' })).toEqual([]); // PlaceView's rule: GIAS sometimes says "Not applicable" for no faith too. expect(labels({ religious_denomination: 'Not applicable' })).toEqual([]); }); it('prints the religious character as the register records it', () => { expect(labels({ religious_denomination: 'Church of England/Methodist' })).toEqual(['Church of England/Methodist']); }); it('does not flag a nursery class on a nursery school, or a sixth form on a post-16 one', () => { expect(labels({ phase: 'Nursery', nursery_provision: 'Has Nursery Classes' })).toEqual([]); expect(labels({ phase: '16 plus', has_sixth_form: true })).toEqual([]); }); });