Files
aia-website/www/tools/jotform-form-a.test.mjs
T

132 lines
7.0 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import test from 'node:test';
import {
buildFormAIframeUrl,
formAIframeId,
formAIframeOrigin,
formAIframePlacements,
formModeForRuntime,
resolveFormAIframe,
resolveFormMode,
} from '../src/utils/form-integration.ts';
const isolated = (overrides = {}) => ({
rawMode: 'isolated-test',
liveApproved: 'false',
isolatedTestApproved: 'true',
environmentRole: 'isolated-test',
allowIndexing: 'false',
route: '/contact',
locale: 'en',
...overrides,
});
test('Form A iframe uses only fixed, approved route parameters', () => {
assert.equal(formAIframeOrigin, 'https://form.jotform.com');
assert.equal(formAIframeId, '262946078314059');
assert.equal(
buildFormAIframeUrl('en', 'contact'),
'https://form.jotform.com/262946078314059?formContext=contact&language=en',
);
assert.equal(
buildFormAIframeUrl('es', 'contact'),
'https://form.jotform.com/262946078314059?formContext=contact&language=es',
);
assert.equal(
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',
'/lp/aba-therapy',
'/lp/aba-insurance',
'/lp/aba-ahcccs',
'/lp/aba-private-pay',
'/lp/early-intervention',
]);
});
test('Form A iframe requires every isolated-test gate and refuses live mode', () => {
const enabled = resolveFormAIframe(isolated());
assert.equal(enabled.enabled, true);
assert.equal(enabled.reason, 'enabled');
assert.equal(enabled.title, 'AIA general enquiries form');
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');
assert.equal(resolveFormAIframe(isolated({ route: '/lp/early-intervention' })).url, 'https://form.jotform.com/262946078314059?formContext=landing&language=en');
assert.equal(resolveFormAIframe(isolated({ route: '/es/contact', locale: 'en' })).reason, 'locale-not-authorized');
assert.equal(resolveFormAIframe(isolated({ route: '/es/contact', locale: 'es' })).url, 'https://form.jotform.com/262946078314059?formContext=contact&language=es');
const campaign = resolveFormAIframe(isolated({ route: '/lp/aba-therapy' }));
assert.equal(campaign.url, 'https://form.jotform.com/262946078314059?formContext=landing&language=en');
assert.equal(campaign.context, 'landing');
assert.equal(formModeForRuntime(resolveFormMode('isolated-test', undefined)), 'off');
assert.equal(formModeForRuntime(resolveFormMode('live', 'true')), 'off');
});
test('Only the seven allowlisted placements can render the adapter, with no helper, tracking, or parent submission code', () => {
const contact = fs.readFileSync('src/components/pages/ContactPage.astro', 'utf8');
const adapter = fs.readFileSync('src/components/JotformIframe.astro', 'utf8');
const campaign = fs.readFileSync('src/components/campaign/ConsultationForm.astro', 'utf8');
const earlyIntervention = fs.readFileSync('src/components/campaign/EarlyInterventionPage.astro', 'utf8');
assert.match(contact, /resolveFormAIframe/);
assert.match(contact, /route = lang === 'es' \? '\/es\/contact' : '\/contact'/);
assert.match(contact, /JotformIframe/);
assert.match(campaign, /resolveFormAIframe/);
assert.match(campaign, /JotformIframe/);
assert.match(campaign, /variant="embedded"/);
assert.match(campaign, /\/lp\/aba-therapy/);
assert.match(campaign, /const iframeDescription = 'Use this form to request a conversation\. An AIA team member can explain the next steps for your family\.'/);
assert.match(campaign, /description=\{iframeDescription\}/);
assert.doesNotMatch(campaign, /description=\{intro\}/);
assert.match(earlyIntervention, /resolveFormAIframe/);
assert.match(earlyIntervention, /route: '\/lp\/early-intervention'/);
assert.match(earlyIntervention, /JotformIframe/);
assert.match(adapter, /referrerpolicy="no-referrer"/);
assert.match(adapter, /sandbox="allow-forms allow-scripts allow-same-origin"/);
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;/);
assert.match(adapter, /width: 100%;/);
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, /for-form-embed-handler|jotformEmbedHandler|onload=|postMessage|fetch\(|form\.submit|analytics|googletag/i);
assert.doesNotMatch(campaign, /262946078314059/);
});
test('Jotform Builder CSS retains the owner-reconciled theme overrides without external assets', () => {
const css = fs.readFileSync('integrations/jotform/aia-form-a.css', 'utf8');
for (const declaration of [
'background: #fcf9f5 !important',
'border: 1px solid #edeef3 !important',
'background: #ffbd59 !important',
'border: 2px solid #ffbd59 !important',
'border-color: #ff914d !important',
'color: #254080 !important',
]) assert.match(css, new RegExp(declaration.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')));
assert.match(css, /:focus-visible/);
assert.doesNotMatch(css, /https?:\/\/|@import|url\(/i);
});