55 lines
2.5 KiB
TypeScript
55 lines
2.5 KiB
TypeScript
import { describe, expect, test } from 'vitest'
|
|
import { exportPage } from './html'
|
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
|
|
|
function makePage(overrides: Partial<Page> = {}): Page {
|
|
const base: Page = {
|
|
title: 'T',
|
|
locale: 'en',
|
|
theme: { primaryColor: '#000000', fontFamily: 'Inter' },
|
|
sections: [
|
|
{ type: 'hero', props: { heading: 'Welcome', subheading: 'Sub', imageUrl: 'https://example.com/img.png' } },
|
|
{ type: 'faq', props: { items: [{ q: 'Q1', a: 'A1' }] } },
|
|
{ type: 'features', props: { items: ['One', 'Two'] } },
|
|
{ type: 'testimonials', props: { items: [{ author: 'Jane', quote: 'Great' }] } },
|
|
{ type: 'cta', props: { text: 'Go', href: '#' } },
|
|
] as Page['sections'],
|
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
|
seo: { title: 'SEO', description: 'Desc' },
|
|
}
|
|
return pageSchema.parse({ ...base, ...overrides })
|
|
}
|
|
|
|
describe('Exporter a11y/responsive enhancements', () => {
|
|
test('includes skip link and main landmark', () => {
|
|
const out = exportPage(makePage())
|
|
expect(out.html).toContain('<a href="#main" class="skip-link">')
|
|
expect(out.html).toContain('<main id="main" role="main">')
|
|
})
|
|
|
|
test('sections use aria-labelledby with h2 ids', () => {
|
|
const out = exportPage(makePage())
|
|
expect(out.html).toContain('<section class="faq" aria-labelledby="faq-heading">')
|
|
expect(out.html).toContain('<h2 id="faq-heading">FAQ</h2>')
|
|
expect(out.html).toContain('<section class="features" aria-labelledby="features-heading">')
|
|
expect(out.html).toContain('<h2 id="features-heading">Features</h2>')
|
|
expect(out.html).toContain('<section class="testimonials" aria-labelledby="testimonials-heading">')
|
|
expect(out.html).toContain('<h2 id="testimonials-heading">Testimonials</h2>')
|
|
})
|
|
|
|
test('hero image alt derives from heading', () => {
|
|
const out = exportPage(makePage())
|
|
expect(out.html).toContain('<h1 id="hero-heading">Welcome</h1>')
|
|
expect(out.html).toMatch(/<img[^>]*src="https:\/\/example\.com\/img\.png"[^>]*alt="Welcome"[^>]*\/>/)
|
|
})
|
|
|
|
test('responsive and a11y CSS tokens exist', () => {
|
|
const out = exportPage(makePage())
|
|
expect(out.css).toMatch(/@media \(max-width: 640px\)/)
|
|
expect(out.css).toMatch(/@media \(prefers-reduced-motion: reduce\)/)
|
|
expect(out.css).toMatch(/a\.skip-link:focus/)
|
|
expect(out.css).toMatch(/outline: 3px solid/)
|
|
})
|
|
})
|