import { beforeEach, describe, expect, it } from 'vitest'; import { applyPageMeta, buildMachinePageMeta } from './meta'; describe('meta utilities', () => { beforeEach(() => { document.head.innerHTML = ''; document.title = 'Previous title'; }); it('applies managed SEO and social tags to the document head', () => { const cleanup = applyPageMeta( { title: 'Turbojet Engine', description: 'Explore compressor, combustion, turbine, and nozzle stages in 3D.', url: '/machines/turbojet-engine', image: '/social/mechanica-og.svg', imageAlt: 'Turbojet engine 3D visualization', keywords: ['jet engine', 'compressor', 'turbine'], structuredData: { '@context': 'https://schema.org', '@type': 'LearningResource', name: 'Turbojet Engine', }, }, { baseUrl: 'https://mechanica.example', restoreOnCleanup: true, }, ); expect(document.title).toBe('Turbojet Engine • Mechanica'); expect(document.querySelector('meta[name="description"]')?.getAttribute('content')).toBe( 'Explore compressor, combustion, turbine, and nozzle stages in 3D.', ); expect(document.querySelector('meta[property="og:url"]')?.getAttribute('content')).toBe( 'https://mechanica.example/machines/turbojet-engine', ); expect(document.querySelector('meta[property="og:image"]')?.getAttribute('content')).toBe( 'https://mechanica.example/social/mechanica-og.svg', ); expect(document.querySelector('link[rel="canonical"]')?.getAttribute('href')).toBe( 'https://mechanica.example/machines/turbojet-engine', ); expect(document.querySelector('script[type="application/ld+json"]')?.textContent).toContain( 'Turbojet Engine', ); cleanup(); expect(document.title).toBe('Previous title'); expect(document.querySelector('[data-mechanica-meta]')).toBeNull(); }); it('builds machine page metadata with educational structured data', () => { const meta = buildMachinePageMeta( { id: 'planetary-gearbox', title: 'Planetary Gearbox', description: 'Sun, planet, and ring gear torque paths.', category: 'Gearboxes & Drives', difficulty: 'Intermediate', }, { baseUrl: 'https://mechanica.example', }, ); expect(meta.url).toBe('https://mechanica.example/machines/planetary-gearbox'); expect(meta.image).toBe('https://mechanica.example/social/mechanica-og.svg'); expect(meta.structuredData).toMatchObject({ '@type': 'LearningResource', proficiencyLevel: 'Intermediate', }); }); });