/** * "Pupils" on a school page is the size of the school. * * A year's results row carries the cohort its figures were measured on. For a * secondary that is the GCSE year group alone (Burntwood: 245, against 1,462 * on roll), so it must never stand in for the whole-school count. */ import { screen } from '@testing-library/react'; import { secondaryFixture } from '../support/schoolFixtures'; import { renderSecondarySchoolDetail } from '../support/renderSchoolDetail'; jest.mock('@/lib/analytics', () => ({ track: jest.fn(), getNavigationSource: () => 'direct', })); jest.mock('@/components/PerformanceChart', () => ({ PerformanceChart: () =>
, })); jest.mock('@/components/SatsChart', () => ({ __esModule: true, default: () => , })); jest.mock('@/components/AdmissionsTrendChart', () => ({ __esModule: true, default: () => , })); jest.mock('@/components/SchoolHeroMap', () => ({ SchoolHeroMap: () => , __esModule: true, })); function withoutCensus(schoolTotal: number | null) { const yearlyData = secondaryFixture.yearlyData.map((r) => ({ ...r, total_pupils: 245 })); return { ...secondaryFixture, census: null, yearlyData, schoolInfo: { ...secondaryFixture.schoolInfo, total_pupils: schoolTotal }, }; } describe('pupil count without a census record', () => { it('uses the register count in the header, not the results cohort', () => { renderSecondarySchoolDetail(withoutCensus(1462)); expect(screen.getByText('1,462 pupils')).toBeInTheDocument(); expect(screen.queryByText('245 pupils')).not.toBeInTheDocument(); }); it('shows no count rather than the results cohort when the register has none', () => { renderSecondarySchoolDetail(withoutCensus(null)); expect(screen.queryByText(/^[\d,]+ pupils$/)).not.toBeInTheDocument(); expect(screen.queryByText('Total pupils')).not.toBeInTheDocument(); }); });