// PL6: the React side (src/react.tsx): a plan read from a source that changes, and the components drawn as plain // elements. Run by the app's vitest, which has react-dom (apps/app vite.config.ts test.include). import { renderToStaticMarkup } from "react-dom/server" import { describe, expect, test } from "vitest" import { Agenda, BoardLanes, memorySource, PlanOutline, TaskLine, toggled, usePlan } from "../src/react" import { readPlan as readValue } from "../src/model" import { readPlan, value } from "./text" const TEXT = `export default plan({ tasks: [{ title: "Act one", tasks: [ { id: "t-rome", keyword: "TODO", priority: "A", title: "Rome storyboard", tasks: [{ id: "t-forum", keyword: "TODO", title: "The forum", deadline: "2026-11-14" }] }, { keyword: "DONE", title: "Cast" }, ] }] })` describe("PL6: React", () => { test("TaskLine: a checkbox, the words, priority, progress, deadline; a heading has no checkbox", () => { const p = readPlan(TEXT) const html = renderToStaticMarkup( {}} />) expect(html).toContain('data-task="t-rome"') expect(html).toContain('role="checkbox" aria-checked="false"') expect(html).toContain('A') expect(html).toContain('Rome storyboard') expect(html).toContain('0/1') expect(renderToStaticMarkup()).not.toContain("checkbox") }) test("the outline nests, the board has its lanes, the agenda its days", () => { const p = readPlan(TEXT) const outline = renderToStaticMarkup() expect(outline.indexOf("The forum")).toBeGreaterThan(outline.indexOf("Rome storyboard")) expect(outline.match(/
    ) expect(board).toMatch(/data-state="todo">

    Next 2<\/span>/) expect(board).toMatch(/data-state="done">

    Done 1<\/span>/) const agenda = renderToStaticMarkup() expect(agenda).toMatch(/data-date="2026-11-14">

    2026-11-14<\/h3>
    • .*The forum/) }) test("usePlan reads a source and edits it by id; a plan value alone is read-only", () => { const src = memorySource(value(TEXT)) let seen: ReturnType | undefined const Probe = () => { seen = usePlan(src) return null } renderToStaticMarkup() expect(seen!.plan.tasks.length).toBe(3) seen!.edit([toggled(seen!.plan.tasks[1])]) expect(readValue(src.read()).tasks[1].state).toBe("done") expect(readValue(src.read()).tasks[0].progress).toEqual({ done: 1, total: 1 }) renderToStaticMarkup() expect(seen!.plan.tasks[1].state).toBe("done") const Fixed = () => { seen = usePlan(value(TEXT)) return null } renderToStaticMarkup() expect(() => seen!.edit([])).toThrow(/read-only/) }) })