83 lines
3.1 KiB
TypeScript
83 lines
3.1 KiB
TypeScript
import { computeSecondaryFlags, buildSecondaryNavItems } from '@/lib/schoolSections';
|
|||
|
|
import type { School, SchoolDestinations } from '@/lib/types';
|
||
|
|
|
||
|
|
const schoolInfo = {
|
||
|
|
urn: 137083, school_name: 'Northbrook Academy', phase: 'Secondary',
|
||
|
|
has_sixth_form: true,
|
||
|
|
} as unknown as School;
|
||
|
|
|
||
|
|
const base = { schoolInfo, yearlyData: [], deprivation: null, finance: null };
|
||
|
|
|
||
|
|
const phase = (categories = 1) => ({
|
||
|
|
cohort_year: '2022/23',
|
||
|
|
groups: {
|
||
|
|
all: {
|
||
|
|
cohort: 180,
|
||
|
|
categories: Array.from({ length: categories }, () => ({
|
||
|
|
category: 'school_sixth_form' as const,
|
||
|
|
pupils: 75, percentage: 41.7, status: 'published' as const,
|
||
|
|
})),
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
const ks4Only: SchoolDestinations = { ks4: phase(), ks5: null };
|
||
|
|
const both: SchoolDestinations = { ks4: phase(), ks5: phase() };
|
||
|
|
|
||
|
|
describe('computeSecondaryFlags — destinations', () => {
|
||
|
|
it('flags KS4 destinations when the block carries categories', () => {
|
||
|
|
const flags = computeSecondaryFlags({ ...base, destinations: ks4Only });
|
||
|
|
expect(flags.hasKs4Destinations).toBe(true);
|
||
|
|
expect(flags.hasKs5Destinations).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('flags both phases when both are present', () => {
|
||
|
|
const flags = computeSecondaryFlags({ ...base, destinations: both });
|
||
|
|
expect(flags.hasKs4Destinations).toBe(true);
|
||
|
|
expect(flags.hasKs5Destinations).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('flags neither when the block is absent', () => {
|
||
|
|
const flags = computeSecondaryFlags({ ...base, destinations: null });
|
||
|
|
expect(flags.hasKs4Destinations).toBe(false);
|
||
|
|
expect(flags.hasKs5Destinations).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('does not flag a phase whose groups carry no categories', () => {
|
||
|
|
const empty: SchoolDestinations = {
|
||
|
|
ks4: { cohort_year: '2022/23', groups: {} }, ks5: null,
|
||
|
|
};
|
||
|
|
expect(computeSecondaryFlags({ ...base, destinations: empty }).hasKs4Destinations)
|
||
|
|
.toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('does not flag a phase whose only group has an empty category list', () => {
|
||
|
|
const empty: SchoolDestinations = { ks4: phase(0), ks5: null };
|
||
|
|
expect(computeSecondaryFlags({ ...base, destinations: empty }).hasKs4Destinations)
|
||
|
|
.toBe(false);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('buildSecondaryNavItems — destinations', () => {
|
||
|
|
const navInput = {
|
||
|
|
ofsted: null, admissions: null, admissionDistance: null,
|
||
|
|
hasLocation: false, yearlyDataLength: 0,
|
||
|
|
};
|
||
|
|
|
||
|
|
it('adds both entries, after GCSEs', () => {
|
||
|
|
const flags = computeSecondaryFlags({ ...base, destinations: both });
|
||
|
|
const ids = buildSecondaryNavItems({ ...flags, hasResults: true }, navInput)
|
||
|
|
.map(i => i.id);
|
||
|
|
expect(ids).toContain('destinations');
|
||
|
|
expect(ids).toContain('post16-destinations');
|
||
|
|
expect(ids.indexOf('destinations')).toBeGreaterThan(ids.indexOf('gcse'));
|
||
|
|
expect(ids.indexOf('post16-destinations')).toBe(ids.indexOf('destinations') + 1);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('adds no entry for a phase that will not render — the nav must not link to a missing anchor', () => {
|
||
|
|
const flags = computeSecondaryFlags({ ...base, destinations: null });
|
||
|
|
const ids = buildSecondaryNavItems(flags, navInput).map(i => i.id);
|
||
|
|
expect(ids).not.toContain('destinations');
|
||
|
|
expect(ids).not.toContain('post16-destinations');
|
||
|
|
});
|
||
|
|
});
|