Files
corazoncp-landing/tests/a11y-foundations.test.js
T
Andrés Tróchez 20908fdf78 fix(a11y): resolve WCAG contrast, sticky header legibility, WhatsApp FAB overlap, and skip link (#16)
* test(a11y): add Red contract tests for contrast, sticky header, skip link, and FAB

- Assert skip-to-content link before .fixed WhatsApp FAB and <main id="main"> across all 4 built routes
- Assert bg-ivory/95 header, #146c3c/#183a2d FAB contrast + mobile icon circle, #7d5d28 gold token, pb-20 footer, and >=24px tap targets

* fix(a11y): resolve WCAG contrast, sticky header legibility, WhatsApp FAB overlap, and skip link

- Switch sticky header from bg-sage/15 to bg-ivory/95, prepend #main skip link before .fixed FAB, and add py-2.5 lg:py-1.5 nav tap padding
- Darken WhatsApp FAB to #146c3c, align aria-label with visible text ("Conversar con Azu por WhatsApp"), and collapse to 48x48 circle on <640px
- Darken --color-gold to #7d5d28 and footer text to #4b5950; add pb-20 on footer and pb-24 on /kundalini/ main
- Add id="main" across all 4 routes, scroll-mt-24 on focus targets, and update Slice 3 header bg assertion in services-catalog.test.js
2026-11-30 13:40:23 -05:00

216 lines
7.6 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
const ROUTES = [
'dist/index.html',
'dist/kundalini/index.html',
'dist/volver-a-ti/index.html',
'dist/descargo/index.html',
];
function readRoute(routePath) {
return fs.readFileSync(path.resolve(routePath), 'utf-8');
}
function readBuiltCss() {
const assetsDir = path.resolve('dist/assets');
const cssFiles = fs.readdirSync(assetsDir).filter((file) => file.endsWith('.css'));
assert.ok(cssFiles.length > 0, 'dist/assets must contain at least one built CSS file');
return cssFiles.map((file) => fs.readFileSync(path.join(assetsDir, file), 'utf-8')).join('\n');
}
function extractBody(html, routePath) {
const match = html.match(/<body\b[^>]*>([\s\S]*)<\/body>/i);
assert.ok(match, `${routePath}: built HTML must contain a <body> element`);
return match[1];
}
function extractFloatingWhatsAppLink(html, routePath) {
const match = html.match(/<a\b[^>]*class="[^"]*\bfixed\b[^"]*"[^>]*>[\s\S]*?<\/a>/i);
assert.ok(match, `${routePath}: built HTML must contain a floating .fixed WhatsApp link`);
return match[0];
}
function hasAccessibleTapTarget(classAttr) {
return (
/\bpy-(?:1\.5|2|2\.5)\b/.test(classAttr) ||
(/\binline-flex\b/.test(classAttr) && /\bmin-h-\[24px\]\b/.test(classAttr))
);
}
test('Issue #11 Acceptance Criteria: A11y foundations, contrast, and sticky header', async (t) => {
await t.test('Criterion 1a: every built route defines <main id="main">', () => {
for (const route of ROUTES) {
const html = readRoute(route);
assert.match(
html,
/<main\b[^>]*\bid="main"[^>]*>/i,
`${route}: must contain <main id="main">`,
);
}
});
await t.test(
'Criterion 1b: every built route has an <a href="#main"> skip link before the floating WhatsApp link in <body>',
() => {
for (const route of ROUTES) {
const body = extractBody(readRoute(route), route);
const skipLinkMatch = /<a\b[^>]*\bhref="#main"[^>]*>[\s\S]*?<\/a>/i.exec(body);
assert.ok(skipLinkMatch, `${route}: <body> must contain an <a href="#main"> skip link`);
const fabMatch = /<a\b[^>]*class="[^"]*\bfixed\b[^"]*"[^>]*>/i.exec(body);
assert.ok(fabMatch, `${route}: <body> must contain a floating .fixed WhatsApp link`);
assert.ok(
skipLinkMatch.index < fabMatch.index,
`${route}: <a href="#main"> skip link must appear before the floating .fixed WhatsApp link`,
);
}
},
);
await t.test(
'Criterion 2: every built route sticky <header> uses bg-ivory/95 instead of bg-sage/15',
() => {
for (const route of ROUTES) {
const html = readRoute(route);
const headerOpenTag = html.match(/<header\b[^>]*>/i)?.[0];
assert.ok(headerOpenTag, `${route}: must contain a <header> element`);
assert.match(
headerOpenTag,
/\bbg-ivory\/95\b/,
`${route}: <header> must use bg-ivory/95 for legibility`,
);
assert.doesNotMatch(
headerOpenTag,
/\bbg-sage\/15\b/,
`${route}: <header> must not use low-contrast bg-sage/15`,
);
}
},
);
await t.test('Criterion 3a: floating WhatsApp FAB does not use low-contrast bg-[#25D366]', () => {
for (const route of ROUTES) {
const fab = extractFloatingWhatsAppLink(readRoute(route), route);
assert.doesNotMatch(
fab,
/bg-\[#25D366\]/i,
`${route}: floating WhatsApp link must not use bg-[#25D366]`,
);
}
});
await t.test(
'Criterion 3b: floating WhatsApp FAB aria-label includes both "Conversar con Azu" and "WhatsApp"',
() => {
for (const route of ROUTES) {
const fab = extractFloatingWhatsAppLink(readRoute(route), route);
const ariaLabel = fab.match(/\baria-label="([^"]*)"/i)?.[1];
assert.ok(ariaLabel, `${route}: floating WhatsApp link must have an aria-label`);
assert.ok(
ariaLabel.includes('Conversar con Azu'),
`${route}: WhatsApp FAB aria-label must include "Conversar con Azu"`,
);
assert.ok(
ariaLabel.includes('WhatsApp'),
`${route}: WhatsApp FAB aria-label must include "WhatsApp"`,
);
}
},
);
await t.test(
'Criterion 3c: floating WhatsApp FAB wraps "Conversar con Azu" in <span class="hidden sm:inline"> for a 48x48 mobile circle',
() => {
for (const route of ROUTES) {
const fab = extractFloatingWhatsAppLink(readRoute(route), route);
assert.match(
fab,
/<span\b[^>]*class="[^"]*\bhidden\b[^"]*\bsm:inline\b[^"]*"[^>]*>\s*Conversar con Azu\s*<\/span>/i,
`${route}: floating WhatsApp link must wrap "Conversar con Azu" in <span class="hidden sm:inline">`,
);
}
},
);
await t.test(
'Criterion 4: <footer> avoids text-forest/60 and includes pb-20 or pb-24 for mobile FAB clearance',
() => {
for (const route of ROUTES) {
const html = readRoute(route);
const footerOpenTag = html.match(/<footer\b[^>]*>/i)?.[0];
assert.ok(footerOpenTag, `${route}: must contain a <footer> element`);
assert.doesNotMatch(
footerOpenTag,
/\btext-forest\/60\b/,
`${route}: <footer> must not use low-contrast text-forest/60`,
);
assert.match(
footerOpenTag,
/\bpb-(?:20|24)\b/,
`${route}: <footer> must include pb-20 or pb-24 to clear the mobile floating button`,
);
}
},
);
await t.test('Criterion 5: built CSS sets --color-gold to #7d5d28 and removes #b08a4f', () => {
const css = readBuiltCss();
assert.match(css, /--color-gold:\s*#7d5d28\b/i, 'Built CSS must define --color-gold: #7d5d28');
assert.doesNotMatch(
css,
/#b08a4f\b/i,
'Built CSS must not contain the old low-contrast #b08a4f gold token',
);
});
await t.test(
'Criterion 6a: header nav links (#site-menu a) include vertical padding or min-h-[24px] for >= 24px tap targets',
() => {
for (const route of ROUTES) {
const html = readRoute(route);
const menuMarkup = html.match(/<ul\b[^>]*\bid="site-menu"[^>]*>[\s\S]*?<\/ul>/i)?.[0];
assert.ok(menuMarkup, `${route}: must contain #site-menu`);
const links = [...menuMarkup.matchAll(/<a\b[^>]*>/gi)].map((match) => match[0]);
assert.ok(links.length > 0, `${route}: #site-menu must contain navigation links`);
for (const link of links) {
const classAttr = link.match(/\bclass="([^"]*)"/i)?.[1] ?? '';
assert.ok(
hasAccessibleTapTarget(classAttr),
`${route}: #site-menu link (${link}) must include py-1.5/py-2/py-2.5 or inline-flex min-h-[24px]`,
);
}
}
},
);
await t.test(
'Criterion 6b: footer social links include vertical padding or min-h-[24px] for >= 24px tap targets',
() => {
for (const route of ROUTES) {
const html = readRoute(route);
const footerMarkup = html.match(/<footer\b[^>]*>[\s\S]*?<\/footer>/i)?.[0];
assert.ok(footerMarkup, `${route}: must contain <footer>`);
const links = [...footerMarkup.matchAll(/<a\b[^>]*>/gi)].map((match) => match[0]);
assert.ok(links.length > 0, `${route}: <footer> must contain social links`);
for (const link of links) {
const classAttr = link.match(/\bclass="([^"]*)"/i)?.[1] ?? '';
assert.ok(
hasAccessibleTapTarget(classAttr),
`${route}: footer link (${link}) must include py-1.5/py-2/py-2.5 or inline-flex min-h-[24px]`,
);
}
}
},
);
});