Files
landing-builder/lib/exporter/headingsLevels.test.ts
T

37 lines
1.6 KiB
TypeScript

import { describe, expect, test } from 'vitest'
import { exportPage } from './html'
import { pageSchema, type Page } from '@/lib/schema/page'
function makePage(): Page {
return pageSchema.parse({
title: 'My Landing',
locale: 'en',
theme: { primaryColor: '#222222', fontFamily: 'Inter' },
sections: [
{ type: 'hero', props: { heading: 'Welcome', subheading: 'Sub', imageUrl: 'https://example.com/hero.png' } },
{ type: 'features', props: { items: ['Fast', 'Reliable'] } },
{ type: 'testimonials', props: { items: [{ author: 'Jane', quote: 'Great' }] } },
{ type: 'faq', props: { items: [{ q: 'Q1', a: 'A1' }] } },
{ type: 'cta', props: { text: 'Start', href: '#' } },
] as Page['sections'],
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
seo: { title: 'SEO', description: 'Desc' },
})
}
describe('Exporter heading levels', () => {
test('hero uses h1, sections use h2, faq questions use h3', () => {
const out = exportPage(makePage())
// hero h1
expect(out.html).toMatch(/<section class="hero"[\s\S]*<h1[\s\S]*>Welcome<\/h1>/)
// features/testimonials/faq/cta use h2 for section titles
expect(out.html).toContain('<h2 id="features-heading">')
expect(out.html).toContain('<h2 id="testimonials-heading">')
expect(out.html).toContain('<h2 id="faq-heading">')
expect(out.html).toContain('<h2 id="cta-heading">')
// faq item question headings h3
expect(out.html).toMatch(/<section class="faq"[\s\S]*<h3[\s\S]*>Q1<\/h3>/)
})
})