import { describe, it, expect } from 'vitest' import { exportPage } from '@/lib/exporter/html' import type { Page } from '@/lib/schema/page' const makePage = (overrides: Partial = {}): Page => ({ title: 'Form Error Regression', locale: 'en', theme: { primaryColor: '#0ea5e9', fontFamily: 'Inter' }, sections: [], form: { actionUrl: '', fields: [ { type: 'text', name: 'name', label: 'Name', required: true, pattern: '^[A-Za-z ]+$', maxLength: 30, help: 'Enter your name' }, { type: 'email', name: 'email', label: 'Email', required: true, help: 'We will contact you' }, { type: 'textarea', name: 'msg', label: 'Message', required: false, maxLength: 200, help: 'Optional' }, ], spamProtection: { honeypotFieldName: '_hp', minSubmitSeconds: 2 }, }, analytics: { ga4MeasurementId: '', metaPixelId: '', customHeadHtml: '' }, seo: { title: 'T', description: 'D' }, ...overrides, }) describe('Exporter - form error/required/pattern regression', () => { it('adds required/pattern/maxlength attributes and aria-describedby links', () => { const page = makePage() const { html } = exportPage(page) // required/pattern on text expect(html).toMatch(/]*name="name"[^>]*required/) expect(html).toMatch(/]*name="name"[^>]*pattern="\^\[A-Za-z \]\+\$"/) expect(html).toMatch(/]*name="name"[^>]*maxlength="30"/) // describedby via help expect(html).toMatch(/