| 1 | import { existsSync, readdirSync, readFileSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { siteCss } from "./site-css"; |
| 4 | |
| 5 | // The whale-road (codewhale-design/DIRECTION.md): one character drawn from |
| 6 | // the v2 kit, a footer on the page's own ground, and a header that stays |
| 7 | // usable in every locale. |
| 8 | const CSS = siteCss(); |
| 9 | const web = (path: string) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8"); |
| 10 | const POSES = [ |
| 11 | "rest", "listen", "think", "busy", "read", "search", "write", "run", "browse", |
| 12 | "talk", "pod", "needs", "done", "hmm", "sleep", "computer", "connect", |
| 13 | ]; |
| 14 | |
| 15 | describe("the whale", () => { |
| 16 | it("ships all seventeen v2 poses in the logo gradient", () => { |
| 17 | const dir = new URL("../public/whale/", import.meta.url); |
| 18 | expect(readdirSync(dir).filter((f) => f.endsWith(".svg")).sort()).toEqual(POSES.map((p) => `${p}.svg`).sort()); |
| 19 | for (const pose of POSES) { |
| 20 | const svg = readFileSync(new URL(`${pose}.svg`, dir), "utf8"); |
| 21 | expect(svg, pose).toContain('stop-color="#1E8FD8"'); |
| 22 | expect(svg, pose).toContain('stop-color="#0B48BB"'); |
| 23 | // A still pose: never animated. |
| 24 | expect(svg, pose).not.toMatch(/<animate|@keyframes/); |
| 25 | } |
| 26 | expect(web("components/whale-pose.tsx")).toContain(POSES.map((p) => `"${p}"`).join(",\n ")); |
| 27 | }); |
| 28 | |
| 29 | it("uses the mono mark as the site identity and the colored whale only as a character", () => { |
| 30 | const icon = web("app/icon.svg"); |
| 31 | expect(icon).toContain("prefers-color-scheme:dark"); |
| 32 | expect(icon).not.toContain("#1E8FD8"); |
| 33 | expect(icon).not.toMatch(/<rect/); |
| 34 | expect(web("app/manifest.ts")).not.toContain("#142352"); |
| 35 | for (const file of ["components/nav.tsx", "components/footer.tsx"]) { |
| 36 | expect(web(file), file).toContain("brand-mark"); |
| 37 | expect(web(file), file).not.toContain("WhalePose"); |
| 38 | } |
| 39 | expect(web("app/styles/shell.css")).toContain('mask: url("/brand/mark-mono.svg")'); |
| 40 | }); |
| 41 | |
| 42 | it("keeps the founder's 404 poster and seals", () => { |
| 43 | // The Codwhale poster is the 404 joke, restored on purpose (site merge plan R4). |
| 44 | expect(existsSync(new URL("../public/codwhale-404.webp", import.meta.url))).toBe(true); |
| 45 | expect(web("components/route-state.tsx")).toContain('src="/codwhale-404.webp"'); |
| 46 | expect(existsSync(new URL("../components/seal.tsx", import.meta.url))).toBe(true); |
| 47 | expect(existsSync(new URL("../components/install-binary.tsx", import.meta.url))).toBe(false); |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | describe("the footer", () => { |
| 52 | it("sits on the page's own ground under one hairline, with no navy band", () => { |
| 53 | const footer = web("components/footer.tsx"); |
| 54 | expect(footer).not.toMatch(/horizon|sea-texture|site-footer-sea|Strata/); |
| 55 | expect(CSS).toMatch(/\.site-footer \{[^}]*border-top: 1px solid var\(--line\);/); |
| 56 | expect(CSS).not.toMatch(/\.site-footer \{[^}]*background:/); |
| 57 | expect(CSS).not.toMatch(/site-footer-sea|sea-texture/); |
| 58 | expect(web("app/[locale]/page.tsx")).not.toContain("sea-continues"); |
| 59 | }); |
| 60 | |
| 61 | it("folds its four link groups into disclosures on a phone", () => { |
| 62 | const footer = web("components/footer.tsx"); |
| 63 | expect(footer).toContain('<details key={group.label} className="site-footer-fold"'); |
| 64 | expect(CSS).toMatch(/@media \(max-width: 640px\) \{\s*\.site-footer-links \{ display: none; \}\s*\.site-footer-folds \{ display: block; \}/); |
| 65 | }); |
| 66 | }); |
| 67 | |
| 68 | describe("the header", () => { |
| 69 | it("keeps localized navigation controls inside compact viewports", () => { |
| 70 | expect(CSS).toMatch(/@media \(max-width: 520px\) \{\s*\.site-nav-inner\s*\{\s*gap:\s*0\.5rem;\s*\}\s*\.site-nav-actions\s*\{\s*min-width:\s*0;/); |
| 71 | expect(CSS).toMatch(/\.site-nav-actions\s*\{[\s\S]*?flex-shrink:\s*0/); |
| 72 | expect(CSS).toMatch(/\.site-nav-actions\s*>\s*\*\s*\{\s*flex-shrink:\s*0/); |
| 73 | expect(CSS).toMatch(/@media \(max-width: 900px\)[\s\S]*?\.site-github-link\s*\{\s*display:\s*none/); |
| 74 | // The locale <select> sits inside the fixed icon box instead of sizing |
| 75 | // the row, and the wordmark keeps a clickable floor. |
| 76 | expect(CSS).not.toMatch(/\.site-nav-actions select/); |
| 77 | expect(CSS).toMatch(/\.nav-locale select\s*\{[^}]*position:\s*absolute;[^}]*inset:\s*0;/); |
| 78 | expect(CSS).toMatch(/\.paper-wordmark\s*\{[^}]*flex:\s*0 1 auto;[^}]*min-width:\s*8\.75rem;/); |
| 79 | }); |
| 80 | |
| 81 | it("re-inks the wordmark through the mark ink, never a filter", () => { |
| 82 | expect(CSS).toMatch(/\.paper-wordmark-logo,\s*\.wordmark\s*\{[^}]*background: var\(--mark-ink\);[^}]*mask: url\("\/brand\/wordmark\.svg"\)/); |
| 83 | expect(CSS).not.toMatch(/paper-wordmark-logo\s*\{\s*filter:/); |
| 84 | }); |
| 85 | }); |
| 86 |