Files
Andrés Tróchez a340121acc feat(nav): add build-time partials, mobile disclosure menu, and dist tests (#9)
* test(nav): add Red build-partial contract tests and migrate suites to dist

- Point hero-whatsapp and services-catalog HTML assertions at dist/index.html so the deployable artifact is the tested seam; keep stylesheet token assertions on source
- Add tests/html-partials.test.js covering partial includes, stripped build hints, root-relative nav, canonical/OG metadata, preserved Kundalini wa.me CTA, and missing-partial error behavior
- Rationale: TDD Red checkpoint for issue #5; new assertions fail against the pre-plugin build for the expected reasons while migrated suites remain green

* feat(build): add HTML partials plugin and single-entry Vite build

- Add scripts/html-partials-plugin.ts to expand src/partials includes, fail loudly on unresolved paths, normalize dev/build route keys, apply/strip data-nav-current markers, and full-reload on partial edits
- Register the plugin before Vite transforms and pin rollup input to the root index.html for Phase 1
- Rationale: build-time injection keeps shared markup dependency-free and preserves identical dev/build route keys ahead of the new pages

* test(nav): add Red disclosure menu and a11y style contract tests

- Assert nav-menu.js class-based toggle, aria-expanded sync, Escape focus return, and same-page hash close without DOM dependencies
- Assert source/built module wiring and the header partial's collapsed mobile panel with the brand title preserved
- Assert style.css scroll padding, active underline, focus ring, reduced motion, and gated-link/disclaimer touch-target rules
- Rationale: Red checkpoint for issue #5 AC #2/#3; all failures are missing files or missing rules

* feat(nav): add shared partials, mobile disclosure menu, and home metadata

- Extract header, footer and floating WhatsApp button into src/partials and replace inline markup in index.html with build-time @include markers
- Add dependency-free src/scripts/nav-menu.js with class-based toggle, aria-expanded sync, Escape focus return and same-page hash close; load it as an ES module
- Add root-relative nav, 44px disclosure target and single-tree mobile panel; add sticky-header scroll padding, focus ring, active underline, reduced-motion and gated-link/disclaimer styles
- Add canonical and Open Graph tags for / while preserving every section's copy and Service Card 2's live wa.me CTA (route change deferred to a later issue)
- Rationale: shared markup stays build-time only, keeping main deployable with zero new runtime dependencies and no broken links

* fix(nav): place mobile disclosure toggle inside nav landmark

- Move the mobile disclosure button inside the primary nav landmark in src/partials/header.html
- Keep the header flex container at two children so the toggle stays flush right at 430px-767px instead of floating beside a 0px nav (CR-04)

* test(nav): execute nav-menu and built bundle against DOM double

- Execute src/scripts/nav-menu.js and the built bundle against a DOM double for toggle, Escape, and same-page vs cross-page link behavior
- Verify built CSS rules and header disclosure structure inside the nav landmark (CR-01, CR-03, CR-04, CR-05, CR-07)

* test(partials): add path-guard and route-key boundary tests

- Add unit tests for expandHtmlPartials path-guard rejection of disallowed @include specifiers and transformIndexHtml route-key marking
- Verify built HTML strips build markers/hints, preserves Open Graph/canonical metadata, and keeps header navigation invariants (CR-02, CR-06, CR-07)

* fix(nav): keep mobile brand title on a single line at 375px

- Use text-sm tracking-wide whitespace-nowrap on mobile and restore sm:text-xl sm:tracking-wider at >= 640px
- Resolves RV-02 375px brand-title wrapping failure while keeping desktop header styling unchanged

* fix(nav): switch desktop nav breakpoint to lg and prevent brand overlap

- Header layout (src/partials/header.html): move desktop nav expansion from md: to lg: (1024px), add shrink-0 on the brand link, and add gap-4 on the header flex row to prevent brand/nav overlap at 768px-1018px (PR #9 CR-08)
- Nav menu tests (tests/nav-menu.test.js): update built-header assertions to check lg:flex/lg:static/lg:hidden, gap-4 on the header inner flex container, and shrink-0 plus lg:hidden exclusion on the brand link
2026-11-30 01:56:48 -05:00

206 lines
7.3 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
// Why: assertions target the built deployable artifact so partial expansion and
// build-time transformations are covered by the same checks as hero markup.
const indexPath = path.resolve('dist/index.html');
const indexHtml = fs.readFileSync(indexPath, 'utf-8');
test('Slice 2 Acceptance Criteria: Hero and WhatsApp Flow', async (t) => {
await t.test(
'Criterion 1: Eyebrow badge signals dual modality and includes confirmation comment',
() => {
// Must contain Valledupar & Online dual modality in Hero section
const heroSection = indexHtml.match(/<section id="hero"[\s\S]*?<\/section>/)?.[0];
assert.ok(heroSection, 'Hero section must exist in index.html');
// Check for dual modality text: VALLEDUPAR & ONLINE
const eyebrowRegex = /ACOMPAÑAMIENTO CONSCIENTE\s*·\s*VALLEDUPAR\s*&\s*ONLINE/i;
assert.match(
heroSection,
eyebrowRegex,
'Eyebrow must explicitly signal dual modality: ACOMPAÑAMIENTO CONSCIENTE · VALLEDUPAR & ONLINE',
);
// Must include comment noting pending client confirmation per brief Section 02
assert.match(
heroSection,
/<!--[\s\S]*?pending[\s\S]*?confirmation[\s\S]*?Section 02[\s\S]*?-->/i,
'Hero eyebrow must have an explanatory comment noting pending confirmation per brief Section 02',
);
},
);
await t.test(
'Criterion 2: Primary Hero CTA triggers wa.me with pre-filled encoded inquiry message',
() => {
const heroSection = indexHtml.match(/<section id="hero"[\s\S]*?<\/section>/)?.[0];
assert.ok(heroSection, 'Hero section must exist');
const expectedPhone = '573215428972';
const expectedMessage =
'Hola Azu, visité tu página y me gustaría conversar sobre tus sesiones.';
const expectedEncoded = encodeURIComponent(expectedMessage);
// Hero primary CTA anchor
const ctaMatch = heroSection.match(/<a[^>]+href="([^"]+)"[^>]*>[\s\S]*?<\/a>/i);
assert.ok(ctaMatch, 'Hero must contain a primary CTA link');
const href = ctaMatch[1];
assert.ok(
href.startsWith(`https://wa.me/${expectedPhone}`),
`Hero CTA must target https://wa.me/${expectedPhone}`,
);
const url = new URL(href);
assert.equal(
url.searchParams.get('text'),
expectedMessage,
'CTA pre-filled text must match approved inquiry message',
);
assert.ok(
href.includes(expectedEncoded) || href.includes('Hola%20Azu'),
'URL must contain correctly percent-encoded query parameter',
);
assert.match(
ctaMatch[0],
/target="_blank"/i,
'Hero CTA must open in a new tab (target="_blank")',
);
assert.match(
ctaMatch[0],
/rel="noopener noreferrer"/i,
'Hero CTA must include rel="noopener noreferrer"',
);
},
);
await t.test(
'Criterion 3: Persistent floating WhatsApp button with >= 48px touch target, SVG icon and aria-label',
() => {
// Find floating WhatsApp button
const floatingBtnMatch = indexHtml.match(
/<a[^>]*class="[^"]*fixed[^"]*bottom-[^"]*right-[^"]*z-50[^"]*"[^>]*>[\s\S]*?<\/a>/i,
);
assert.ok(
floatingBtnMatch,
'Floating WhatsApp button must exist with fixed positioning (fixed, bottom-*, right-*, z-50)',
);
const buttonMarkup = floatingBtnMatch[0];
// Touch target >= 48px
assert.match(buttonMarkup, /min-h-\[48px\]/, 'Touch target must specify min-h-[48px]');
assert.match(buttonMarkup, /min-w-\[48px\]/, 'Touch target must specify min-w-[48px]');
// Accessible aria-label
assert.match(
buttonMarkup,
/aria-label="[^"]*WhatsApp[^"]*"/i,
'Button must have an accessible aria-label mentioning WhatsApp',
);
// Crisp SVG WhatsApp icon (no emoji placeholder)
assert.ok(buttonMarkup.includes('<svg'), 'Floating button must contain an inline SVG icon');
assert.ok(!buttonMarkup.includes('💬'), 'Floating button must not use emoji 💬');
// New tab target
assert.match(
buttonMarkup,
/target="_blank"/i,
'Floating WhatsApp button must open in a new tab (target="_blank")',
);
assert.match(
buttonMarkup,
/rel="noopener noreferrer"/i,
'Floating WhatsApp button must include rel="noopener noreferrer"',
);
},
);
await t.test(
'Criterion 4: Natural lifestyle portrait photo used in Hero with descriptive alt text',
() => {
const heroSection = indexHtml.match(/<section id="hero"[\s\S]*?<\/section>/)?.[0];
assert.ok(heroSection, 'Hero section must exist');
const imgMatch = heroSection.match(/<img[^>]+src="([^"]+)"[^>]*>/i);
assert.ok(imgMatch, 'Hero must contain an image tag');
const src = imgMatch[1];
assert.equal(
src,
'/img/azu-hero.jpg',
'Hero must use natural lifestyle photo /img/azu-hero.jpg',
);
assert.ok(
!heroSection.includes('turban') && !heroSection.includes('turbante'),
'Turban photo must not be used or referenced in Hero',
);
// Descriptive alt text
const altMatch = imgMatch[0].match(/alt="([^"]*)"/i);
assert.ok(altMatch, 'Hero image must have alt attribute');
assert.ok(
altMatch[1].length >= 15 && altMatch[1].toLowerCase().includes('azucena'),
'Alt text must be descriptive and identify Azucena',
);
},
);
await t.test(
'Criterion 5: Zero personal or secondary phone numbers in rendered markup or scripts',
() => {
// Find all phone number sequences
// Colombian mobile phone numbers are 10 digits starting with 3 (e.g. 321 542 8972)
// or international format +57... / 573215428972
const phoneMatches = indexHtml.matchAll(/(?:\+?57)?[ -]?(3\d{2}[ -]?\d{3}[ -]?\d{4})/g);
for (const match of phoneMatches) {
const rawDigits = match[0].replace(/\D/g, '');
const normalized = rawDigits.startsWith('57') ? rawDigits : `57${rawDigits}`;
assert.equal(
normalized,
'573215428972',
`Found unexpected phone number: ${match[0]} (only 573215428972 allowed)`,
);
}
},
);
await t.test(
'Criterion 6: Grounded problem-identification narrative ("Esto es lo que necesito" hook)',
() => {
const heroSection = indexHtml.match(/<section id="hero"[\s\S]*?<\/section>/)?.[0];
assert.ok(heroSection, 'Hero section must exist');
const lowerHero = heroSection.toLowerCase();
// Autopilot
assert.ok(
lowerHero.includes('automático') || lowerHero.includes('automatico'),
'Hero must speak directly to chronic autopilot',
);
// Mental chatter / overthinking
assert.ok(
lowerHero.includes('parloteo mental'),
'Hero must speak directly to mental chatter ("parloteo mental")',
);
// Nervous system fatigue
assert.ok(
lowerHero.includes('sistema nervioso'),
'Hero must speak directly to nervous system fatigue',
);
// Opening heart
assert.ok(
lowerHero.includes('abre tu corazón') || lowerHero.includes('abrir tu corazón'),
'Hero must speak to opening the heart',
);
},
);
});