mirror of
https://github.com/corazoncp/corazoncp-landing.git
synced 2026-12-01 12:30:31 +00:00
- vite.config.ts: register kundalini, volverATi, and descargo HTML entrypoints in Rollup multi-page build inputs so all routes emit into dist/. - kundalini/index.html: add the Kundalini Yoga hub page presenting Seva Surpreet Kaur's pathways (Volver a ti and group classes) with SEO/OG metadata. - volver-a-ti/index.html: add the Volver a ti personalized Kundalini Yoga program page with enrollment links gated by disclaimer acceptance. - src/scripts/volver-a-ti.js: implement the disclaimer acceptance gate using aria-disabled, BFCache pageshow synchronization, and accessible status/focus feedback before enrollment. - descargo/index.html: add the participation conditions and liability disclaimer page referenced by the Volver a ti enrollment gate. - tests/kundalini-routes.test.js: add route, metadata, contact invariant, and disclaimer gate behavioral tests covering all new pages.
773 lines
27 KiB
JavaScript
773 lines
27 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
import { pathToFileURL } from 'node:url';
|
|
|
|
const volverScriptUrl = pathToFileURL(path.resolve('src/scripts/volver-a-ti.js')).href;
|
|
const distDir = path.resolve('dist');
|
|
const distAssetsDir = path.resolve('dist/assets');
|
|
|
|
const ALLOWED_EMAIL = 'contactocorazoncp@gmail.com';
|
|
const ALLOWED_PHONE_DIGITS = '573215428972';
|
|
const EXPECTED_GATE_STATUS = 'Por favor marca la casilla de aceptación antes de continuar.';
|
|
const EXPECTED_ZELLE_ACCEPT_TEXT =
|
|
'he leído y acepto las condiciones de participación y el descargo de responsabilidad';
|
|
|
|
const ROUTE_SPECS = [
|
|
{
|
|
route: '/',
|
|
file: 'index.html',
|
|
title: 'El Corazón como Portal — Acompañamiento Consciente en Valledupar',
|
|
description:
|
|
'Sal del automático. Abre tu corazón, recupera tu soberanía. Barras de Access®, Procesos de Cuerpo y Mentorías de Consciencia en Valledupar.',
|
|
canonical: 'https://elcorazoncomoportal.com/',
|
|
ogImage: 'https://elcorazoncomoportal.com/img/azu-hero.jpg',
|
|
ogImageWidth: '529',
|
|
ogImageHeight: '530',
|
|
ogImageAlt: 'Azucena Sánchez, facilitadora de El Corazón como Portal',
|
|
expectedHeaderCurrentHref: '/',
|
|
},
|
|
{
|
|
route: '/kundalini/',
|
|
file: 'kundalini/index.html',
|
|
title: 'Kundalini Yoga — El Corazón como Portal',
|
|
description:
|
|
'Explora los caminos de Kundalini Yoga con Seva Surpreet Kaur: acompañamiento personalizado Volver a ti y clases grupales.',
|
|
canonical: 'https://elcorazoncomoportal.com/kundalini/',
|
|
ogImage: 'https://elcorazoncomoportal.com/img/og-kundalini.jpg',
|
|
ogImageWidth: '1200',
|
|
ogImageHeight: '630',
|
|
ogImageAlt: 'Práctica de Kundalini Yoga con Seva Surpreet Kaur',
|
|
expectedHeaderCurrentHref: '/kundalini/',
|
|
},
|
|
{
|
|
route: '/volver-a-ti/',
|
|
file: 'volver-a-ti/index.html',
|
|
title: 'Volver a ti — Acompañamiento Personalizado en Kundalini Yoga',
|
|
description:
|
|
'Volver a ti: acompañamiento personalizado de Kundalini Yoga para equilibrio físico, calma emocional y conexión interior.',
|
|
canonical: 'https://elcorazoncomoportal.com/volver-a-ti/',
|
|
ogImage: 'https://elcorazoncomoportal.com/img/og-kundalini.jpg',
|
|
ogImageWidth: '1200',
|
|
ogImageHeight: '630',
|
|
ogImageAlt: 'Volver a ti — Acompañamiento personalizado de Kundalini Yoga',
|
|
expectedHeaderCurrentHref: null,
|
|
},
|
|
{
|
|
route: '/descargo/',
|
|
file: 'descargo/index.html',
|
|
title: 'Condiciones de Participación y Descargo — El Corazón como Portal',
|
|
description:
|
|
'Condiciones de participación y descargo de responsabilidad del programa Volver a ti de El Corazón como Portal.',
|
|
canonical: 'https://elcorazoncomoportal.com/descargo/',
|
|
ogImage: 'https://elcorazoncomoportal.com/img/logo.png',
|
|
ogImageWidth: '150',
|
|
ogImageHeight: '150',
|
|
ogImageAlt: 'Emblema de El Corazón como Portal',
|
|
expectedHeaderCurrentHref: null,
|
|
},
|
|
];
|
|
|
|
function readBuiltRoute(relativeFile) {
|
|
const fullPath = path.join(distDir, relativeFile);
|
|
assert.ok(fs.existsSync(fullPath), `Expected built route dist/${relativeFile} to exist`);
|
|
return fs.readFileSync(fullPath, 'utf8');
|
|
}
|
|
|
|
function attrValue(tag, attrName) {
|
|
const match = tag.match(
|
|
new RegExp(`(?:^|\\s)${attrName}=(?:(?:"([^"]*)")|(?:'([^']*)')|([^\\s>]+))`, 'i'),
|
|
);
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
return match[1] ?? match[2] ?? match[3] ?? '';
|
|
}
|
|
|
|
function metaContent(html, attrName, attrVal) {
|
|
for (const match of html.matchAll(/<meta\b[^>]*>/gi)) {
|
|
const tag = match[0];
|
|
if (attrValue(tag, attrName) === attrVal) {
|
|
return attrValue(tag, 'content');
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function canonicalHref(html) {
|
|
for (const match of html.matchAll(/<link\b[^>]*>/gi)) {
|
|
const tag = match[0];
|
|
if (attrValue(tag, 'rel') === 'canonical') {
|
|
return attrValue(tag, 'href');
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function headerSection(html) {
|
|
const match = html.match(/<header\b[^>]*>[\s\S]*?<\/header>/i);
|
|
assert.ok(match, 'Expected <header> element in built HTML');
|
|
return match[0];
|
|
}
|
|
|
|
function sectionById(html, id) {
|
|
const pattern = new RegExp(
|
|
`<([a-z][a-z0-9]*)\\b[^>]*\\bid=(?:"${id}"|'${id}'|${id})[^>]*>[\\s\\S]*?<\\/\\1>`,
|
|
'i',
|
|
);
|
|
const match = html.match(pattern);
|
|
assert.ok(match, `Expected element with id="${id}" in built HTML`);
|
|
return match[0];
|
|
}
|
|
|
|
function anchorTags(html) {
|
|
return [...html.matchAll(/<a\b[^>]*>[\s\S]*?<\/a>/gi)].map((match) => match[0]);
|
|
}
|
|
|
|
function bundledModuleSources(html) {
|
|
return [...html.matchAll(/<script\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.filter((tag) => attrValue(tag, 'type') === 'module')
|
|
.map((tag) => attrValue(tag, 'src') ?? '')
|
|
.filter((src) => /(?:^|\/)assets\/[^"']+\.js(?:[?#].*)?$/i.test(src));
|
|
}
|
|
|
|
function collectBuiltTextFiles(dir) {
|
|
if (!fs.existsSync(dir)) {
|
|
return [];
|
|
}
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
const files = [];
|
|
for (const entry of entries) {
|
|
const fullPath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
files.push(...collectBuiltTextFiles(fullPath));
|
|
} else if (
|
|
entry.isFile() &&
|
|
(entry.name.endsWith('.html') ||
|
|
(entry.name.endsWith('.js') && !entry.name.endsWith('.js.map')))
|
|
) {
|
|
files.push(fullPath);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function createEmitter() {
|
|
const listeners = new Map();
|
|
return {
|
|
addEventListener(type, listener) {
|
|
if (!listeners.has(type)) {
|
|
listeners.set(type, []);
|
|
}
|
|
listeners.get(type).push(listener);
|
|
},
|
|
dispatch(type, event = {}) {
|
|
for (const listener of listeners.get(type) ?? []) {
|
|
listener(event);
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
function createLinkDouble(href, gated = false) {
|
|
const emitter = createEmitter();
|
|
const attributes = new Map([['href', href]]);
|
|
if (gated) {
|
|
attributes.set('data-disclaimer-gate', '');
|
|
}
|
|
return {
|
|
addEventListener: emitter.addEventListener,
|
|
dispatch: emitter.dispatch,
|
|
get href() {
|
|
return attributes.get('href') ?? '';
|
|
},
|
|
getAttribute(name) {
|
|
return attributes.get(name) ?? null;
|
|
},
|
|
setAttribute(name, value) {
|
|
attributes.set(name, String(value));
|
|
},
|
|
removeAttribute(name) {
|
|
attributes.delete(name);
|
|
},
|
|
hasAttribute(name) {
|
|
return attributes.has(name);
|
|
},
|
|
};
|
|
}
|
|
|
|
function createVolverDomDouble({
|
|
includeCheckbox = true,
|
|
includeStatus = true,
|
|
includeInscripcion = true,
|
|
initialChecked = false,
|
|
} = {}) {
|
|
const checkboxEmitter = createEmitter();
|
|
let focusCalls = 0;
|
|
const checkbox = includeCheckbox
|
|
? {
|
|
checked: initialChecked,
|
|
addEventListener: checkboxEmitter.addEventListener,
|
|
dispatch: checkboxEmitter.dispatch,
|
|
focus() {
|
|
focusCalls += 1;
|
|
},
|
|
get focusCalls() {
|
|
return focusCalls;
|
|
},
|
|
}
|
|
: null;
|
|
|
|
const status = includeStatus ? { textContent: '' } : null;
|
|
|
|
const zelleLink = createLinkDouble('https://wa.me/573215428972?text=Hola%20Azu', true);
|
|
const kofiLink = createLinkDouble('https://ko-fi.com/example', true);
|
|
const inquiryLink = createLinkDouble('https://wa.me/573215428972?text=Consulta', false);
|
|
const descargoLink = createLinkDouble('/descargo/', false);
|
|
|
|
const gatedLinks = [zelleLink, kofiLink];
|
|
|
|
const inscripcion = includeInscripcion
|
|
? {
|
|
querySelectorAll(selector) {
|
|
if (selector === 'a[data-disclaimer-gate]') {
|
|
return gatedLinks;
|
|
}
|
|
return [];
|
|
},
|
|
}
|
|
: null;
|
|
|
|
const documentEmitter = createEmitter();
|
|
const windowEmitter = createEmitter();
|
|
|
|
const documentDouble = {
|
|
// Why: Vite's modulepreload polyfill checks link.relList.supports('modulepreload')
|
|
// at top level when executing built bundles; returning true avoids MutationObserver.
|
|
createElement() {
|
|
return { relList: { supports: () => true } };
|
|
},
|
|
getElementById(id) {
|
|
if (id === 'accept-disclaimer') {
|
|
return checkbox;
|
|
}
|
|
if (id === 'disclaimer-status') {
|
|
return status;
|
|
}
|
|
if (id === 'inscripcion') {
|
|
return inscripcion;
|
|
}
|
|
return null;
|
|
},
|
|
querySelector() {
|
|
return null;
|
|
},
|
|
addEventListener: documentEmitter.addEventListener,
|
|
dispatch: documentEmitter.dispatch,
|
|
};
|
|
|
|
const windowDouble = {
|
|
location: { pathname: '/volver-a-ti/' },
|
|
addEventListener: windowEmitter.addEventListener,
|
|
dispatch: windowEmitter.dispatch,
|
|
};
|
|
|
|
return {
|
|
documentDouble,
|
|
windowDouble,
|
|
checkbox,
|
|
status,
|
|
zelleLink,
|
|
kofiLink,
|
|
inquiryLink,
|
|
descargoLink,
|
|
};
|
|
}
|
|
|
|
async function withVolverDomDouble(options, callback) {
|
|
const prevDocument = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
|
const prevWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
|
|
|
|
const env = createVolverDomDouble(options);
|
|
globalThis.document = env.documentDouble;
|
|
globalThis.window = env.windowDouble;
|
|
|
|
try {
|
|
await callback(env);
|
|
} finally {
|
|
for (const [key, descriptor] of [
|
|
['document', prevDocument],
|
|
['window', prevWindow],
|
|
]) {
|
|
if (descriptor) {
|
|
Object.defineProperty(globalThis, key, descriptor);
|
|
} else {
|
|
delete globalThis[key];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
test('Issue #6 built routes, metadata, navigation state, and page contracts', async (t) => {
|
|
for (const spec of ROUTE_SPECS) {
|
|
await t.test(`built route dist/${spec.file} exists on disk`, () => {
|
|
assert.ok(
|
|
fs.existsSync(path.join(distDir, spec.file)),
|
|
`Expected dist/${spec.file} to exist`,
|
|
);
|
|
});
|
|
|
|
await t.test(`route ${spec.route} defines exact SEO and Open Graph metadata`, () => {
|
|
const html = readBuiltRoute(spec.file);
|
|
const titleMatch = html.match(/<title>([\s\S]*?)<\/title>/i);
|
|
assert.ok(titleMatch, `Expected <title> in ${spec.file}`);
|
|
assert.equal(titleMatch[1].trim(), spec.title);
|
|
|
|
const description = metaContent(html, 'name', 'description');
|
|
assert.equal(description, spec.description);
|
|
assert.ok(
|
|
description.length <= 160,
|
|
`Expected description <= 160 chars on ${spec.route}, got ${description.length}`,
|
|
);
|
|
|
|
assert.equal(canonicalHref(html), spec.canonical);
|
|
assert.equal(metaContent(html, 'property', 'og:type'), 'website');
|
|
assert.equal(metaContent(html, 'property', 'og:locale'), 'es_CO');
|
|
assert.equal(metaContent(html, 'property', 'og:title'), spec.title);
|
|
assert.equal(metaContent(html, 'property', 'og:description'), spec.description);
|
|
assert.equal(metaContent(html, 'property', 'og:url'), spec.canonical);
|
|
assert.equal(metaContent(html, 'property', 'og:image'), spec.ogImage);
|
|
assert.equal(metaContent(html, 'property', 'og:image:width'), spec.ogImageWidth);
|
|
assert.equal(metaContent(html, 'property', 'og:image:height'), spec.ogImageHeight);
|
|
assert.equal(metaContent(html, 'property', 'og:image:alt'), spec.ogImageAlt);
|
|
});
|
|
|
|
await t.test(
|
|
`route ${spec.route} sets expected header aria-current="page" and strips data-nav-current`,
|
|
() => {
|
|
const html = readBuiltRoute(spec.file);
|
|
assert.equal(
|
|
/\bdata-nav-current\b/i.test(html),
|
|
false,
|
|
`Built ${spec.file} must strip data-nav-current`,
|
|
);
|
|
|
|
const header = headerSection(html);
|
|
const currentAnchors = anchorTags(header).filter(
|
|
(tag) => attrValue(tag, 'aria-current') === 'page',
|
|
);
|
|
|
|
if (spec.expectedHeaderCurrentHref === null) {
|
|
assert.equal(
|
|
currentAnchors.length,
|
|
0,
|
|
`Expected no aria-current="page" in header on ${spec.route}`,
|
|
);
|
|
} else {
|
|
assert.equal(
|
|
currentAnchors.length,
|
|
1,
|
|
`Expected exactly one aria-current="page" in header on ${spec.route}`,
|
|
);
|
|
assert.equal(attrValue(currentAnchors[0], 'href'), spec.expectedHeaderCurrentHref);
|
|
}
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
`route ${spec.route} loads external /assets/*.js module with zero inline scripts or event handlers`,
|
|
() => {
|
|
const html = readBuiltRoute(spec.file);
|
|
const scriptSources = bundledModuleSources(html);
|
|
assert.ok(
|
|
scriptSources.length > 0,
|
|
`Expected ${spec.file} to reference at least one external /assets/*.js module`,
|
|
);
|
|
for (const src of scriptSources) {
|
|
const cleanSrc = src.split(/[?#]/)[0].replace(/^\.?\//, '');
|
|
assert.ok(
|
|
cleanSrc.startsWith('assets/') && fs.existsSync(path.join(distDir, cleanSrc)),
|
|
`Expected bundled module ${src} to exist under dist/assets/`,
|
|
);
|
|
}
|
|
|
|
const inlineScripts = [...html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].filter(
|
|
(match) => !/\bsrc=/i.test(match[1]) || match[2].trim().length > 0,
|
|
);
|
|
assert.equal(
|
|
inlineScripts.length,
|
|
0,
|
|
`Expected zero inline <script> blocks on ${spec.route}`,
|
|
);
|
|
|
|
assert.equal(
|
|
/<[a-z][^>]*\son[a-z]+\s*=/i.test(html),
|
|
false,
|
|
`Expected zero inline on<event>= handlers on ${spec.route}`,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
await t.test('/kundalini/ Card 1 links to /volver-a-ti/', () => {
|
|
const html = readBuiltRoute('kundalini/index.html');
|
|
const linksToVolver = anchorTags(html).filter(
|
|
(tag) => attrValue(tag, 'href') === '/volver-a-ti/',
|
|
);
|
|
assert.ok(linksToVolver.length > 0, 'Expected /kundalini/ to link to /volver-a-ti/');
|
|
});
|
|
|
|
await t.test(
|
|
'/kundalini/ Card 2 has non-interactive Próximamente badge and ungated WhatsApp interest link',
|
|
() => {
|
|
const html = readBuiltRoute('kundalini/index.html');
|
|
assert.match(html, /Próximamente/, 'Expected Próximamente badge on /kundalini/');
|
|
|
|
const interactiveWithBadge = [...html.matchAll(/<(a|button)\b[^>]*>[\s\S]*?<\/\1>/gi)].filter(
|
|
(match) => /Próximamente/i.test(match[0]),
|
|
);
|
|
assert.equal(
|
|
interactiveWithBadge.length,
|
|
0,
|
|
'Próximamente badge must not be inside an <a> or <button>',
|
|
);
|
|
|
|
const waLinks = anchorTags(html).filter((tag) =>
|
|
(attrValue(tag, 'href') ?? '').startsWith('https://wa.me/573215428972'),
|
|
);
|
|
assert.ok(
|
|
waLinks.some((tag) => attrValue(tag, 'data-disclaimer-gate') === null),
|
|
'Expected ungated WhatsApp interest link on /kundalini/',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'/volver-a-ti/ hero image has fetchpriority="high", no loading="lazy", and explicit dimensions',
|
|
() => {
|
|
const html = readBuiltRoute('volver-a-ti/index.html');
|
|
const heroImgs = [...html.matchAll(/<img\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.filter((tag) => (attrValue(tag, 'src') ?? '').includes('volver-a-ti-hero.webp'));
|
|
|
|
assert.equal(heroImgs.length, 1, 'Expected exactly one volver-a-ti-hero.webp image');
|
|
const heroImg = heroImgs[0];
|
|
assert.equal(attrValue(heroImg, 'fetchpriority'), 'high');
|
|
assert.notEqual(attrValue(heroImg, 'loading'), 'lazy');
|
|
assert.ok(attrValue(heroImg, 'width'), 'Hero image must declare explicit width');
|
|
assert.ok(attrValue(heroImg, 'height'), 'Hero image must declare explicit height');
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'/volver-a-ti/ below-the-fold volver-a-ti-*.webp images have loading="lazy" and explicit dimensions',
|
|
() => {
|
|
const html = readBuiltRoute('volver-a-ti/index.html');
|
|
const belowFoldImgs = [...html.matchAll(/<img\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.filter((tag) => {
|
|
const src = attrValue(tag, 'src') ?? '';
|
|
return src.includes('volver-a-ti-') && !src.includes('volver-a-ti-hero.webp');
|
|
});
|
|
|
|
assert.equal(belowFoldImgs.length, 4, 'Expected 4 below-the-fold volver-a-ti-*.webp images');
|
|
for (const img of belowFoldImgs) {
|
|
assert.equal(attrValue(img, 'loading'), 'lazy');
|
|
assert.ok(attrValue(img, 'width'), `Below-the-fold image must declare width: ${img}`);
|
|
assert.ok(attrValue(img, 'height'), `Below-the-fold image must declare height: ${img}`);
|
|
}
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'/volver-a-ti/ #inscripcion renders checkbox, label, /descargo/ link outside label, and live status',
|
|
() => {
|
|
const html = readBuiltRoute('volver-a-ti/index.html');
|
|
const inscripcion = sectionById(html, 'inscripcion');
|
|
|
|
const checkbox = inscripcion.match(
|
|
/<input\b[^>]*\bid=(?:"accept-disclaimer"|'accept-disclaimer'|accept-disclaimer)[^>]*>/i,
|
|
)?.[0];
|
|
assert.ok(checkbox, 'Expected #accept-disclaimer checkbox inside #inscripcion');
|
|
assert.equal(attrValue(checkbox, 'type'), 'checkbox');
|
|
assert.equal(attrValue(checkbox, 'aria-describedby'), 'disclaimer-status');
|
|
|
|
const labelMatch = inscripcion.match(
|
|
/<label\b[^>]*\bfor=(?:"accept-disclaimer"|'accept-disclaimer'|accept-disclaimer)[^>]*>([\s\S]*?)<\/label>/i,
|
|
);
|
|
assert.ok(labelMatch, 'Expected <label for="accept-disclaimer"> inside #inscripcion');
|
|
assert.equal(
|
|
/<a\b/i.test(labelMatch[1]),
|
|
false,
|
|
'/descargo/ link must stay outside <label for="accept-disclaimer">',
|
|
);
|
|
|
|
const descargoLinks = anchorTags(inscripcion).filter(
|
|
(tag) => attrValue(tag, 'href') === '/descargo/',
|
|
);
|
|
assert.ok(descargoLinks.length >= 1, 'Expected <a href="/descargo/"> inside #inscripcion');
|
|
|
|
const statusTag = inscripcion.match(
|
|
/<p\b[^>]*\bid=(?:"disclaimer-status"|'disclaimer-status'|disclaimer-status)[^>]*>/i,
|
|
)?.[0];
|
|
assert.ok(statusTag, 'Expected <p id="disclaimer-status"> inside #inscripcion');
|
|
assert.equal(attrValue(statusTag, 'aria-live'), 'polite');
|
|
assert.equal(attrValue(statusTag, 'role'), 'status');
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'/volver-a-ti/ #inscripcion wires ungated inquiry link, gated Zelle & Ko-fi links, and zero hardcoded aria-disabled',
|
|
() => {
|
|
const html = readBuiltRoute('volver-a-ti/index.html');
|
|
assert.equal(
|
|
/\baria-disabled=(?:"true"|'true'|true)\b/i.test(html),
|
|
false,
|
|
'Built /volver-a-ti/ HTML must not hardcode aria-disabled="true"',
|
|
);
|
|
|
|
const inscripcion = sectionById(html, 'inscripcion');
|
|
const anchors = anchorTags(inscripcion);
|
|
|
|
const ungatedWa = anchors.filter(
|
|
(tag) =>
|
|
(attrValue(tag, 'href') ?? '').startsWith('https://wa.me/573215428972') &&
|
|
attrValue(tag, 'data-disclaimer-gate') === null,
|
|
);
|
|
assert.ok(ungatedWa.length >= 1, 'Expected ungated WhatsApp inquiry link in #inscripcion');
|
|
|
|
const gatedZelle = anchors.filter(
|
|
(tag) =>
|
|
(attrValue(tag, 'href') ?? '').startsWith('https://wa.me/573215428972') &&
|
|
attrValue(tag, 'data-disclaimer-gate') !== null,
|
|
);
|
|
assert.equal(gatedZelle.length, 1, 'Expected one gated Zelle WhatsApp link in #inscripcion');
|
|
assert.equal(attrValue(gatedZelle[0], 'target'), '_blank');
|
|
const zelleRel = new Set((attrValue(gatedZelle[0], 'rel') ?? '').split(/\s+/));
|
|
assert.ok(zelleRel.has('noopener') && zelleRel.has('noreferrer'));
|
|
|
|
const zelleUrl = new URL(attrValue(gatedZelle[0], 'href'));
|
|
const decodedText = zelleUrl.searchParams.get('text') ?? '';
|
|
assert.ok(
|
|
decodedText.toLowerCase().includes(EXPECTED_ZELLE_ACCEPT_TEXT),
|
|
`Expected Zelle ?text= to include "${EXPECTED_ZELLE_ACCEPT_TEXT}", got "${decodedText}"`,
|
|
);
|
|
|
|
const kofiLinks = anchors.filter((tag) =>
|
|
(attrValue(tag, 'href') ?? '').startsWith('https://ko-fi.com/'),
|
|
);
|
|
assert.ok(
|
|
kofiLinks.length >= 0 && kofiLinks.length <= 2,
|
|
`Expected 0..2 Ko-fi links, got ${kofiLinks.length}`,
|
|
);
|
|
for (const kofi of kofiLinks) {
|
|
assert.notEqual(attrValue(kofi, 'data-disclaimer-gate'), null);
|
|
assert.equal(attrValue(kofi, 'target'), '_blank');
|
|
const rel = new Set((attrValue(kofi, 'rel') ?? '').split(/\s+/));
|
|
assert.ok(rel.has('noopener') && rel.has('noreferrer'));
|
|
}
|
|
},
|
|
);
|
|
|
|
await t.test('/descargo/ contains return link to /volver-a-ti/#inscripcion', () => {
|
|
const html = readBuiltRoute('descargo/index.html');
|
|
const returnLinks = anchorTags(html).filter(
|
|
(tag) => attrValue(tag, 'href') === '/volver-a-ti/#inscripcion',
|
|
);
|
|
assert.ok(
|
|
returnLinks.length >= 1,
|
|
'Expected /descargo/ to contain a return link to /volver-a-ti/#inscripcion',
|
|
);
|
|
});
|
|
|
|
await t.test('dist/ built HTML and JS files pass PII email and phone allowlist', () => {
|
|
assert.ok(fs.existsSync(distAssetsDir), 'Expected dist/assets directory to exist');
|
|
const files = collectBuiltTextFiles(distDir);
|
|
assert.ok(files.length > 0, 'Expected built .html and .js files in dist/');
|
|
|
|
const emailPattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
|
|
const coMobilePattern = /\b(?:\+?57[\s.-]?)?3\d{2}[\s.-]?\d{3}[\s.-]?\d{4}\b/g;
|
|
const usPhonePattern =
|
|
/(?:\+?1[\s.-]?)?\(\d{3}\)[\s.-]?\d{3}[\s.-]?\d{4}\b|\+?1[\s.-]\d{3}[\s.-]\d{3}[\s.-]\d{4}\b/g;
|
|
|
|
for (const filePath of files) {
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
if (filePath.endsWith('.html')) {
|
|
// Why: exclude inline <svg> path data (d="...") and xmlns attributes from PII regexes.
|
|
content = content.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gi, '');
|
|
}
|
|
const rel = path.relative(distDir, filePath);
|
|
|
|
for (const match of content.matchAll(emailPattern)) {
|
|
assert.equal(match[0], ALLOWED_EMAIL, `Unexpected email ${match[0]} in dist/${rel}`);
|
|
}
|
|
|
|
for (const match of content.matchAll(coMobilePattern)) {
|
|
const digits = match[0].replace(/\D/g, '');
|
|
const normalized = digits.length === 10 ? `57${digits}` : digits;
|
|
assert.equal(
|
|
normalized,
|
|
ALLOWED_PHONE_DIGITS,
|
|
`Unexpected Colombian mobile ${match[0]} in dist/${rel}`,
|
|
);
|
|
}
|
|
|
|
for (const match of content.matchAll(usPhonePattern)) {
|
|
const normalized = match[0].replace(/\D/g, '');
|
|
assert.equal(
|
|
normalized,
|
|
ALLOWED_PHONE_DIGITS,
|
|
`Unexpected US phone ${match[0]} in dist/${rel}`,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
test('Issue #6 disclaimer gate script (volver-a-ti.js) behavior', async (t) => {
|
|
await t.test(
|
|
'unchecked init sets aria-disabled="true" on gated links without mutating href or ungated links',
|
|
async () => {
|
|
await withVolverDomDouble(
|
|
{ initialChecked: false },
|
|
async ({ zelleLink, kofiLink, inquiryLink, descargoLink }) => {
|
|
const initialZelleHref = zelleLink.href;
|
|
await import(`${volverScriptUrl}?case=init-unchecked`);
|
|
|
|
assert.equal(zelleLink.getAttribute('aria-disabled'), 'true');
|
|
assert.equal(kofiLink.getAttribute('aria-disabled'), 'true');
|
|
assert.equal(zelleLink.href, initialZelleHref);
|
|
assert.equal(inquiryLink.getAttribute('aria-disabled'), null);
|
|
assert.equal(descargoLink.getAttribute('aria-disabled'), null);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'clicking gated link while unchecked calls preventDefault(), sets status text, and focuses checkbox',
|
|
async () => {
|
|
await withVolverDomDouble(
|
|
{ initialChecked: false },
|
|
async ({ checkbox, status, zelleLink }) => {
|
|
await import(`${volverScriptUrl}?case=click-unchecked`);
|
|
|
|
let defaultPrevented = false;
|
|
zelleLink.dispatch('click', {
|
|
preventDefault() {
|
|
defaultPrevented = true;
|
|
},
|
|
});
|
|
|
|
assert.equal(defaultPrevented, true);
|
|
assert.equal(status.textContent, EXPECTED_GATE_STATUS);
|
|
assert.equal(checkbox.focusCalls, 1);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'checking #accept-disclaimer removes aria-disabled, clears status, and allows subsequent click',
|
|
async () => {
|
|
await withVolverDomDouble(
|
|
{ initialChecked: false },
|
|
async ({ checkbox, status, zelleLink, kofiLink }) => {
|
|
await import(`${volverScriptUrl}?case=check-unlocks`);
|
|
|
|
zelleLink.dispatch('click', { preventDefault() {} });
|
|
assert.equal(status.textContent, EXPECTED_GATE_STATUS);
|
|
|
|
checkbox.checked = true;
|
|
checkbox.dispatch('change');
|
|
|
|
assert.equal(zelleLink.getAttribute('aria-disabled'), null);
|
|
assert.equal(kofiLink.getAttribute('aria-disabled'), null);
|
|
assert.equal(status.textContent, '');
|
|
|
|
let defaultPrevented = false;
|
|
zelleLink.dispatch('click', {
|
|
preventDefault() {
|
|
defaultPrevented = true;
|
|
},
|
|
});
|
|
assert.equal(defaultPrevented, false);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test('window pageshow with checkbox.checked === true removes aria-disabled', async () => {
|
|
await withVolverDomDouble(
|
|
{ initialChecked: false },
|
|
async ({ windowDouble, checkbox, zelleLink }) => {
|
|
await import(`${volverScriptUrl}?case=pageshow-sync`);
|
|
assert.equal(zelleLink.getAttribute('aria-disabled'), 'true');
|
|
|
|
checkbox.checked = true;
|
|
windowDouble.dispatch('pageshow');
|
|
assert.equal(zelleLink.getAttribute('aria-disabled'), null);
|
|
},
|
|
);
|
|
});
|
|
|
|
await t.test(
|
|
'missing #accept-disclaimer or #inscripcion DOM elements is a safe no-op without throwing',
|
|
async () => {
|
|
await withVolverDomDouble({ includeCheckbox: false }, async () => {
|
|
await assert.doesNotReject(() => import(`${volverScriptUrl}?case=missing-checkbox`));
|
|
});
|
|
await withVolverDomDouble({ includeInscripcion: false }, async () => {
|
|
await assert.doesNotReject(() => import(`${volverScriptUrl}?case=missing-inscripcion`));
|
|
});
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'built /volver-a-ti/ JS bundle wires disclaimer gate behavior end-to-end',
|
|
async () => {
|
|
const html = readBuiltRoute('volver-a-ti/index.html');
|
|
const scriptSources = bundledModuleSources(html);
|
|
assert.ok(
|
|
scriptSources.length > 0,
|
|
'Built /volver-a-ti/index.html must reference at least one bundled /assets/*.js module',
|
|
);
|
|
|
|
const bundlePaths = scriptSources.map((src) => {
|
|
const cleanSrc = src.split(/[?#]/)[0].replace(/^\.?\//, '');
|
|
const bundlePath = path.resolve('dist', cleanSrc);
|
|
assert.ok(fs.existsSync(bundlePath), `Bundled module ${src} must exist on disk`);
|
|
return bundlePath;
|
|
});
|
|
|
|
await withVolverDomDouble(
|
|
{ initialChecked: false },
|
|
async ({ checkbox, status, zelleLink }) => {
|
|
for (const [index, bundlePath] of bundlePaths.entries()) {
|
|
await import(`${pathToFileURL(bundlePath).href}?case=dist-volver-${index}`);
|
|
}
|
|
|
|
assert.equal(zelleLink.getAttribute('aria-disabled'), 'true');
|
|
|
|
let prevented = false;
|
|
zelleLink.dispatch('click', {
|
|
preventDefault() {
|
|
prevented = true;
|
|
},
|
|
});
|
|
assert.equal(prevented, true);
|
|
assert.equal(status.textContent, EXPECTED_GATE_STATUS);
|
|
assert.equal(checkbox.focusCalls, 1);
|
|
|
|
checkbox.checked = true;
|
|
checkbox.dispatch('change');
|
|
assert.equal(zelleLink.getAttribute('aria-disabled'), null);
|
|
assert.equal(status.textContent, '');
|
|
},
|
|
);
|
|
},
|
|
);
|
|
});
|