242 lines
13 KiB
JavaScript
242 lines
13 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import test from 'node:test';
|
|
import {
|
|
buildFormAIframeUrl,
|
|
formAConsultationTestPlacements,
|
|
formAIframeId,
|
|
formAIframeOrigin,
|
|
formAIframePlacements,
|
|
formModeForRuntime,
|
|
resolveFormAIframe,
|
|
resolveFormMode,
|
|
} from '../src/utils/form-integration.ts';
|
|
|
|
const isolated = (overrides = {}) => ({
|
|
rawMode: 'isolated-test',
|
|
liveApproved: 'false',
|
|
isolatedTestApproved: 'true',
|
|
consultationTestApproved: 'false',
|
|
productionApproved: 'false',
|
|
environmentRole: 'isolated-test',
|
|
allowIndexing: 'false',
|
|
route: '/contact',
|
|
locale: 'en',
|
|
...overrides,
|
|
});
|
|
|
|
const consultation = (overrides = {}) => isolated({
|
|
consultationTestApproved: 'true',
|
|
route: '/client-consultation',
|
|
locale: 'en',
|
|
...overrides,
|
|
});
|
|
|
|
const production = (overrides = {}) => ({
|
|
rawMode: 'live',
|
|
liveApproved: 'true',
|
|
isolatedTestApproved: 'false',
|
|
consultationTestApproved: 'true',
|
|
productionApproved: 'true',
|
|
environmentRole: 'production',
|
|
allowIndexing: 'true',
|
|
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',
|
|
);
|
|
assert.equal(
|
|
buildFormAIframeUrl('es', 'consultation'),
|
|
'https://form.jotform.com/262946078314059?formContext=consultation&language=es',
|
|
);
|
|
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',
|
|
]);
|
|
assert.deepEqual(formAConsultationTestPlacements.map((placement) => placement.route), [
|
|
'/client-consultation',
|
|
'/es/client-consultation',
|
|
'/schedule-consultation',
|
|
'/aba-therapy',
|
|
'/autism-evaluations',
|
|
'/learner-social-club',
|
|
'/es/aba-therapy',
|
|
'/es/autism-evaluations',
|
|
'/es/learner-social-club',
|
|
]);
|
|
});
|
|
|
|
test('Form A iframe requires every isolated-test or production approval gate', () => {
|
|
const enabled = resolveFormAIframe(isolated());
|
|
assert.equal(enabled.enabled, true);
|
|
assert.equal(enabled.reason, 'enabled');
|
|
assert.equal(enabled.title, 'AIA general enquiries form');
|
|
assert.equal(enabled.mode, 'isolated-test');
|
|
assert.equal(enabled.environmentRole, 'isolated-test');
|
|
assert.equal(resolveFormAIframe(isolated({ rawMode: undefined })).reason, 'mode-not-authorized');
|
|
assert.equal(resolveFormAIframe(isolated({ rawMode: 'mock' })).reason, 'mode-not-authorized');
|
|
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');
|
|
const live = resolveFormAIframe(production());
|
|
assert.equal(live.enabled, true);
|
|
assert.equal(live.mode, 'live');
|
|
assert.equal(live.environmentRole, 'production');
|
|
assert.equal(live.url, 'https://form.jotform.com/262946078314059?formContext=contact&language=en');
|
|
assert.equal(resolveFormAIframe(production({ productionApproved: undefined })).reason, 'production-approval-not-granted');
|
|
assert.equal(resolveFormAIframe(production({ productionApproved: 'false' })).reason, 'production-approval-not-granted');
|
|
assert.equal(resolveFormAIframe(production({ environmentRole: 'isolated-test' })).reason, 'invalid-environment-role');
|
|
assert.equal(resolveFormAIframe(production({ liveApproved: 'false' })).reason, 'mode-not-authorized');
|
|
assert.equal(resolveFormAIframe(production({ rawMode: 'off' })).reason, 'mode-not-authorized');
|
|
assert.equal(resolveFormAIframe(production({ route: '/referrals' })).reason, 'route-not-authorized');
|
|
assert.equal(resolveFormAIframe(production({ route: '/es/contact', locale: 'es' })).url, 'https://form.jotform.com/262946078314059?formContext=contact&language=es');
|
|
assert.equal(formModeForRuntime(resolveFormMode('isolated-test', undefined)), 'off');
|
|
assert.equal(formModeForRuntime(resolveFormMode('live', 'true')), 'off');
|
|
});
|
|
|
|
test('consultation is isolated-test-only and requires its additional explicit approval', () => {
|
|
const enabled = resolveFormAIframe(consultation());
|
|
assert.equal(enabled.enabled, true);
|
|
assert.equal(enabled.context, 'consultation');
|
|
assert.equal(enabled.title, 'AIA consultation form');
|
|
assert.equal(enabled.url, 'https://form.jotform.com/262946078314059?formContext=consultation&language=en');
|
|
|
|
const spanish = resolveFormAIframe(consultation({ route: '/es/client-consultation', locale: 'es' }));
|
|
assert.equal(spanish.enabled, true);
|
|
assert.equal(spanish.title, 'Formulario de consulta de AIA');
|
|
assert.equal(spanish.url, 'https://form.jotform.com/262946078314059?formContext=consultation&language=es');
|
|
|
|
for (const placement of formAConsultationTestPlacements) {
|
|
const config = resolveFormAIframe(consultation({ route: placement.route, locale: placement.locale }));
|
|
assert.equal(config.enabled, true, placement.route);
|
|
assert.equal(config.context, 'consultation', placement.route);
|
|
assert.equal(config.url, buildFormAIframeUrl(placement.locale, 'consultation'), placement.route);
|
|
}
|
|
|
|
assert.equal(resolveFormAIframe(isolated({ route: '/client-consultation' })).reason, 'consultation-test-not-approved');
|
|
assert.equal(resolveFormAIframe(consultation({ consultationTestApproved: undefined })).reason, 'consultation-test-not-approved');
|
|
assert.equal(resolveFormAIframe(consultation({ consultationTestApproved: 'yes' })).reason, 'consultation-test-not-approved');
|
|
assert.equal(resolveFormAIframe(consultation({ rawMode: 'mock' })).reason, 'mode-not-authorized');
|
|
assert.equal(resolveFormAIframe(consultation({ liveApproved: 'true' })).reason, 'live-approval-not-disabled');
|
|
assert.equal(resolveFormAIframe(consultation({ isolatedTestApproved: 'false' })).reason, 'isolated-test-not-approved');
|
|
assert.equal(resolveFormAIframe(consultation({ environmentRole: 'staging' })).reason, 'invalid-environment-role');
|
|
assert.equal(resolveFormAIframe(consultation({ allowIndexing: 'true' })).reason, 'indexing-enabled');
|
|
assert.equal(resolveFormAIframe(consultation({ route: '/es/aba-therapy', locale: 'en' })).reason, 'locale-not-authorized');
|
|
assert.equal(resolveFormAIframe(production({ route: '/client-consultation' })).reason, 'route-not-authorized');
|
|
assert.equal(resolveFormAIframe(production({ route: '/client-consultation', consultationTestApproved: 'true' })).reason, 'route-not-authorized');
|
|
});
|
|
|
|
test('the adapter preserves seven production routes and supports the separate bilingual consultation test surface', () => {
|
|
const contact = fs.readFileSync('src/components/pages/ContactPage.astro', 'utf8');
|
|
const adapter = fs.readFileSync('src/components/JotformIframe.astro', 'utf8');
|
|
const shell = fs.readFileSync('src/components/FormShell.astro', 'utf8');
|
|
const drawer = fs.readFileSync('src/components/ServiceInquiryDrawer.astro', 'utf8');
|
|
const layout = fs.readFileSync('src/layouts/PageLayout.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(contact, /PUBLIC_AIA_FORM_A_PRODUCTION_APPROVED/);
|
|
assert.match(contact, /PUBLIC_AIA_FORMS_CONSULTATION_TEST_APPROVED/);
|
|
assert.match(campaign, /resolveFormAIframe/);
|
|
assert.match(campaign, /JotformIframe/);
|
|
assert.match(campaign, /PUBLIC_AIA_FORM_A_PRODUCTION_APPROVED/);
|
|
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(earlyIntervention, /PUBLIC_AIA_FORM_A_PRODUCTION_APPROVED/);
|
|
assert.match(earlyIntervention, /PUBLIC_AIA_FORMS_CONSULTATION_TEST_APPROVED/);
|
|
assert.match(campaign, /PUBLIC_AIA_FORMS_CONSULTATION_TEST_APPROVED/);
|
|
assert.match(shell, /resolveFormAIframe/);
|
|
assert.match(shell, /PUBLIC_AIA_FORMS_CONSULTATION_TEST_APPROVED/);
|
|
assert.match(shell, /JotformIframe/);
|
|
assert.match(drawer, /lang: SupportedLocale/);
|
|
assert.match(drawer, /data-service-inquiry-open/);
|
|
assert.match(drawer, /data-explicit-activation/);
|
|
assert.match(drawer, /deferUntilActivated/);
|
|
assert.match(drawer, /aia:jotform-activate/);
|
|
assert.match(drawer, /Cerrar el formulario de consulta/);
|
|
assert.doesNotMatch(drawer, /No WAITLIST!|guarantee your child|now open for enrollment/i);
|
|
assert.match(layout, /entry\.data\.lang === 'en' \|\| entry\.data\.lang === 'es'/);
|
|
assert.match(adapter, /referrerpolicy="no-referrer"/);
|
|
assert.match(adapter, /sandbox="allow-forms allow-scripts allow-same-origin"/);
|
|
assert.match(adapter, /data-form-mode=\{config\.mode\}/);
|
|
assert.match(adapter, /data-form-environment=\{config\.environmentRole\}/);
|
|
assert.match(adapter, /data-jotform-iframe-frame/);
|
|
assert.match(adapter, /data-jotform-iframe-url/);
|
|
assert.match(adapter, /data-jotform-deferred/);
|
|
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.match(adapter, /container\.addEventListener\('aia:jotform-activate'/);
|
|
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.match(adapter, /\.jotform-iframe--drawer \{\s*--jotform-frame-height: 72rem/);
|
|
assert.match(adapter, /\.jotform-iframe--drawer \.jotform-iframe__frame \{\s*height: 82rem/);
|
|
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);
|
|
});
|