@devries-cameron20 / OCIU-npo Mirror · read-only / commits / d282e74
Fork 0

Mirrored from https://github.com/Camo67/OCIU-npo.git

Synced Nov 21, 03:37 UTC

Add static regression tests for Hero CTA navigation

Dependency-free source checks only. These tests do not render React or establish browser behavior; production build and real desktop/mobile clicks were checked separately.

Cameron “Camo” De Vries committed Nov 9, 2026 at 16:47 UTC d282e74d547700dfb09811b8c5d6c9977855e4d8
1 file changed +246
tests/tests/tion.test.mjshero-cta-naviga new
+246
@@ -0,0 +1,246 @@
1 +/**
2 + * STATIC source-level regression checks for the Hero CTA navigation fix.
3 + *
4 + * Scope and honesty boundary:
5 + * - These checks read the two supplied source files as text and assert on their
6 + * structure. They do NOT render React, do NOT run a DOM, do NOT open a browser,
7 + * and do NOT prove runtime, visual or mobile behaviour.
8 + * - Dependency-free on purpose: only Node.js built-ins (node:test, node:assert,
9 + * node:fs, node:path). No install, no network, no external packages.
10 + *
11 + * Run with: node --test tests/hero-cta-navigation.test.mjs
12 + */
13 +
14 +import { test, describe } from "node:test";
15 +import assert from "node:assert/strict";
16 +import { readFileSync } from "node:fs";
17 +import { fileURLToPath } from "node:url";
18 +import path from "node:path";
19 +
20 +const PROJECT_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
21 +const HERO_PATH = path.join(PROJECT_ROOT, "src/components/Hero.tsx");
22 +const INDEX_PATH = path.join(PROJECT_ROOT, "src/pages/Index.tsx");
23 +
24 +const heroSource = readFileSync(HERO_PATH, "utf8");
25 +const indexSource = readFileSync(INDEX_PATH, "utf8");
26 +
27 +/** All literal `id="..."` values declared in a JSX source file. */
28 +function declaredIds(source) {
29 + return [...source.matchAll(/\bid="([^"]*)"/g)].map((match) => match[1]);
30 +}
31 +
32 +/** All `<Button ...>...</Button>` elements, split into attribute string and body. */
33 +function buttonElements(source) {
34 + return [...source.matchAll(/<Button\b([^>]*)>([\s\S]*?)<\/Button>/g)].map((match) => ({
35 + attrs: match[1],
36 + body: match[2],
37 + raw: match[0],
38 + }));
39 +}
40 +
41 +/** First opening `<a ...>` tag found inside a JSX fragment, or null. */
42 +function firstAnchor(fragment) {
43 + const match = fragment.match(/<a\b([^>]*)>/);
44 + return match ? { attrs: match[1], raw: match[0] } : null;
45 +}
46 +
47 +const INDEX_IDS = declaredIds(indexSource);
48 +const HERO_IDS = declaredIds(heroSource);
49 +const CTAS = buttonElements(heroSource);
50 +
51 +/** Look up one CTA by its visible label, failing loudly if it is missing. */
52 +function ctaFor(label) {
53 + const found = CTAS.filter((cta) => cta.body.includes(label));
54 + assert.equal(
55 + found.length,
56 + 1,
57 + `Expected exactly one <Button> containing the label "${label}" in ${HERO_PATH}, found ${found.length}.`,
58 + );
59 + return found[0];
60 +}
61 +
62 +describe("Hero CTA navigation (static source checks)", () => {
63 + test("Hero still renders exactly the two intended CTA buttons", () => {
64 + assert.equal(
65 + CTAS.length,
66 + 2,
67 + `Expected 2 <Button> CTAs in Hero.tsx, found ${CTAS.length}. This check guards against extra or removed CTAs.`,
68 + );
69 + });
70 +
71 + test("Get Involved CTA is an anchor pointing at the existing #join section", () => {
72 + const cta = ctaFor("Get Involved");
73 + const anchor = firstAnchor(cta.body);
74 +
75 + assert.ok(anchor, '"Get Involved" CTA renders no <a> element, so it cannot navigate.');
76 + assert.match(
77 + anchor.attrs,
78 + /\bhref="#join"/,
79 + `"Get Involved" anchor must have href="#join"; found: <a${anchor.attrs}>. Index.tsx declares ids: ${JSON.stringify(INDEX_IDS)}.`,
80 + );
81 + assert.ok(
82 + INDEX_IDS.includes("join"),
83 + `"#join" target id is not declared in ${INDEX_PATH}; declared ids: ${JSON.stringify(INDEX_IDS)}.`,
84 + );
85 + });
86 +
87 + test("Explore Our Work CTA is an anchor pointing at the existing #mission section", () => {
88 + const cta = ctaFor("Explore Our Work");
89 + const anchor = firstAnchor(cta.body);
90 +
91 + assert.ok(anchor, '"Explore Our Work" CTA renders no <a> element, so it cannot navigate.');
92 + assert.match(
93 + anchor.attrs,
94 + /\bhref="#mission"/,
95 + `"Explore Our Work" anchor must have href="#mission"; found: <a${anchor.attrs}>. Index.tsx declares ids: ${JSON.stringify(INDEX_IDS)}.`,
96 + );
97 + assert.ok(
98 + INDEX_IDS.includes("mission"),
99 + `"#mission" target id is not declared in ${INDEX_PATH}; declared ids: ${JSON.stringify(INDEX_IDS)}.`,
100 + );
101 + });
102 +
103 + test("both CTAs delegate their styling to Button via asChild (Button stays the styling owner)", () => {
104 + for (const label of ["Get Involved", "Explore Our Work"]) {
105 + const cta = ctaFor(label);
106 + assert.match(
107 + cta.attrs,
108 + /(^|\s)asChild(\s|$|=)/,
109 + `"${label}" <Button> is missing the asChild prop, so the anchor would nest inside a <button> instead of replacing it (invalid, inaccessible nesting).`,
110 + );
111 + }
112 + });
113 +
114 + test("the anchor is the direct child of Button, not a nested extra wrapper", () => {
115 + for (const label of ["Get Involved", "Explore Our Work"]) {
116 + const cta = ctaFor(label);
117 + assert.match(
118 + cta.body,
119 + /^\s*<a\b/,
120 + `In "${label}", the <a> must be the immediate child of <Button> for asChild to forward props/styles correctly.`,
121 + );
122 + }
123 + });
124 +
125 + test("anchor does not declare its own className, so Button styling is preserved", () => {
126 + for (const label of ["Get Involved", "Explore Our Work"]) {
127 + const anchor = firstAnchor(ctaFor(label).body);
128 + assert.ok(anchor, `"${label}" CTA has no anchor.`);
129 + assert.doesNotMatch(
130 + anchor.attrs,
131 + /\bclassName=/,
132 + `"${label}" anchor sets its own className, which would fight the Button variants. Styling must stay on <Button>.`,
133 + );
134 + }
135 + });
136 +
137 + test("Button sizing, variants and the 200px CTA width are unchanged", () => {
138 + const growth = ctaFor("Get Involved").attrs;
139 + const energy = ctaFor("Explore Our Work").attrs;
140 +
141 + for (const [label, attrs] of [
142 + ["Get Involved", growth],
143 + ["Explore Our Work", energy],
144 + ]) {
145 + assert.match(attrs, /\bsize="lg"/, `"${label}" lost size="lg".`);
146 + assert.match(attrs, /\bclassName="min-w-\[200px\]"/, `"${label}" lost className="min-w-[200px]".`);
147 + }
148 + assert.match(growth, /\bvariant="growth"/, '"Get Involved" lost variant="growth".');
149 + assert.match(energy, /\bvariant="energy"/, '"Explore Our Work" lost variant="energy".');
150 + });
151 +
152 + test("responsive CTA layout wrapper is unchanged", () => {
153 + assert.ok(
154 + heroSource.includes("flex flex-col sm:flex-row gap-4 justify-center items-center pt-8"),
155 + "The responsive CTA container classes changed; the column-on-mobile / row-on-desktop layout must be preserved.",
156 + );
157 + });
158 +
159 + test("the two CTAs target different, existing sections", () => {
160 + const joinHref = firstAnchor(ctaFor("Get Involved").body)?.attrs.match(/href="([^"]*)"/)?.[1];
161 + const missionHref = firstAnchor(ctaFor("Explore Our Work").body)?.attrs.match(/href="([^"]*)"/)?.[1];
162 +
163 + assert.ok(joinHref, '"Get Involved" has no href.');
164 + assert.ok(missionHref, '"Explore Our Work" has no href.');
165 + assert.notEqual(joinHref, missionHref, "Both CTAs point at the same fragment; they should lead to different sections.");
166 +
167 + for (const href of [joinHref, missionHref]) {
168 + assert.match(href, /^#[A-Za-z][\w-]*$/, `Fragment "${href}" is not a plain same-page id reference.`);
169 + assert.ok(
170 + INDEX_IDS.includes(href.slice(1)),
171 + `Fragment "${href}" has no matching id="..." in ${INDEX_PATH}; declared ids: ${JSON.stringify(INDEX_IDS)}.`,
172 + );
173 + }
174 + });
175 +
176 + test("every in-page fragment used by Hero resolves to a declared id", () => {
177 + const fragments = [...heroSource.matchAll(/\bhref="#([^"]*)"/g)].map((match) => match[1]);
178 + assert.ok(fragments.length >= 2, `Expected at least 2 in-page fragment links in Hero.tsx, found ${fragments.length}.`);
179 +
180 + const unresolved = fragments.filter((fragment) => !INDEX_IDS.includes(fragment));
181 + assert.deepEqual(
182 + unresolved,
183 + [],
184 + `Hero.tsx links to fragments with no declared target in ${INDEX_PATH}: ${JSON.stringify(unresolved)}.`,
185 + );
186 + });
187 +
188 + test("declared section ids in Index.tsx are unique", () => {
189 + const duplicates = INDEX_IDS.filter((id, position) => INDEX_IDS.indexOf(id) !== position);
190 + assert.deepEqual(duplicates, [], `Duplicate id="..." declarations in ${INDEX_PATH}: ${JSON.stringify(duplicates)}.`);
191 + });
192 +
193 + test("no inactive <button> CTA remains and no onclick handler was introduced", () => {
194 + assert.doesNotMatch(heroSource, /<button\b/, "Hero.tsx must not render a bare <button> CTA; navigation must be anchor-based.");
195 + assert.doesNotMatch(heroSource, /\bonClick\b/, "Hero.tsx must not use onClick scroll handlers for CTA navigation.");
196 + });
197 +
198 + test("decorative arrow icon inside the link is hidden from assistive tech", () => {
199 + const cta = ctaFor("Get Involved");
200 + if (!cta.body.includes("<ArrowRight")) {
201 + return; // icon removed by design; nothing to hide.
202 + }
203 + const icon = cta.body.match(/<ArrowRight\b([^>]*)\/?>/);
204 + assert.ok(icon, "ArrowRight usage could not be read.");
205 + assert.match(
206 + icon[1],
207 + /\baria-hidden="true"/,
208 + "The arrow icon sits inside the link text; mark it aria-hidden=\"true\" so the CTA is announced as its label only.",
209 + );
210 + });
211 +
212 + test("scope guards: no form, invented contacts, external URLs or tracking added", () => {
213 + for (const [label, pattern] of [
214 + ["a <form>", /<form\b/],
215 + ["a mailto: link", /mailto:/i],
216 + ["a tel: link", /tel:/i],
217 + ["an external http(s) URL", /https?:\/\//i],
218 + ["a payment/bank directive", /\b(iban|swift|account number|bank details)\b/i],
219 + ]) {
220 + assert.doesNotMatch(heroSource, pattern, `Hero.tsx must not add ${label} in this bounded navigation task.`);
221 + }
222 + });
223 +
224 + test("motto, tagline and headings were left untouched", () => {
225 + assert.ok(heroSource.includes("Learn, Build, Earn"), "The motto was changed; it is out of scope for this task.");
226 + assert.ok(
227 + heroSource.includes("Empowering communities to learn, build, and support community growth."),
228 + "The tagline was changed; it is out of scope for this task.",
229 + );
230 + assert.ok(
231 + heroSource.includes("Our Community in Unity (OCIU)"),
232 + "The hero heading was changed; it is out of scope for this task.",
233 + );
234 + });
235 +});
236 +
237 +describe("Supplied sources are the reviewed inputs", () => {
238 + test("Hero.tsx and Index.tsx are readable and non-empty", () => {
239 + assert.ok(heroSource.trim().length > 0, `${HERO_PATH} is empty.`);
240 + assert.ok(indexSource.trim().length > 0, `${INDEX_PATH} is empty.`);
241 + });
242 +
243 + test("Hero still declares no section ids of its own (targets live in Index.tsx)", () => {
244 + assert.deepEqual(HERO_IDS, [], `Hero.tsx unexpectedly declares ids: ${JSON.stringify(HERO_IDS)}.`);
245 + });
246 +});