feat(forms): add Form A iframe fallback safeguards

This commit is contained in:
DeCentN2Madness committed 2026-10-28 18:29:32 -07:00
1 parent 7cdf209032
commit 1a56cd7603
10 files changed
+299 -59

No files matched your search

+16 -5
View File
@@ -37,6 +37,12 @@ test('Form A iframe uses only fixed, approved route parameters', () => {
buildFormAIframeUrl('en', 'landing'),
'https://form.jotform.com/262946078314059?formContext=landing&language=en',
);
const english = resolveFormAIframe(isolated());
const spanish = resolveFormAIframe(isolated({ route: '/es/contact', locale: 'es' }));
assert.equal(english.fallbackText, 'If the embedded form does not load,');
assert.equal(english.fallbackLinkText, 'open the form in a new tab.');
assert.equal(spanish.fallbackText, 'Si el formulario integrado no se carga,');
assert.equal(spanish.fallbackLinkText, 'abra el formulario en una pestaña nueva.');
assert.deepEqual(formAIframePlacements.map((placement) => placement.route), [
'/contact',
'/es/contact',
@@ -56,6 +62,8 @@ test('Form A iframe requires every isolated-test gate and refuses live mode', ()
assert.equal(resolveFormAIframe(isolated({ rawMode: undefined })).reason, 'mode-not-isolated-test');
assert.equal(resolveFormAIframe(isolated({ rawMode: 'mock' })).reason, 'mode-not-isolated-test');
assert.equal(resolveFormAIframe(isolated({ rawMode: 'live', liveApproved: 'true' })).reason, 'mode-not-isolated-test');
assert.equal(resolveFormAIframe(isolated({ liveApproved: undefined })).reason, 'live-approval-not-disabled');
assert.equal(resolveFormAIframe(isolated({ liveApproved: 'true' })).reason, 'live-approval-not-disabled');
assert.equal(resolveFormAIframe(isolated({ isolatedTestApproved: 'false' })).reason, 'isolated-test-not-approved');
assert.equal(resolveFormAIframe(isolated({ environmentRole: 'staging' })).reason, 'invalid-environment-role');
assert.equal(resolveFormAIframe(isolated({ allowIndexing: 'true' })).reason, 'indexing-enabled');
@@ -90,10 +98,13 @@ test('Only the seven allowlisted placements can render the adapter, with no help
assert.match(earlyIntervention, /JotformIframe/);
assert.match(adapter, /referrerpolicy="no-referrer"/);
assert.match(adapter, /sandbox="allow-forms allow-scripts allow-same-origin"/);
assert.match(adapter, /const fallbackMarkup = `<p class="jotform-iframe__fallback">/);
assert.match(adapter, /set:html=\{fallbackMarkup\}/);
assert.match(adapter, /escapeHtml\(config\.url\)/);
assert.doesNotMatch(adapter, /<\/h3>\s*(?:\{description[^\n]*\}\s*)?<p class="jotform-iframe__fallback">/);
assert.match(adapter, /data-jotform-iframe-frame/);
assert.match(adapter, /data-jotform-iframe-fallback hidden aria-live="polite" role="status"/);
assert.match(adapter, /<noscript>/);
assert.match(adapter, /fallbackTimeoutMs = 15_000/);
assert.match(adapter, /frame\.addEventListener\('load', onLoad, \{ once: true \}\)/);
assert.match(adapter, /document\.addEventListener\('astro:before-swap', dispose, \{ once: true \}\)/);
assert.doesNotMatch(adapter, /set:html=|fallbackMarkup|escapeHtml\(/);
assert.match(adapter, /target="_blank" rel="noopener noreferrer"/);
assert.match(adapter, /--jotform-frame-height: 60rem/);
assert.match(adapter, /max-width: none;/);
@@ -101,7 +112,7 @@ test('Only the seven allowlisted placements can render the adapter, with no help
assert.match(adapter, /\.jotform-iframe--embedded \{\s*--jotform-frame-height: 42rem/);
assert.match(adapter, /\.jotform-iframe__frame \{\s*height: 68rem/);
assert.match(adapter, /\.jotform-iframe--embedded \.jotform-iframe__frame \{\s*height: 50rem/);
assert.doesNotMatch(adapter, /<script|onload=|postMessage|fetch\(|form\.submit|analytics|googletag/i);
assert.doesNotMatch(adapter, /for-form-embed-handler|jotformEmbedHandler|onload=|postMessage|fetch\(|form\.submit|analytics|googletag/i);
assert.doesNotMatch(campaign, /262946078314059/);
});