Compare commits

..

1 Commits

Author SHA1 Message Date
jaybe 033519f973 Export 회귀: 폼 required/pattern/maxlength + describedby 검증 추가, :invalid 에러 스타일 포함
Auto PR / open-pr (push) Successful in 16s
Auto Label PR / add-automerge-label (pull_request) Successful in 7s
CI / test (pull_request) Failing after 1m55s
2025-11-17 21:19:01 +09:00
2 changed files with 53 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import { describe, it, expect } from 'vitest'
import { exportPage } from '@/lib/exporter/html'
import type { Page } from '@/lib/schema/page'
const makePage = (overrides: Partial<Page> = {}): 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(/<input[^>]*name="name"[^>]*required/)
expect(html).toMatch(/<input[^>]*name="name"[^>]*pattern="\^\[A-Za-z \]\+\$"/)
expect(html).toMatch(/<input[^>]*name="name"[^>]*maxlength="30"/)
// describedby via help
expect(html).toMatch(/<label for="field-name">Name<\/label>/)
expect(html).toMatch(/<input[^>]*id="field-name"[^>]*aria-describedby="field-name-help"/)
expect(html).toMatch(/<div id="field-name-help" class="form-help">Enter your name<\/div>/)
// email required + describedby
expect(html).toMatch(/<input[^>]*type="email"[^>]*name="email"[^>]*required/)
expect(html).toMatch(/<input[^>]*id="field-email"[^>]*aria-describedby="field-email-help"/)
// textarea maxlength + describedby
expect(html).toMatch(/<textarea[^>]*name="msg"[^>]*maxlength="200"/)
expect(html).toMatch(/<textarea[^>]*id="field-msg"[^>]*aria-describedby="field-msg-help"/)
})
it('CSS includes :invalid rule for error state', () => {
const page = makePage()
const { css } = exportPage(page)
expect(css).toMatch(/input:invalid,select:invalid,textarea:invalid\{[^}]*border-color/)
})
})
+1
View File
@@ -314,6 +314,7 @@ function buildCss(page: Page) {
label{ display:block; margin: .5rem 0 }
button{ background: var(--primary); color:#fff; border:none; padding:.75rem 1rem; border-radius:.5rem }
button:focus, a:focus, input:focus, select:focus, textarea:focus{ outline: 3px solid #2563eb; outline-offset:2px }
input:invalid,select:invalid,textarea:invalid{ border-color:#ef4444 }
.faq-list{ list-style:none; padding:0; margin:0 }
.faq-item{ margin: .75rem 0 }
.faq-q{ font-size: 1rem; font-weight:600; overflow-wrap:anywhere }