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(/]*>([\s\S]*)<\/body>/i); assert.ok(match, `${routePath}: built HTML must contain a element`); return match[1]; } function extractFloatingWhatsAppLink(html, routePath) { const match = html.match(/]*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
', () => { for (const route of ROUTES) { const html = readRoute(route); assert.match( html, /]*\bid="main"[^>]*>/i, `${route}: must contain
`, ); } }); await t.test( 'Criterion 1b: every built route has an skip link before the floating WhatsApp link in ', () => { for (const route of ROUTES) { const body = extractBody(readRoute(route), route); const skipLinkMatch = /]*\bhref="#main"[^>]*>[\s\S]*?<\/a>/i.exec(body); assert.ok(skipLinkMatch, `${route}: must contain an skip link`); const fabMatch = /]*class="[^"]*\bfixed\b[^"]*"[^>]*>/i.exec(body); assert.ok(fabMatch, `${route}: must contain a floating .fixed WhatsApp link`); assert.ok( skipLinkMatch.index < fabMatch.index, `${route}: skip link must appear before the floating .fixed WhatsApp link`, ); } }, ); await t.test( 'Criterion 2: every built route sticky
uses bg-ivory/95 instead of bg-sage/15', () => { for (const route of ROUTES) { const html = readRoute(route); const headerOpenTag = html.match(/]*>/i)?.[0]; assert.ok(headerOpenTag, `${route}: must contain a
element`); assert.match( headerOpenTag, /\bbg-ivory\/95\b/, `${route}:
must use bg-ivory/95 for legibility`, ); assert.doesNotMatch( headerOpenTag, /\bbg-sage\/15\b/, `${route}:
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