Files
gw-svelte/src/lib/seo.test.ts
T

72 lines
2.2 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from 'vitest';
import { locationPages } from '$lib/content/locations';
import { buildAreaServed, buildBreadcrumb, buildLocationSeo } from './seo';
import type { LocationPageContent } from '$lib/types';
describe('seo helpers', () => {
it('derives area served from location content', () => {
const areaServed = buildAreaServed();
expect(areaServed).toHaveLength(locationPages.length);
expect(areaServed[0]).toEqual({
'@type': 'Place',
name: `${locationPages[0].suburb}, Auckland, New Zealand`
});
});
it('builds location seo from data with sensible defaults', () => {
const seo = buildLocationSeo(locationPages[0]);
expect(seo.title).toBe('Dog Walkers in Mt Eden | Goodwalk Auckland');
expect(seo.canonicalPath).toBe('/locations/mt-eden');
2026-05-12 00:45:02 +12:00
expect(seo.image).toBe('/images/auckland-pack-walk-small-dogs-group.jpg');
expect(seo.imageAlt).toBe('Goodwalk dog walkers in Mt Eden, Auckland');
expect(seo.structuredData).toHaveLength(2);
});
it('builds breadcrumbs from real paths', () => {
const breadcrumb = buildBreadcrumb([
{ name: 'Home', url: 'https://www.goodwalk.co.nz' },
{ name: 'Mt Eden', path: '/locations/mt-eden' }
]);
expect(breadcrumb.itemListElement).toEqual([
{
'@type': 'ListItem',
position: 1,
name: 'Home',
item: 'https://www.goodwalk.co.nz'
},
{
'@type': 'ListItem',
position: 2,
name: 'Mt Eden',
item: 'https://www.goodwalk.co.nz/locations/mt-eden'
}
]);
});
it('uses the first park image for seo when no explicit seo image is set', () => {
const location: LocationPageContent = {
suburb: 'Test Suburb',
slug: 'test-suburb',
intro: 'Test intro',
parks: [
{
name: 'Test Park',
description: 'A local park for testing.',
image: {
src: '/images/test-park-photo.webp',
alt: 'Dogs walking through Test Park'
}
}
]
};
const seo = buildLocationSeo(location);
expect(seo.image).toBe('/images/test-park-photo.webp');
expect(seo.imageAlt).toBe('Dogs walking through Test Park');
});
});