import React from 'react' import { afterEach, describe, expect, it } from 'vitest' import { render, cleanup } from '@testing-library/react' import { HelmetProvider } from 'react-helmet-async' import SEOHead from './SEOHead' import { BRAND_SUFFIX } from './seo.js' afterEach(() => { cleanup() document.head.querySelectorAll('[data-rh="true"]').forEach(node => node.remove()) }) describe('SEOHead', () => { it('renders one branded title, description, and canonical link', () => { render( , ) expect(document.head.querySelectorAll('title')).toHaveLength(1) expect(document.title).toBe(`Artikel${BRAND_SUFFIX}`) expect(document.title.match(/Dr\. André Knie/g)).toHaveLength(1) expect(document.head.querySelectorAll('meta[name="description"]')).toHaveLength(1) expect(document.head.querySelector('link[rel="canonical"]')?.getAttribute('href')).toBe('https://andreknie.de/artikel') }) it('replaces static fallback metadata instead of duplicating it', () => { document.head.insertAdjacentHTML('beforeend', ` Fallback `) render( , ) expect(document.head.querySelectorAll('[data-seo-fallback]')).toHaveLength(0) expect(document.head.querySelectorAll('title')).toHaveLength(1) expect(document.head.querySelectorAll('meta[name="description"]')).toHaveLength(1) expect(document.head.querySelectorAll('link[rel="canonical"]')).toHaveLength(1) }) it('normalizes relative and absolute image URLs', () => { const { rerender } = render( , ) expect(document.head.querySelector('meta[property="og:image"]')?.getAttribute('content')).toBe('https://andreknie.de/images/andre-knie.webp') rerender( , ) expect(document.head.querySelector('meta[property="og:image"]')?.getAttribute('content')).toBe('https://cdn.example.invalid/image.webp') }) })