32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { exportPage } from '@/lib/exporter/html'
|
|
import { pageSchema, type Page } from '@/lib/schema/page'
|
|
|
|
function makePage(overrides: Partial<Page> = {}): Page {
|
|
const base: Page = {
|
|
title: 'Hero Edge',
|
|
locale: 'en',
|
|
theme: { primaryColor: '#2563eb', fontFamily: 'Inter' },
|
|
sections: [
|
|
{ type: 'hero', props: { heading: 'Welcome', subheading: ' ', imageUrl: 'https://img.example/h.png' } },
|
|
] as Page['sections'],
|
|
form: { actionUrl: '', fields: [], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 } },
|
|
analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' },
|
|
seo: { title: 't', description: 'd' },
|
|
}
|
|
return pageSchema.parse({ ...base, ...overrides })
|
|
}
|
|
|
|
describe('Exporter - hero edge cases', () => {
|
|
it('omits subheading when whitespace-only', () => {
|
|
const out = exportPage(makePage())
|
|
expect(out.html).toContain('<h1 id="hero-heading">Welcome</h1>')
|
|
expect(out.html).not.toMatch(/<div class="text">[\s\S]*<p>\s*<\/p>/)
|
|
})
|
|
|
|
it('trims subheading content', () => {
|
|
const out = exportPage(makePage({ sections: [ { type: 'hero', props: { heading: 'Welcome', subheading: ' Hello world ', imageUrl: 'https://img.example/h.png' } } ] as Page['sections'] }))
|
|
expect(out.html).toContain('<p>Hello world</p>')
|
|
})
|
|
})
|