2026-09-02 16:11:48 +01:00
|
|
|
import { generateMetadata as placeMeta } from '@/app/(frontend)/schools/[place]/page';
|
2026-08-21 18:17:57 +01:00
|
|
|
|
|
|
|
|
jest.mock('@/lib/places', () => ({
|
|
|
|
|
...jest.requireActual('@/lib/places'),
|
|
|
|
|
fetchPlace: jest.fn(async (kind: string, slug: string) =>
|
|
|
|
|
slug === 'atlantis' ? null : ({
|
|
|
|
|
place: { kind, slug, name: 'Brentwood', count: 29,
|
|
|
|
|
parent_authority: 'Essex' },
|
|
|
|
|
schools: [], averages: { rwm_expected_pct: 63, attainment_8_score: null },
|
|
|
|
|
})),
|
|
|
|
|
fetchPlaces: jest.fn(async () => []),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe('place page metadata', () => {
|
|
|
|
|
it('titles the page the way the place is searched', async () => {
|
|
|
|
|
const m = await placeMeta({ params: Promise.resolve({ place: 'brentwood' }) });
|
2026-08-21 21:42:53 +01:00
|
|
|
expect((m.title as { absolute: string }).absolute).toMatch(/schools in brentwood/i);
|
2026-08-21 18:17:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('canonicalises to its own path on the www host', async () => {
|
|
|
|
|
const m = await placeMeta({ params: Promise.resolve({ place: 'brentwood' }) });
|
|
|
|
|
expect(m.alternates?.canonical)
|
|
|
|
|
.toBe('https://www.schoolcompare.co.uk/schools/brentwood');
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-21 21:42:53 +01:00
|
|
|
it('opts out of the layout template, which would double the brand', () => {
|
|
|
|
|
// The root layout appends '| schoolcompare' to a plain string title, and
|
|
|
|
|
// these titles already carry it — every place page shipped reading
|
|
|
|
|
// '... | schoolcompare | schoolcompare' until this was made absolute.
|
|
|
|
|
return placeMeta({ params: Promise.resolve({ place: 'brentwood' }) })
|
|
|
|
|
.then((m) => {
|
|
|
|
|
expect(typeof m.title).toBe('object');
|
|
|
|
|
expect((m.title as { absolute: string }).absolute)
|
|
|
|
|
.not.toMatch(/schoolcompare.*schoolcompare/);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-21 18:17:57 +01:00
|
|
|
it('an unknown place gets a not-found title rather than inventing one', async () => {
|
|
|
|
|
const m = await placeMeta({ params: Promise.resolve({ place: 'atlantis' }) });
|
|
|
|
|
expect(m.title).toMatch(/not found/i);
|
|
|
|
|
});
|
|
|
|
|
});
|