@davoodmehraban89 / medusa / commits / ce67fb9e
Fork 0

test(preview): validate localized Pages output, market interactions, accessibility and zero external assets

davoodmehraban89 committed Oct 15, 2026 at 19:21 UTC ce67fb9e5e4f25d3a56300c459a08b2c6b1d0ff6
1 file changed +54
commerce/scripts/validate-static-preview.mjs new
+54
@@ -0,0 +1,54 @@
1 +import { readFileSync } from "node:fs"
2 +import { fileURLToPath } from "node:url"
3 +import assert from "node:assert/strict"
4 +
5 +const pages = [
6 + { file: "index.html", lang: "fa", dir: "rtl" },
7 + { file: "en.html", lang: "en", dir: "ltr" },
8 + { file: "ar.html", lang: "ar", dir: "rtl" },
9 +]
10 +
11 +const docs = new URL("../../docs/", import.meta.url)
12 +
13 +const occurrences = (text, expression) => [...text.matchAll(expression)].length
14 +
15 +for (const { file, lang, dir } of pages) {
16 + const html = readFileSync(fileURLToPath(new URL(file, docs)), "utf8")
17 +
18 + assert.match(html, /^<!doctype html><html /i, file + ": valid document start")
19 + assert.ok(html.includes(`<html lang="${lang}" dir="${dir}"`), file + ": language and direction")
20 + assert.ok(html.includes('name="viewport"'), file + ": mobile viewport")
21 + assert.ok(html.includes('name="robots" content="noindex,nofollow"'), file + ": preview must not be indexed")
22 + assert.ok(html.includes('class="skip"'), file + ": skip navigation")
23 + assert.equal(occurrences(html, /class="market-input"/g), 5, file + ": five independent markets")
24 + assert.equal(occurrences(html, /class="market-panel /g), 5, file + ": five market panels")
25 + assert.equal(occurrences(html, /class="card"/g), 24, file + ": category examples across the five panels")
26 + assert.equal(occurrences(html, /class="faq-item"/g), 4, file + ": four FAQs")
27 + assert.equal(occurrences(html, /class="languages"/g), 1, file + ": locale menu")
28 + assert.equal(occurrences(html, /href="\.\/(?:index|en|ar)\.html"/g), 3, file + ": all three translations")
29 + assert.equal(occurrences(html, /class="feature"/g), 3, file + ": three experience features")
30 + assert.equal(occurrences(html, /class="step"/g), 3, file + ": three delivery milestones")
31 + assert.equal(occurrences(html, /class="hero"/g), 1, file + ": accessible hero")
32 + assert.ok(html.includes('id="collections"') && html.includes('id="roadmap"') && html.includes('id="faq"'), file + ": required navigation destinations")
33 + assert.ok(html.includes('@media(max-width:420px)'), file + ": small-screen styling")
34 + assert.ok(html.includes('prefers-reduced-motion'), file + ": reduced motion support")
35 + assert.ok(html.includes('focus-visible'), file + ": keyboard focus indicator")
36 + assert.ok(html.includes('IRR') && html.includes('AED') && html.includes('OMR') && html.includes('IQD') && html.includes('QAR'), file + ": explicit market currencies")
37 + assert.doesNotMatch(html, /<(script|link|iframe|img)\b/i, file + ": zero external asset dependencies")
38 + assert.doesNotMatch(html, /https?:\/\//, file + ": no external network requests")
39 +
40 + for (const country of ["ir", "ae", "om", "iq", "qa"]) {
41 + assert.ok(html.includes(`id="market-${country}"`), file + ": radio " + country)
42 + assert.ok(html.includes(`for="market-${country}"`), file + ": label " + country)
43 + assert.ok(html.includes(`class="market-panel ${country}"`), file + ": panel " + country)
44 + }
45 +
46 + const iranStart = html.indexOf('class="market-panel ir"')
47 + const uaeStart = html.indexOf('class="market-panel ae"')
48 + const omanStart = html.indexOf('class="market-panel om"')
49 + assert.ok(iranStart >= 0 && uaeStart > iranStart && omanStart > uaeStart, file + ": country panel order")
50 + assert.equal(occurrences(html.slice(iranStart, uaeStart), /class="card"/g), 8, file + ": Iran's eight illustrative categories")
51 + assert.equal(occurrences(html.slice(uaeStart, omanStart), /class="card"/g), 4, file + ": UAE's four illustrative Iran-origin categories")
52 +
53 + process.stdout.write(`PASS ${file}: ${html.length} characters, 5 markets, 24 sample cards, 3 languages, 4 FAQs, no JS/external assets\n`)
54 +}