Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59ea8a4bdd | ||
|
|
c931d1078c | ||
|
|
807133c305 | ||
|
|
e3f21a5bc7 | ||
|
|
dea435a906 |
No files matched your search
@@ -410,6 +410,29 @@ test('search and the school page agree on how many pupils a secondary has', asyn
|
|||||||
expect(school.total_pupils).toBe(detail.school_info.total_pupils);
|
expect(school.total_pupils).toBe(detail.school_info.total_pupils);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a secondary search row compares its Attainment 8 with the LA average', async ({ page }) => {
|
||||||
|
// The comparison vanished unnoticed: the averages were fetched with
|
||||||
|
// force-cache, so one stored failure hid it in that browser for good.
|
||||||
|
// Playwright disables the HTTP cache when it intercepts requests, so this
|
||||||
|
// guards the comparison itself; the unit test pins the cache mode.
|
||||||
|
const la = await (await page.request.get('/api/la-averages')).json();
|
||||||
|
const averages: Record<string, number> = la.secondary?.attainment_8_by_la ?? {};
|
||||||
|
const res = await page.request.get('/api/schools?search=school&phase=secondary&page_size=50');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const school = ((await res.json()).schools ?? []).find(
|
||||||
|
(s: { attainment_8_score?: number | null; local_authority?: string; school_type?: string }) =>
|
||||||
|
s.attainment_8_score != null && s.local_authority != null && averages[s.local_authority] != null
|
||||||
|
&& !/special|pupil referral|alternative provision/i.test(s.school_type ?? ''));
|
||||||
|
test.skip(!school, 'no mainstream secondary with an LA average here');
|
||||||
|
|
||||||
|
await searchByName(page, school.school_name);
|
||||||
|
const link = page.locator(`a[href^="/school/${school.urn}-"]`).first();
|
||||||
|
await expect(link).toBeVisible({ timeout: 15_000 });
|
||||||
|
const stats = link.locator('xpath=ancestor::div[contains(@class, "__rowContent")][1]')
|
||||||
|
.locator('[class*="__line3"]');
|
||||||
|
await expect(stats.getByText(/vs LA avg/)).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
test('a phase outside primary/secondary filters to that phase, not to everything', async ({ page }) => {
|
test('a phase outside primary/secondary filters to that phase, not to everything', async ({ page }) => {
|
||||||
// The search page offers every GIAS phase, but the API only knew the grouped
|
// The search page offers every GIAS phase, but the API only knew the grouped
|
||||||
// ones and silently dropped the rest — so "Nursery" returned primaries.
|
// ones and silently dropped the rest — so "Nursery" returned primaries.
|
||||||
@@ -3341,3 +3364,26 @@ for (const width of [360, 390, 430]) {
|
|||||||
expect(failing).toEqual([]);
|
expect(failing).toEqual([]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The header's facts row read GIAS text as booleans: "Not applicable" put a
|
||||||
|
* "Nursery" chip on secondaries aged 11–18, and "Girls" became "Girls's
|
||||||
|
* school". Data-invariant: the chip follows whatever the API says.
|
||||||
|
*/
|
||||||
|
test('a girls\' secondary header names it properly and shows Nursery only when it has one', async ({ page }) => {
|
||||||
|
const res = await page.request.get('/api/schools?search=school&phase=secondary&gender=girls&page_size=1');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const [school] = (await res.json()).schools ?? [];
|
||||||
|
test.skip(!school, 'no girls\' secondary in this environment');
|
||||||
|
expect(school.gender, 'the gender filter was ignored').toBe('Girls');
|
||||||
|
const detail = await (await page.request.get(`/api/schools/${school.urn}`)).json();
|
||||||
|
// Without the field, the Nursery assertion below would pass vacuously.
|
||||||
|
expect(detail.school_info).toHaveProperty('nursery_provision');
|
||||||
|
|
||||||
|
await page.goto(`/school/${school.urn}`);
|
||||||
|
const header = page.locator('header', { has: page.getByRole('heading', { level: 1 }) });
|
||||||
|
await expect(header.getByText("Girls' school", { exact: true })).toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(header.getByText(/'s school/)).toHaveCount(0);
|
||||||
|
await expect(header.getByText('Nursery', { exact: true }))
|
||||||
|
.toHaveCount(detail.school_info.nursery_provision === 'Has Nursery Classes' ? 1 : 0);
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import { HomeView } from '@/components/HomeView';
|
import { HomeView } from '@/components/HomeView';
|
||||||
import { fetchSchools } from '@/lib/api';
|
import { fetchLAaverages, fetchSchools } from '@/lib/api';
|
||||||
import { primaryFixture } from '../support/schoolFixtures';
|
import { primaryFixture } from '../support/schoolFixtures';
|
||||||
import type { SchoolsResponse, School } from '@/lib/types';
|
import type { SchoolsResponse, School } from '@/lib/types';
|
||||||
|
|
||||||
@@ -84,3 +84,23 @@ test('failed map requests can be retried by reopening the map', async () => {
|
|||||||
expect(fetchSchools).toHaveBeenCalledTimes(2);
|
expect(fetchSchools).toHaveBeenCalledTimes(2);
|
||||||
expect(screen.getByTestId('map')).toHaveTextContent('Retry result');
|
expect(screen.getByTestId('map')).toHaveTextContent('Retry result');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('LA averages are not fetched with force-cache, so one failure is not replayed for good', async () => {
|
||||||
|
// force-cache serves any stored response, however old, without asking the
|
||||||
|
// server. A request that failed once (a staging deploy restart, the July
|
||||||
|
// proxy outage) was stored and replayed on every later visit, and the
|
||||||
|
// "vs LA avg" delta vanished from every secondary row in that browser.
|
||||||
|
// The default mode honours the API's Cache-Control and never reuses an
|
||||||
|
// error.
|
||||||
|
params = new URLSearchParams('search=high');
|
||||||
|
const secondary: SchoolsResponse = {
|
||||||
|
...response('Alpha High'),
|
||||||
|
schools: [{ ...primaryFixture.schoolInfo, school_name: 'Alpha High', phase: 'Secondary', attainment_8_score: 50 }],
|
||||||
|
};
|
||||||
|
render(<HomeView initialSchools={secondary} filters={filters} />);
|
||||||
|
await act(async () => {});
|
||||||
|
expect(fetchLAaverages).toHaveBeenCalled();
|
||||||
|
for (const [options] of jest.mocked(fetchLAaverages).mock.calls) {
|
||||||
|
expect(options?.cache).not.toBe('force-cache');
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -361,12 +361,12 @@ describe('PlaceView school attributes', () => {
|
|||||||
{ urn: 1, school_name: 'Alpha Primary', phase: 'Primary',
|
{ urn: 1, school_name: 'Alpha Primary', phase: 'Primary',
|
||||||
rwm_expected_pct: 82, attainment_8_score: null,
|
rwm_expected_pct: 82, attainment_8_score: null,
|
||||||
age_range: '4-11', religious_denomination: 'Church of England',
|
age_range: '4-11', religious_denomination: 'Church of England',
|
||||||
nursery_provision: true,
|
nursery_provision: 'Has Nursery Classes',
|
||||||
parliamentary_constituency: 'Chelmsford' } as never,
|
parliamentary_constituency: 'Chelmsford' } as never,
|
||||||
{ urn: 2, school_name: 'Beta High', phase: 'Secondary',
|
{ urn: 2, school_name: 'Beta High', phase: 'Secondary',
|
||||||
rwm_expected_pct: null, attainment_8_score: 47,
|
rwm_expected_pct: null, attainment_8_score: 47,
|
||||||
age_range: '11-16', religious_denomination: 'Does not apply',
|
age_range: '11-16', religious_denomination: 'Does not apply',
|
||||||
nursery_provision: false,
|
nursery_provision: 'No Nursery Classes',
|
||||||
parliamentary_constituency: 'Witham' } as never,
|
parliamentary_constituency: 'Witham' } as never,
|
||||||
],
|
],
|
||||||
averages: { rwm_expected_pct: 63, attainment_8_score: 45 },
|
averages: { rwm_expected_pct: 63, attainment_8_score: 45 },
|
||||||
@@ -459,6 +459,18 @@ describe('PlaceView school attributes', () => {
|
|||||||
expect(cells.slice(2)).toEqual(['—', '—', '—', '—']);
|
expect(cells.slice(2)).toEqual(['—', '—', '—', '—']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reads "Not applicable" as no nursery, not as a yes', () => {
|
||||||
|
// GIAS sends text. Tested for truthiness, every value was a "Yes".
|
||||||
|
const notApplicable: PlaceDetail = {
|
||||||
|
...withAttributes,
|
||||||
|
schools: [{ urn: 5, school_name: 'Epsilon Primary', phase: 'Primary',
|
||||||
|
rwm_expected_pct: 70, nursery_provision: 'Not applicable' } as never],
|
||||||
|
};
|
||||||
|
const { container } = render(<PlaceView detail={notApplicable} phase="primary"
|
||||||
|
englandAverage={61} neighbours={[]} />);
|
||||||
|
expect(container.querySelector('tbody')!.textContent).not.toContain('Yes');
|
||||||
|
});
|
||||||
|
|
||||||
it('gives an all-through school its nursery under primary only', () => {
|
it('gives an all-through school its nursery under primary only', () => {
|
||||||
// All-through schools render in both groups. Nursery belongs to the
|
// All-through schools render in both groups. Nursery belongs to the
|
||||||
// primary reading of the same school, not the secondary one.
|
// primary reading of the same school, not the secondary one.
|
||||||
@@ -467,7 +479,7 @@ describe('PlaceView school attributes', () => {
|
|||||||
schools: [{ urn: 4, school_name: 'Delta Academy', phase: 'All-through',
|
schools: [{ urn: 4, school_name: 'Delta Academy', phase: 'All-through',
|
||||||
rwm_expected_pct: 66, attainment_8_score: 51,
|
rwm_expected_pct: 66, attainment_8_score: 51,
|
||||||
age_range: '4-18', religious_denomination: 'None',
|
age_range: '4-18', religious_denomination: 'None',
|
||||||
nursery_provision: true,
|
nursery_provision: 'Has Nursery Classes',
|
||||||
parliamentary_constituency: 'Chelmsford' } as never],
|
parliamentary_constituency: 'Chelmsford' } as never],
|
||||||
};
|
};
|
||||||
const { container } = render(<PlaceView detail={allThrough}
|
const { container } = render(<PlaceView detail={allThrough}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* The facts row under the school name.
|
||||||
|
*
|
||||||
|
* nursery_provision is GIAS text, not a boolean: "Has Nursery Classes",
|
||||||
|
* "No Nursery Classes" or "Not applicable". Tested for truthiness, every one
|
||||||
|
* of those read as a nursery, so secondaries aged 11–18 showed "Nursery".
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { screen } from '@testing-library/react';
|
||||||
|
import type { School } from '@/lib/types';
|
||||||
|
import { primaryFixture, secondaryFixture } from '../support/schoolFixtures';
|
||||||
|
import { renderSchoolDetail, renderSecondarySchoolDetail } from '../support/renderSchoolDetail';
|
||||||
|
|
||||||
|
jest.mock('@/lib/analytics', () => ({
|
||||||
|
track: jest.fn(),
|
||||||
|
getNavigationSource: () => 'direct',
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/PerformanceChart', () => ({
|
||||||
|
PerformanceChart: () => <div data-testid="performance-chart" />,
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/SatsChart', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: () => <div data-testid="sats-chart" />,
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/AdmissionsTrendChart', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: () => <div data-testid="admissions-trend-chart" />,
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/SchoolHeroMap', () => ({
|
||||||
|
SchoolHeroMap: () => <div data-testid="hero-map" />,
|
||||||
|
__esModule: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
function withSchool<T extends { schoolInfo: School }>(fixture: T, info: Partial<School>): T {
|
||||||
|
return { ...fixture, schoolInfo: { ...fixture.schoolInfo, ...info } };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('school header nursery chip', () => {
|
||||||
|
it('shows Nursery when GIAS says the school has nursery classes', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { nursery_provision: 'Has Nursery Classes' }));
|
||||||
|
expect(screen.getByText('Nursery', { selector: 'span' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['No Nursery Classes', 'Not applicable', null])(
|
||||||
|
'hides Nursery when GIAS says %p',
|
||||||
|
(value) => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { nursery_provision: value }));
|
||||||
|
expect(screen.queryByText('Nursery', { selector: 'span' })).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('school header single-sex chip', () => {
|
||||||
|
it.each([['Girls', "Girls' school"], ['Boys', "Boys' school"]])(
|
||||||
|
'labels a %s school with a plural possessive',
|
||||||
|
(gender, label) => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { gender }));
|
||||||
|
expect(screen.getByText(label)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/'s school/)).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it('says nothing for a mixed school', () => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { gender: 'Mixed' }));
|
||||||
|
expect(screen.queryByText(/^(Girls|Boys|Mixed)'s? school$/)).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -15,6 +15,8 @@ import {
|
|||||||
computeYBounds,
|
computeYBounds,
|
||||||
formatAgeRange,
|
formatAgeRange,
|
||||||
formatAgeSpan,
|
formatAgeSpan,
|
||||||
|
hasNurseryClasses,
|
||||||
|
singleSexLabel,
|
||||||
} from '@/lib/utils';
|
} from '@/lib/utils';
|
||||||
|
|
||||||
describe('formatPercentage', () => {
|
describe('formatPercentage', () => {
|
||||||
@@ -346,3 +348,32 @@ describe('formatAgeRange', () => {
|
|||||||
expect(formatAgeRange('4-11')).toBe('Ages 4–11');
|
expect(formatAgeRange('4-11')).toBe('Ages 4–11');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('hasNurseryClasses', () => {
|
||||||
|
it('is true only for the GIAS value that means it', () => {
|
||||||
|
// GIAS sends text, and two of its three values mean no nursery.
|
||||||
|
expect(hasNurseryClasses('Has Nursery Classes')).toBe(true);
|
||||||
|
expect(hasNurseryClasses('No Nursery Classes')).toBe(false);
|
||||||
|
expect(hasNurseryClasses('Not applicable')).toBe(false);
|
||||||
|
expect(hasNurseryClasses(null)).toBe(false);
|
||||||
|
expect(hasNurseryClasses(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('singleSexLabel', () => {
|
||||||
|
it('uses the plural possessive GIAS values need', () => {
|
||||||
|
expect(singleSexLabel('Girls')).toBe("Girls' school");
|
||||||
|
expect(singleSexLabel('Boys')).toBe("Boys' school");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores case, as hasNurseryClasses does', () => {
|
||||||
|
expect(singleSexLabel(' girls ')).toBe("Girls' school");
|
||||||
|
expect(singleSexLabel('BOYS')).toBe("Boys' school");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null for a mixed or unknown school', () => {
|
||||||
|
expect(singleSexLabel('Mixed')).toBeNull();
|
||||||
|
expect(singleSexLabel(null)).toBeNull();
|
||||||
|
expect(singleSexLabel(undefined)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -358,10 +358,14 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
|
|||||||
return () => controller.abort();
|
return () => controller.abort();
|
||||||
}, [resultsView, searchParams, initialSchools.schools]);
|
}, [resultsView, searchParams, initialSchools.schools]);
|
||||||
|
|
||||||
// Fetch LA averages when secondary or mixed schools are visible
|
// Fetch LA averages when secondary or mixed schools are visible. Default
|
||||||
|
// cache mode, never force-cache: force-cache replays any stored response
|
||||||
|
// without asking the server, so one failed request (a deploy restart) hid
|
||||||
|
// every "vs LA avg" delta in that browser for good. The API's Cache-Control
|
||||||
|
// already lets the browser reuse a good answer for five minutes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isSecondaryView && !isMixedView) return;
|
if (!isSecondaryView && !isMixedView) return;
|
||||||
fetchLAaverages({ cache: 'force-cache' })
|
fetchLAaverages()
|
||||||
.then(data => setLaAverages(data.secondary.attainment_8_by_la))
|
.then(data => setLaAverages(data.secondary.attainment_8_by_la))
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, [isSecondaryView, isMixedView]);
|
}, [isSecondaryView, isMixedView]);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import Link from 'next/link';
|
|||||||
import type { PlaceDetail, PlaceSummary } from '@/lib/places';
|
import type { PlaceDetail, PlaceSummary } from '@/lib/places';
|
||||||
import { placeUrl, authoritySlug } from '@/lib/places';
|
import { placeUrl, authoritySlug } from '@/lib/places';
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { schoolUrl, formatAgeSpan } from '@/lib/utils';
|
import { schoolUrl, formatAgeSpan, hasNurseryClasses } from '@/lib/utils';
|
||||||
import { absoluteUrl } from '@/lib/site';
|
import { absoluteUrl } from '@/lib/site';
|
||||||
import { TrackPlaceView } from './TrackPlaceView';
|
import { TrackPlaceView } from './TrackPlaceView';
|
||||||
import styles from './PlaceView.module.css';
|
import styles from './PlaceView.module.css';
|
||||||
@@ -131,9 +131,10 @@ function SchoolTable({ schools, phase }: { schools: School[]; phase: PhaseKey })
|
|||||||
{showNursery && (
|
{showNursery && (
|
||||||
<td className={styles.attr}>
|
<td className={styles.attr}>
|
||||||
{/* Undefined is a mart the pipeline has not rebuilt, and
|
{/* Undefined is a mart the pipeline has not rebuilt, and
|
||||||
false is a school without one. Neither is a "Yes", and
|
"No Nursery Classes" or "Not applicable" is a school
|
||||||
neither is worth two different words. */}
|
without one. None is a "Yes", and none is worth a
|
||||||
{s.nursery_provision ? 'Yes' : NO_VALUE}
|
different word. */}
|
||||||
|
{hasNurseryClasses(s.nursery_provision) ? 'Yes' : NO_VALUE}
|
||||||
</td>
|
</td>
|
||||||
)}
|
)}
|
||||||
<td className={styles.attrWide}>
|
<td className={styles.attrWide}>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { useRouter } from 'next/navigation';
|
|||||||
import { useComparison } from '@/hooks/useComparison';
|
import { useComparison } from '@/hooks/useComparison';
|
||||||
import { SchoolHeroMap, type SchoolHeroMapHandle } from '../SchoolHeroMap';
|
import { SchoolHeroMap, type SchoolHeroMapHandle } from '../SchoolHeroMap';
|
||||||
import type { School, SchoolResult, SchoolCensus } from '@/lib/types';
|
import type { School, SchoolResult, SchoolCensus } from '@/lib/types';
|
||||||
import { formatAgeRange, isProposedToClose } from '@/lib/utils';
|
import { formatAgeRange, hasNurseryClasses, isProposedToClose, singleSexLabel } from '@/lib/utils';
|
||||||
import type { NavItem } from '@/lib/schoolSections';
|
import type { NavItem } from '@/lib/schoolSections';
|
||||||
import { track, getNavigationSource } from '@/lib/analytics';
|
import { track, getNavigationSource } from '@/lib/analytics';
|
||||||
import styles from './SchoolDetailShell.module.css';
|
import styles from './SchoolDetailShell.module.css';
|
||||||
@@ -120,13 +120,14 @@ export function SchoolDetailShell({
|
|||||||
return () => window.removeEventListener('keydown', onKey);
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
}, [sectionsOpen]);
|
}, [sectionsOpen]);
|
||||||
|
|
||||||
// The chrome needs only these four. The section-shape flags are computed
|
// The chrome needs only these few. The section-shape flags are computed
|
||||||
// once on the server (lib/schoolSections) and consumed by the section
|
// once on the server (lib/schoolSections) and consumed by the section
|
||||||
// composers; recomputing them here would duplicate that work for values
|
// composers; recomputing them here would duplicate that work for values
|
||||||
// this component never renders.
|
// this component never renders.
|
||||||
const phase = schoolInfo.phase ?? '';
|
const phase = schoolInfo.phase ?? '';
|
||||||
const isAllThrough = phase.toLowerCase() === 'all-through';
|
const isAllThrough = phase.toLowerCase() === 'all-through';
|
||||||
const hasLocation = schoolInfo.latitude != null && schoolInfo.longitude != null;
|
const hasLocation = schoolInfo.latitude != null && schoolInfo.longitude != null;
|
||||||
|
const singleSex = singleSexLabel(schoolInfo.gender);
|
||||||
|
|
||||||
const handleComparisonToggle = () => {
|
const handleComparisonToggle = () => {
|
||||||
if (isInComparison) {
|
if (isInComparison) {
|
||||||
@@ -211,13 +212,11 @@ export function SchoolDetailShell({
|
|||||||
{isAllThrough && (
|
{isAllThrough && (
|
||||||
<span className={styles.metaItem}>All-through (primary & secondary)</span>
|
<span className={styles.metaItem}>All-through (primary & secondary)</span>
|
||||||
)}
|
)}
|
||||||
{schoolInfo.gender && schoolInfo.gender !== 'Mixed' && (
|
{singleSex && <span className={styles.metaItem}>{singleSex}</span>}
|
||||||
<span className={styles.metaItem}>{schoolInfo.gender}'s school</span>
|
|
||||||
)}
|
|
||||||
{schoolInfo.age_range && (
|
{schoolInfo.age_range && (
|
||||||
<span className={styles.metaItem}>{formatAgeRange(schoolInfo.age_range)}</span>
|
<span className={styles.metaItem}>{formatAgeRange(schoolInfo.age_range)}</span>
|
||||||
)}
|
)}
|
||||||
{schoolInfo.nursery_provision && (
|
{hasNurseryClasses(schoolInfo.nursery_provision) && (
|
||||||
<span className={styles.metaItem}>Nursery</span>
|
<span className={styles.metaItem}>Nursery</span>
|
||||||
)}
|
)}
|
||||||
{schoolInfo.has_sixth_form && (
|
{schoolInfo.has_sixth_form && (
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ export interface School {
|
|||||||
religious_denomination: string | null;
|
religious_denomination: string | null;
|
||||||
age_range: string | null;
|
age_range: string | null;
|
||||||
has_sixth_form?: boolean | null;
|
has_sixth_form?: boolean | null;
|
||||||
nursery_provision?: boolean | null;
|
/** GIAS text; read it through hasNurseryClasses(). */
|
||||||
|
nursery_provision?: string | null;
|
||||||
status?: string | null; // GIAS establishment status ("Open" / "Open, but proposed to close")
|
status?: string | null; // GIAS establishment status ("Open" / "Open, but proposed to close")
|
||||||
|
|
||||||
// Address
|
// Address
|
||||||
|
|||||||
@@ -99,6 +99,26 @@ export function formatAgeRange(ageRange: string | null | undefined): string {
|
|||||||
return /^\d+–\d+$/.test(span) ? `Ages ${span}` : span;
|
return /^\d+–\d+$/.test(span) ? `Ages ${span}` : span;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GIAS NurseryProvision is text: "Has Nursery Classes", "No Nursery Classes"
|
||||||
|
* or "Not applicable". Only the first means a nursery, so never test the raw
|
||||||
|
* value for truthiness.
|
||||||
|
*/
|
||||||
|
export function hasNurseryClasses(value: string | null | undefined): boolean {
|
||||||
|
return value?.trim().toLowerCase() === 'has nursery classes';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Girls' school" / "Boys' school" for a single-sex school, null otherwise.
|
||||||
|
* GIAS genders are plural, so the possessive is a bare apostrophe.
|
||||||
|
*/
|
||||||
|
export function singleSexLabel(gender: string | null | undefined): string | null {
|
||||||
|
const g = gender?.trim().toLowerCase();
|
||||||
|
if (g === 'girls') return "Girls' school";
|
||||||
|
if (g === 'boys') return "Boys' school";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Number Formatting
|
// Number Formatting
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in new issue
Block a user