refactor(forms): enable approved Form A placements by default
This commit is contained in:
41 files changed
+862
-523
No files matched your search
@@ -1,167 +1,67 @@
|
||||
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';
|
||||
import { buildFormAIframeUrl, 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 expected = [
|
||||
['/contact', 'en', 'contact'], ['/es/contact', 'es', 'contact'],
|
||||
...['aba-therapy','aba-insurance','aba-ahcccs','aba-private-pay','early-intervention'].map(s => ['/lp/' + s, 'en', 'landing']),
|
||||
['/client-consultation', 'en', 'consultation'], ['/es/client-consultation', 'es', 'consultation'], ['/schedule-consultation', 'en', 'consultation'],
|
||||
...['en','es'].flatMap(lang => ['aba-therapy','autism-evaluations','learner-social-club'].map(s => [(lang === 'es' ? '/es/' : '/') + s, lang, 'consultation'])),
|
||||
];
|
||||
|
||||
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', () => {
|
||||
test('default and explicit live enable exactly sixteen fixed route/locale/context placements', () => {
|
||||
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.deepEqual(formAIframePlacements.map(p => [p.route,p.locale,p.context]), expected);
|
||||
assert.equal(new Set(formAIframePlacements.map(p => p.route)).size, 16);
|
||||
for (const rawMode of [undefined, '', ' ', 'live', 'LIVE']) for (const [route, locale, context] of expected) {
|
||||
const config = resolveFormAIframe({ rawMode, route, locale });
|
||||
assert.equal(config.enabled, true, route);
|
||||
assert.equal(config.context, context);
|
||||
assert.equal(config.mode, 'live');
|
||||
assert.equal(config.url, `https://form.jotform.com/262946078314059?formContext=${context}&language=${locale}`);
|
||||
assert.equal(formModeForRuntime(resolveFormMode(rawMode)), 'off', 'native surfaces remain inactive');
|
||||
}
|
||||
|
||||
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');
|
||||
for (const value of [undefined, '', 'invalid']) assert.equal(resolveFormAIframe(consultation({ allowIndexing: value })).enabled, false);
|
||||
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', () => {
|
||||
test('invalid and obsolete mode values fail clearly instead of silently disabling forms', () => {
|
||||
for (const rawMode of ['isolated-test', 'production', 'invalid', 'false']) {
|
||||
assert.throws(() => resolveFormMode(rawMode), /PUBLIC_AIA_FORMS_MODE.*Remove.*live, off, or mock/);
|
||||
assert.throws(() => resolveFormAIframe({ rawMode, route: '/contact', locale: 'en' }), /PUBLIC_AIA_FORMS_MODE/);
|
||||
}
|
||||
});
|
||||
|
||||
test('off and mock reject real frames on every approved placement', () => {
|
||||
for (const rawMode of ['off', 'mock']) for (const [route, locale] of expected) {
|
||||
const config = resolveFormAIframe({ rawMode, route, locale });
|
||||
assert.equal(config.enabled, false);
|
||||
assert.equal(config.url, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
test('registry rejects unknown routes, mismatched locales and arbitrary URL parameters', () => {
|
||||
for (const route of ['/referrals', '/tour', '/ar/contact', '/contact/', '/contact?formContext=landing', 'https://evil.invalid']) {
|
||||
assert.equal(resolveFormAIframe({ rawMode: undefined, route, locale: 'en' }).reason, 'route-not-authorized');
|
||||
}
|
||||
for (const [route, locale] of expected) {
|
||||
assert.equal(resolveFormAIframe({ rawMode: undefined, route, locale: locale === 'en' ? 'es' : 'en' }).reason, 'locale-not-authorized');
|
||||
}
|
||||
assert.throws(() => buildFormAIframeUrl('ar', 'contact'), /Unsupported/);
|
||||
assert.throws(() => buildFormAIframeUrl('en', 'untrusted'), /Unsupported/);
|
||||
});
|
||||
|
||||
test('EN/ES consultation and contact titles/fallbacks remain localized', () => {
|
||||
const en = resolveFormAIframe({ rawMode: undefined, route: '/client-consultation', locale: 'en' });
|
||||
const es = resolveFormAIframe({ rawMode: undefined, route: '/es/client-consultation', locale: 'es' });
|
||||
assert.equal(en.title, 'AIA consultation form');
|
||||
assert.equal(es.title, 'Formulario de consulta de AIA');
|
||||
assert.equal(es.fallbackLinkText, 'abra el formulario de consulta en una pestaña nueva.');
|
||||
assert.equal(resolveFormAIframe({rawMode: undefined,route:'/es/contact',locale:'es'}).fallbackText,'Si el formulario integrado no se carga,');
|
||||
});
|
||||
|
||||
test('the shared adapter preserves layout, bilingual drawers, sandbox, fallback and dimensions', () => {
|
||||
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');
|
||||
@@ -173,11 +73,8 @@ test('the adapter preserves seven production routes and supports the separate bi
|
||||
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\.'/);
|
||||
@@ -186,14 +83,10 @@ test('the adapter preserves seven production routes and supports the separate bi
|
||||
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-consultation-test/);
|
||||
assert.match(drawer, /data-consultation-enabled/);
|
||||
assert.match(drawer, /serviceCopy.heading/);
|
||||
assert.match(drawer, /deferUntilActivated/);
|
||||
assert.match(fs.readFileSync('src/scripts/service-inquiry.ts', 'utf8'), /aia:jotform-activate/);
|
||||
@@ -203,7 +96,6 @@ test('the adapter preserves seven production routes and supports the separate bi
|
||||
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/);
|
||||
|
||||
Reference in new issue
Block a user