56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
|
import { exportPage } from '@/lib/exporter/html'
|
|
|
|
function makePage(): Page {
|
|
return pageSchema.parse({
|
|
title: 'Sections Regression',
|
|
locale: 'en',
|
|
theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' },
|
|
sections: [
|
|
{ type: 'hero', props: { heading: 'Welcome', subheading: '', imageUrl: 'https://via.placeholder.com/800x400' } },
|
|
{ type: 'features', props: { items: ['F1','F2'] } },
|
|
{ type: 'benefits', props: { items: ['B1','B2','B3'] } },
|
|
{ type: 'testimonials', props: { items: [{ author: 'Ada', quote: 'Great' }] } },
|
|
{ type: 'faq', props: { items: [{ q: 'Q1', a: 'A1' }] } },
|
|
{ type: 'cta', props: { text: 'Start', href: '#' } },
|
|
],
|
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
|
seo: { title: 'SEO', description: 'Desc' },
|
|
})
|
|
}
|
|
|
|
describe('Exporter - sections regression (includes benefits)', () => {
|
|
it('renders sections with correct ARIA/heading/list structures', () => {
|
|
const out = exportPage(makePage())
|
|
const html = out.html
|
|
|
|
// hero h1
|
|
expect(html).toMatch(/<section class="hero" aria-labelledby="hero-heading">/)
|
|
expect(html).toMatch(/<h1 id="hero-heading">Welcome<\/h1>/)
|
|
|
|
// features
|
|
expect(html).toMatch(/<section class="features" aria-labelledby="features-heading">/)
|
|
expect(html).toMatch(/<h2 id="features-heading">Features<\/h2>/)
|
|
expect(html).toMatch(/<ul class="features-list">[\s\S]*<li class="feature-item">F1<\/li>[\s\S]*<li class="feature-item">F2<\/li>[\s\S]*<\/ul>/)
|
|
|
|
// benefits
|
|
expect(html).toMatch(/<section class="benefits" aria-labelledby="benefits-heading">/)
|
|
expect(html).toMatch(/<h2 id="benefits-heading">Benefits<\/h2>/)
|
|
expect(html).toMatch(/<ul class="benefits-list">[\s\S]*<li class="benefit-item">B1<\/li>[\s\S]*<li class="benefit-item">B2<\/li>[\s\S]*<li class="benefit-item">B3<\/li>[\s\S]*<\/ul>/)
|
|
|
|
// testimonials
|
|
expect(html).toMatch(/<section class="testimonials" aria-labelledby="testimonials-heading">/)
|
|
expect(html).toMatch(/<h2 id="testimonials-heading">Testimonials<\/h2>/)
|
|
|
|
// faq with h3
|
|
expect(html).toMatch(/<section class="faq" aria-labelledby="faq-heading">/)
|
|
expect(html).toMatch(/<h2 id="faq-heading">FAQ<\/h2>/)
|
|
expect(html).toMatch(/<h3 class="faq-q">Q1<\/h3>/)
|
|
|
|
// cta
|
|
expect(html).toMatch(/<section class="cta" aria-labelledby="cta-heading">/)
|
|
expect(html).toMatch(/<h2 id="cta-heading">CTA<\/h2>/)
|
|
})
|
|
})
|