mirror of
https://github.com/corazoncp/corazoncp-landing.git
synced 2026-11-30 20:20:32 +00:00
- `src/partials/header.html`: add `Kundalini Yoga` (`/kundalini/`, `data-nav-current="kundalini"`) link between `/#servicios` and `/#otros-espacios` - `index.html`: route Service Card 2 CTA in-tab to `/kundalini/` instead of `wa.me` - `AGENTS.md`: document `/kundalini/` routing and temporary Spanish-only routes ahead of Slice 5 - `tests/html-partials.test.js` & `tests/services-catalog.test.js`: update contract tests for `/kundalini/` nav link, `aria-current="page"` mapping, and Card 2 route
410 lines
15 KiB
JavaScript
410 lines
15 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
import { expandHtmlPartials, htmlPartialsPlugin } from '../scripts/html-partials-plugin.ts';
|
|
|
|
const distIndexPath = path.resolve('dist/index.html');
|
|
|
|
// Why: the plugin only runs at build time, so these assertions must inspect the
|
|
// deployable artifact instead of the source document.
|
|
const distHtml = fs.readFileSync(distIndexPath, 'utf-8');
|
|
|
|
function findMetaByProperty(html, property) {
|
|
return [...html.matchAll(/<meta\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => tag.toLowerCase().includes(`property="${property}"`));
|
|
}
|
|
|
|
function extractHeaderMarkup(html) {
|
|
const headerMarkup = html.match(/<header\b[\s\S]*?<\/header>/i)?.[0];
|
|
assert.ok(headerMarkup, 'Built HTML must contain an expanded header partial');
|
|
return headerMarkup;
|
|
}
|
|
|
|
function findDisclosureButton(headerMarkup) {
|
|
const disclosureButton = [...headerMarkup.matchAll(/<button\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => /\baria-controls="site-menu"/i.test(tag));
|
|
assert.ok(disclosureButton, 'Header must have a disclosure button controlling #site-menu');
|
|
return disclosureButton;
|
|
}
|
|
|
|
/**
|
|
* Locate a service card by its <h3> heading and return its enclosing card <div>.
|
|
* Why: avoids coupling tests to HTML comments that minification may strip.
|
|
*/
|
|
function extractCardByHeading(html, headingText) {
|
|
const headingMatch = new RegExp(`<h3\\b[^>]*>[^<]*${headingText}[^<]*</h3>`, 'i').exec(html);
|
|
if (!headingMatch) {
|
|
return undefined;
|
|
}
|
|
|
|
const cardOpenPattern = /<div\b[^>]*class="[^"]*\brounded-2xl\b[^"]*"[^>]*>/gi;
|
|
let cardStart = -1;
|
|
for (const match of html.matchAll(cardOpenPattern)) {
|
|
if (match.index <= headingMatch.index) {
|
|
cardStart = match.index;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
if (cardStart === -1) {
|
|
return undefined;
|
|
}
|
|
|
|
const divTagPattern = /<\/?div\b[^>]*>/gi;
|
|
divTagPattern.lastIndex = cardStart;
|
|
let depth = 0;
|
|
for (const tagMatch of html.matchAll(divTagPattern)) {
|
|
if (tagMatch.index < cardStart) {
|
|
continue;
|
|
}
|
|
depth += tagMatch[0].startsWith('</') ? -1 : 1;
|
|
if (depth === 0) {
|
|
return html.slice(cardStart, tagMatch.index + tagMatch[0].length);
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
test('Issue #5 Acceptance Criteria: built partials, navigation and metadata', async (t) => {
|
|
await t.test('Criterion 2: built header uses root-relative navigation links', () => {
|
|
const headerMarkup = extractHeaderMarkup(distHtml);
|
|
|
|
for (const href of [
|
|
'/',
|
|
'/#servicios',
|
|
'/#otros-espacios',
|
|
'/#acerca',
|
|
'/#filosofia',
|
|
'/#contacto',
|
|
]) {
|
|
assert.ok(
|
|
headerMarkup.includes(`href="${href}"`),
|
|
`Built header must use the root-relative href="${href}"`,
|
|
);
|
|
}
|
|
});
|
|
|
|
await t.test(
|
|
'Issue #6: built header exposes a "Kundalini Yoga" link to /kundalini/ between Servicios and Otros Espacios',
|
|
() => {
|
|
const headerMarkup = extractHeaderMarkup(distHtml);
|
|
const kundaliniLink = headerMarkup.match(
|
|
/<a\b[^>]*\bhref="\/kundalini\/"[^>]*>([\s\S]*?)<\/a>/i,
|
|
);
|
|
assert.ok(kundaliniLink, 'Built header must contain a link with href="/kundalini/"');
|
|
assert.match(
|
|
kundaliniLink[1].replace(/<[^>]*>/g, ' '),
|
|
/Kundalini Yoga/,
|
|
'The /kundalini/ header link must be labelled "Kundalini Yoga"',
|
|
);
|
|
|
|
// Why: spec places the route link right after Servicios so the nav mirrors page order.
|
|
const serviciosIndex = headerMarkup.indexOf('href="/#servicios"');
|
|
const kundaliniIndex = headerMarkup.indexOf('href="/kundalini/"');
|
|
const otrosIndex = headerMarkup.indexOf('href="/#otros-espacios"');
|
|
assert.ok(
|
|
serviciosIndex !== -1 && serviciosIndex < kundaliniIndex && kundaliniIndex < otrosIndex,
|
|
'The /kundalini/ link must sit between /#servicios and /#otros-espacios',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test('Issue #6: /kundalini/ header link is not aria-current on the home route', () => {
|
|
const headerMarkup = extractHeaderMarkup(distHtml);
|
|
const kundaliniTag = [...headerMarkup.matchAll(/<a\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => /\bhref="\/kundalini\/"/i.test(tag));
|
|
assert.ok(kundaliniTag, 'Built header must contain a link with href="/kundalini/"');
|
|
// Why: on "/" only the brand link is current; a second current item would mislead AT users.
|
|
assert.doesNotMatch(
|
|
kundaliniTag,
|
|
/\baria-current=/i,
|
|
'The /kundalini/ link must not carry aria-current on the home route',
|
|
);
|
|
});
|
|
|
|
await t.test(
|
|
'Criterion 2: built header marks the root brand link with aria-current="page"',
|
|
() => {
|
|
const headerMarkup = extractHeaderMarkup(distHtml);
|
|
const brandLink = [...headerMarkup.matchAll(/<a\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => /\bhref="\/"/i.test(tag));
|
|
assert.ok(brandLink, 'Brand link in built header must target "/"');
|
|
assert.match(
|
|
brandLink,
|
|
/\baria-current="page"/i,
|
|
'Root brand link must carry aria-current="page" on the home route',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test('Criterion 2: built header contains exactly one #site-menu navigation tree', () => {
|
|
const headerMarkup = extractHeaderMarkup(distHtml);
|
|
assert.equal(
|
|
headerMarkup.match(/id="site-menu"/gi)?.length ?? 0,
|
|
1,
|
|
'Header must contain exactly one #site-menu navigation tree',
|
|
);
|
|
});
|
|
|
|
await t.test('Criterion 2: header disclosure button exposes aria-expanded state', () => {
|
|
const disclosureButton = findDisclosureButton(extractHeaderMarkup(distHtml));
|
|
assert.match(
|
|
disclosureButton,
|
|
/\baria-expanded="(?:true|false)"/i,
|
|
'Disclosure button must expose aria-expanded state',
|
|
);
|
|
});
|
|
|
|
await t.test('Criterion 2: header disclosure button meets the 44px minimum touch target', () => {
|
|
const disclosureButton = findDisclosureButton(extractHeaderMarkup(distHtml));
|
|
// Why: 44px is the minimum touch target; Tailwind h-11/w-11 equal 44px.
|
|
assert.match(
|
|
disclosureButton,
|
|
/(?:min-)?h-(?:\[44px\]|11)|size-11/i,
|
|
'Disclosure button must have at least a 44px height',
|
|
);
|
|
assert.match(
|
|
disclosureButton,
|
|
/(?:min-)?w-(?:\[44px\]|11)|size-11/i,
|
|
'Disclosure button must have at least a 44px width',
|
|
);
|
|
});
|
|
|
|
await t.test(
|
|
'Criterion 1: built footer partial is expanded with the official Facebook link',
|
|
() => {
|
|
const footerMarkup = distHtml.match(/<footer\b[\s\S]*?<\/footer>/i)?.[0];
|
|
assert.ok(footerMarkup, 'Built HTML must contain an expanded footer partial');
|
|
assert.match(
|
|
footerMarkup,
|
|
/href="https:\/\/www\.facebook\.com\/elcorazoncomoportal\/"/i,
|
|
'Built footer must retain the official Facebook link from the footer partial',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'Criterion 1: built WhatsApp FAB partial is expanded with the approved wa.me link',
|
|
() => {
|
|
const fabMarkup = distHtml.match(
|
|
/<a[^>]*class="[^"]*fixed[^"]*bottom-[^"]*right-[^"]*z-50[^"]*"[^>]*>[\s\S]*?<\/a>/i,
|
|
)?.[0];
|
|
assert.ok(fabMarkup, 'Built HTML must contain the expanded persistent WhatsApp FAB');
|
|
assert.match(
|
|
fabMarkup,
|
|
/href="https:\/\/wa\.me\/573215428972/i,
|
|
'Expanded FAB must keep the approved wa.me destination',
|
|
);
|
|
},
|
|
);
|
|
|
|
await t.test('Criterion 1: build strips @include markers from built HTML', () => {
|
|
assert.doesNotMatch(
|
|
distHtml,
|
|
/<!--\s*@include/i,
|
|
'Built HTML must not leak any @include markers',
|
|
);
|
|
});
|
|
|
|
await t.test('Criterion 1: build strips data-nav-current hints from built HTML', () => {
|
|
assert.doesNotMatch(
|
|
distHtml,
|
|
/data-nav-current(?:="[^"]*")?/i,
|
|
'Build-time data-nav-current hints must be stripped from built HTML',
|
|
);
|
|
});
|
|
|
|
await t.test('Criterion 4: built HTML carries canonical link to the site root', () => {
|
|
const canonicalTag = [...distHtml.matchAll(/<link\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => tag.toLowerCase().includes('rel="canonical"'));
|
|
assert.ok(canonicalTag, 'Built HTML must include a canonical link tag');
|
|
assert.match(
|
|
canonicalTag,
|
|
/href="https:\/\/elcorazoncomoportal\.com\/"/i,
|
|
'Canonical URL must be the site root',
|
|
);
|
|
});
|
|
|
|
await t.test('Criterion 4: built HTML carries non-empty og:title metadata', () => {
|
|
const ogTitle = findMetaByProperty(distHtml, 'og:title');
|
|
assert.ok(ogTitle, 'Built HTML must include og:title');
|
|
assert.match(ogTitle, /content="[^"]+"/i, 'og:title must have non-empty content');
|
|
});
|
|
|
|
await t.test('Criterion 4: built HTML carries non-empty og:description metadata', () => {
|
|
const ogDescription = findMetaByProperty(distHtml, 'og:description');
|
|
assert.ok(ogDescription, 'Built HTML must include og:description');
|
|
assert.match(ogDescription, /content="[^"]+"/i, 'og:description must have non-empty content');
|
|
});
|
|
|
|
await t.test('Criterion 4: built HTML carries og:url pointing to the site root', () => {
|
|
const ogUrl = findMetaByProperty(distHtml, 'og:url');
|
|
assert.ok(ogUrl, 'Built HTML must include og:url');
|
|
assert.match(
|
|
ogUrl,
|
|
/content="https:\/\/elcorazoncomoportal\.com\/"/i,
|
|
'og:url must point to the site root',
|
|
);
|
|
});
|
|
|
|
await t.test('Criterion 4: built HTML carries og:image using the approved hero asset', () => {
|
|
const ogImage = findMetaByProperty(distHtml, 'og:image');
|
|
assert.ok(ogImage, 'Built HTML must include og:image');
|
|
assert.match(
|
|
ogImage,
|
|
/content="https:\/\/elcorazoncomoportal\.com\/img\/azu-hero\.jpg"/i,
|
|
'og:image must use the approved absolute azu-hero.jpg URL',
|
|
);
|
|
});
|
|
|
|
await t.test('Issue #6: Kundalini service card CTA opens /kundalini/ in the same tab', () => {
|
|
const kundaliniCard = extractCardByHeading(
|
|
distHtml,
|
|
'Clases de Kundalini Yoga y Acompañamientos',
|
|
);
|
|
assert.ok(kundaliniCard, 'Service Card 2 (Kundalini Yoga) must exist in built HTML');
|
|
const ctaTag = [...kundaliniCard.matchAll(/<a\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => /\bhref="\/kundalini\/"/i.test(tag));
|
|
assert.ok(ctaTag, 'Service Card 2 must link to the internal /kundalini/ route');
|
|
// Why: an internal route is same-site navigation; new-tab attributes are only for external links.
|
|
assert.doesNotMatch(ctaTag, /\btarget=/i, 'The /kundalini/ card CTA must open in-tab');
|
|
assert.doesNotMatch(ctaTag, /\brel=/i, 'The /kundalini/ card CTA must not carry rel');
|
|
assert.doesNotMatch(
|
|
kundaliniCard,
|
|
/href="https:\/\/wa\.me\//i,
|
|
'Service Card 2 must no longer carry a direct wa.me CTA',
|
|
);
|
|
});
|
|
});
|
|
|
|
test('html-partials-plugin unit behavior', async (t) => {
|
|
const navSampleHtml =
|
|
'<nav><a href="/" data-nav-current="home">Inicio</a><a href="/kundalini/" data-nav-current="kundalini">Kundalini</a></nav>';
|
|
|
|
await t.test(
|
|
'expandHtmlPartials rejects a missing partial path naming the unresolved file',
|
|
() => {
|
|
assert.throws(
|
|
() => expandHtmlPartials('<!-- @include src/partials/does-not-exist.html -->'),
|
|
/does-not-exist\.html/i,
|
|
'A missing partial include must throw an error naming the unresolved partial',
|
|
);
|
|
},
|
|
);
|
|
|
|
for (const disallowedSpecifier of [
|
|
'../package.json',
|
|
'src/partials/../package.json',
|
|
'src/partials/sub/header.html',
|
|
'src/partials/header.txt',
|
|
]) {
|
|
await t.test(`expandHtmlPartials rejects disallowed @include "${disallowedSpecifier}"`, () => {
|
|
assert.throws(
|
|
() => expandHtmlPartials(`<!-- @include ${disallowedSpecifier} -->`),
|
|
/Unsupported @include|Unsafe @include/i,
|
|
`Disallowed @include "${disallowedSpecifier}" must be rejected`,
|
|
);
|
|
});
|
|
}
|
|
|
|
await t.test('transformIndexHtml marks kundalini current and strips home hint in dev ctx', () => {
|
|
const plugin = htmlPartialsPlugin();
|
|
plugin.configResolved?.({ root: process.cwd() });
|
|
|
|
const result = plugin.transformIndexHtml.handler(navSampleHtml, {
|
|
path: '/kundalini/',
|
|
filename: path.resolve('index.html'),
|
|
server: {},
|
|
});
|
|
|
|
assert.match(result, /href="\/kundalini\/"[^>]*\baria-current="page"/i);
|
|
assert.doesNotMatch(result, /href="\/"[^>]*\baria-current="page"/i);
|
|
assert.doesNotMatch(result, /\bdata-nav-current\b/i);
|
|
});
|
|
|
|
await t.test(
|
|
'transformIndexHtml marks kundalini current and strips home hint in build ctx',
|
|
() => {
|
|
const plugin = htmlPartialsPlugin();
|
|
plugin.configResolved?.({ root: process.cwd() });
|
|
|
|
const result = plugin.transformIndexHtml.handler(navSampleHtml, {
|
|
path: '/index.html',
|
|
filename: path.resolve('kundalini/index.html'),
|
|
});
|
|
|
|
assert.match(result, /href="\/kundalini\/"[^>]*\baria-current="page"/i);
|
|
assert.doesNotMatch(result, /href="\/"[^>]*\baria-current="page"/i);
|
|
assert.doesNotMatch(result, /\bdata-nav-current\b/i);
|
|
},
|
|
);
|
|
|
|
await t.test(
|
|
'transformIndexHtml strips all data-nav-current attributes without setting aria-current on non-matching routes',
|
|
() => {
|
|
const plugin = htmlPartialsPlugin();
|
|
plugin.configResolved?.({ root: process.cwd() });
|
|
|
|
const result = plugin.transformIndexHtml.handler(navSampleHtml, {
|
|
path: '/unknown/',
|
|
filename: path.resolve('index.html'),
|
|
server: {},
|
|
});
|
|
|
|
assert.doesNotMatch(result, /\baria-current=/i);
|
|
assert.doesNotMatch(result, /\bdata-nav-current\b/i);
|
|
},
|
|
);
|
|
|
|
// Why: these exercise the real header partial (not a synthetic sample) so the
|
|
// partial's data-nav-current hints and the plugin's route map stay in sync.
|
|
const realHeaderHtml = '<!-- @include src/partials/header.html -->';
|
|
|
|
function transformRealHeaderFor(routeFile) {
|
|
const plugin = htmlPartialsPlugin();
|
|
plugin.configResolved?.({ root: process.cwd() });
|
|
return plugin.transformIndexHtml.handler(realHeaderHtml, {
|
|
path: '/index.html',
|
|
filename: path.resolve(routeFile),
|
|
});
|
|
}
|
|
|
|
function anchorTagByHref(html, href) {
|
|
return [...html.matchAll(/<a\b[^>]*>/gi)]
|
|
.map((match) => match[0])
|
|
.find((tag) => tag.includes(`href="${href}"`));
|
|
}
|
|
|
|
await t.test(
|
|
'real header partial marks /kundalini/ link aria-current on kundalini/index.html build',
|
|
() => {
|
|
const result = transformRealHeaderFor('kundalini/index.html');
|
|
const kundaliniTag = anchorTagByHref(result, '/kundalini/');
|
|
assert.ok(kundaliniTag, 'Header partial must contain a href="/kundalini/" link');
|
|
assert.match(kundaliniTag, /\baria-current="page"/i);
|
|
assert.doesNotMatch(anchorTagByHref(result, '/') ?? '', /\baria-current=/i);
|
|
},
|
|
);
|
|
|
|
for (const routeFile of ['volver-a-ti/index.html', 'descargo/index.html']) {
|
|
await t.test(`real header partial sets no aria-current on ${routeFile} build`, () => {
|
|
const result = transformRealHeaderFor(routeFile);
|
|
assert.ok(
|
|
anchorTagByHref(result, '/kundalini/'),
|
|
'Header partial must contain a href="/kundalini/" link',
|
|
);
|
|
// Why: these routes have no nav entry, so no item may claim to be current.
|
|
assert.doesNotMatch(result, /\baria-current=/i);
|
|
assert.doesNotMatch(result, /\bdata-nav-current\b/i);
|
|
});
|
|
}
|
|
});
|