Repository Public
1import { describe, expect, it } from "vitest";2import { renderToStaticMarkup } from "react-dom/server";3import { BlockSchema, type BlockOf } from "@/schema";4import { DiagramEditor } from "@/components/editor/diagram/DiagramEditor";5import { T } from "@/components/editor/diagram/strings";6import { DIAGRAM } from "./renderer.fixture";78const block = BlockSchema.parse(DIAGRAM) as BlockOf<"diagram">;9const render = (locale: "fr" | "en") => renderToStaticMarkup(<DiagramEditor block={block} onChange={() => {}} locale={locale} theme={{ preset: "blueprint", accent: "teal" }} />);1011describe("DiagramEditor — static render", () => {12 it("draws the reader's diagram inside the sheet theme", () => {13 const html = render("fr");14 expect(html).not.toMatch(/undefined|NaN|\[object Object\]/);15 expect(html).toMatch(/<div class="sheet" data-theme="blueprint" data-accent="teal" tabindex="0" role="group"/);16 expect(html).toContain("touch-action:none");17 expect(html.match(/touch-action/g)).toHaveLength(1);18 for (const n of block.nodes) expect(html).toContain(`data-node-id="${n.id}"`);19 for (const e of block.edges) expect(html).toContain(`data-edge-id="${e.id}"`);20 });21 it("lists every node and edge in the layers panel, with the schema limits", () => {22 const html = render("fr");23 expect(html).toContain("Nœuds (8/60)"); expect(html).toContain("Liens (9/120)");24 expect(html).toContain("Légende (2/8)"); expect(html).toContain("Groupes (1/12)");25 expect(html).toContain("Entrée → Routeur");26 expect(html).toContain('maxLength="200"');27 });28 it("has every string in both languages", () => {29 const fr = T("fr"), en = T("en");30 for (const key of Object.keys(fr) as (keyof typeof fr)[]) { expect(fr[key], key).not.toBe(""); expect(en[key], key).not.toBe(""); }31 const html = render("en");32 for (const label of [en.toolSelect, en.toolPan, en.toolConnect, en.multi, en.addNode, en.delete, en.undo, en.redo, en.fit, en.zoomIn, en.zoomOut, en.shortcuts, en.layers, en.properties, en.steps, en.autoPlaceAll]) {33 expect(html, label).toContain(label.replace(/’/g, "’"));34 }35 expect(render("fr")).toContain("Ajuster à l’écran");36 });37});38