import { generateMetadata as placeMeta } from '@/app/(frontend)/schools/[place]/page'; 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' }) }); expect((m.title as { absolute: string }).absolute).toMatch(/schools in brentwood/i); }); 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'); }); 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/); }); }); 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); }); });