diff --git a/craft/src/components/forms/ContactForm.toHtml.test.ts b/craft/src/components/forms/ContactForm.toHtml.test.ts new file mode 100644 index 0000000..d79c413 --- /dev/null +++ b/craft/src/components/forms/ContactForm.toHtml.test.ts @@ -0,0 +1,24 @@ +import { describe, test, expect } from 'vitest'; +import { ContactForm } from './ContactForm'; + +const toHtml = (ContactForm as any).toHtml; + +describe('ContactForm.toHtml relay wiring', () => { + test('with recipientEmail: emits marker, placeholder action, honeypot', () => { + const { html } = toHtml({ recipientEmail: 'a@b.com', thankYouUrl: '/thx', fields: [] }, ''); + expect(html).toMatch(//); + expect(html).toMatch(/action="__WHP_FORM_ACTION__F[0-9a-z]+__"/); + expect(html).toContain('method="POST"'); + expect(html).toContain('name="_gotcha"'); + // marker id and action id match + const mid = html.match(/id="(F[0-9a-z]+)"/)![1]; + expect(html).toContain(`__WHP_FORM_ACTION__${mid}__`); + }); + + test('without recipientEmail: no marker, falls back to formAction', () => { + const { html } = toHtml({ formAction: '/legacy', fields: [] }, ''); + expect(html).not.toContain('WHP-FORM'); + expect(html).toContain('action="/legacy"'); + expect(html).not.toContain('_gotcha'); + }); +}); diff --git a/craft/src/components/forms/ContactForm.tsx b/craft/src/components/forms/ContactForm.tsx index a813e01..0955cd9 100644 --- a/craft/src/components/forms/ContactForm.tsx +++ b/craft/src/components/forms/ContactForm.tsx @@ -21,6 +21,8 @@ interface ContactFormProps { labelColor?: string; inputBg?: string; inputBorder?: string; + recipientEmail?: string; + thankYouUrl?: string; } const defaultFields: ContactFormField[] = [ @@ -187,6 +189,23 @@ const ContactFormSettings: React.FC = () => { /> + {/* Relay recipient */} +
+ Delivered via the site's contact-form relay. Requires the relay to be enabled on this server. +
+