import assert from 'node:assert/strict'; import fs from 'node:fs'; import test from 'node:test'; import { formAPreviewEnabled } from '../src/utils/form-integration.ts'; const read = (file) => fs.readFileSync(file, 'utf8'); test('Form A preview is explicit and has no live destination in source', () => { const source = read('src/components/FormAPreview.astro'); assert.match(source, /data-form-a-preview/); assert.match(source, /type="button"/); assert.match(source, /submitText/); assert.match(source, /text\.internalPreview/); assert.match(source, /dataset\.emailRequired/); assert.match(source, /border: 2px solid var\(--color-accent/); assert.doesNotMatch(source, /jotform\.com|api\.azinstitute4autism\.com|fetch\(/i); assert.equal(formAPreviewEnabled('true', 'false', 'mock'), true); assert.equal(formAPreviewEnabled('true', 'true', 'mock'), false); }); test('Form A preview placements are explicit and compact previews omit message cautions', () => { const contact = read('src/components/pages/ContactPage.astro'); const contactForm = read('src/components/ContactForm.astro'); const campaign = read('src/components/campaign/ConsultationForm.astro'); const preview = read('src/components/FormAPreview.astro'); const messages = read('src/utils/form-messages.ts'); const early = read('src/components/campaign/EarlyInterventionPage.astro'); assert.match(contact, /FormAPreview/); assert.match(contact, /submitText=\{lang === 'es' \? 'Enviar' : 'Submit'\}/); assert.match(campaign, /FormAPreview/); assert.match(campaign, /submitText=\{buttonText\}/); assert.doesNotMatch(early, /FormAPreview/); assert.doesNotMatch(preview, /name="inquiryType"/); assert.match(preview, /variant === 'full'.*form-a-preview__caution/s); assert.match(contactForm, /textarea[^>]+aria-describedby="contact-sensitive-note"/); assert.match(contactForm, /text\.formAPreview\.caution/); assert.match(messages, /Preview only — nothing is submitted/); assert.match(messages, /Vista previa para reunión interna/); assert.doesNotMatch(campaign, /detailed medical|diagnostic|insurance-member/i); assert.doesNotMatch(early, /(?:online )?(?:forms?|requests?|submissions?) (?:are |is )?(?:unavailable|not enabled)|detailed medical|diagnostic|insurance-member/i); }); test('default environment keeps the preview disabled', () => { assert.match(read('.env.example'), /PUBLIC_AIA_FORM_A_PREVIEW=false/); assert.equal(formAPreviewEnabled('false', 'false', 'off'), false); }); test('Jotform handoff preserves AIA form tokens and accessible native controls', () => { const css = read('integrations/jotform/aia-form-a.css'); const guide = read('integrations/jotform/README.md'); for (const value of ['#ffbd59', '#ff914d', '#254080', '#fcf9f5', '#edeef3']) assert.match(css, new RegExp(value)); assert.match(css, /\.form-all \.form-submit-button/); assert.match(css, /\.form-all button\[type="submit"\]/); assert.match(css, /:focus-visible/); assert.doesNotMatch(css, /https?:\/\/|@import|url\(/i); assert.match(guide, /formContext/); assert.match(guide, /multiple native Jotform Submit buttons/i); assert.match(guide, /honeypot/i); assert.match(guide, /cross-origin iframe/i); });