Repository Public
1import { describe, expect, it } from "vitest";2import { en } from "@/lib/dict/en";3import { fr } from "@/lib/dict/fr";4import { switchLocalePath } from "@/lib/i18n";5import { mailtoHref, requestBody } from "@/lib/mailto";6import { accessRequestSchema, benchmarkSchema } from "@/lib/schemas";78const shape = (o: unknown): unknown => (Array.isArray(o) ? o.map(shape) : o && typeof o === "object" ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, shape(v)])) : typeof o);9const strings = (o: unknown): string[] => (typeof o === "string" ? [o] : o && typeof o === "object" ? Object.values(o).flatMap(strings) : []);1011describe("dictionaries", () => {12 it("French mirrors the English structure exactly", () => {13 expect(shape(fr)).toEqual(shape(en));14 });15 it("French is a real translation, not a copy", () => {16 const e = strings(en).filter((s) => s.length > 40);17 const f = new Set(strings(fr));18 expect(e.filter((s) => f.has(s))).toEqual([]);19 });20 it("makes no commercial or availability promise", () => {21 for (const s of [...strings(en), ...strings(fr)]) expect(s).not.toMatch(/\b(pricing|subscribe|99\.9|24\/7|guaranteed uptime|world[- ]class|revolutionary)\b/i);22 });23});2425describe("locale switch", () => {26 it("keeps the current page", () => {27 expect(switchLocalePath("/en/nodes/node-03", "fr")).toBe("/fr/nodes/node-03");28 expect(switchLocalePath("/fr", "en")).toBe("/en");29 expect(switchLocalePath("/en/access", "fr")).toBe("/fr/access");30 });31});3233describe("access request", () => {34 const valid = { name: "Ada Lovelace", email: "ada@example.org", projectTitle: "Reproducing a result", researchQuestion: "Does the published speed-up hold on M4 Max hardware?", compute: "One node, 64 GB, MLX, two days" };35 it("accepts a minimal valid request and rejects incomplete ones", () => {36 expect(accessRequestSchema.safeParse(valid).success).toBe(true);37 expect(accessRequestSchema.safeParse({ ...valid, email: "nope" }).success).toBe(false);38 expect(accessRequestSchema.safeParse({ ...valid, researchQuestion: "short" }).success).toBe(false);39 });40 it("rejects a filled honeypot", () => {41 expect(accessRequestSchema.safeParse({ ...valid, website: "http://spam" }).success).toBe(false);42 });43 it("builds a structured mailto with only the filled fields", () => {44 const body = requestBody(accessRequestSchema.parse(valid), en.access.form);45 expect(body).toContain("Ada Lovelace");46 expect(body).not.toContain(en.access.form.dates);47 const href = mailtoHref("someone@example.org", "Subject & more", body);48 expect(href.startsWith("mailto:someone@example.org?subject=Subject%20%26%20more&body=")).toBe(true);49 });50});5152describe("benchmark observation", () => {53 it("is rejected when measurement context is missing", () => {54 expect(benchmarkSchema.safeParse({ id: "x", nodeId: "node-01", metric: "tokens_per_second", value: 42 }).success).toBe(false);55 });56});57