mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
One loop, raea goal: every rule in TypeScript, held at edit, render, publish and done (goal check, tasks, judge, seen, gates, next); the brief's contract is goal: (one goal or a list, a workflow inline), and its plan is plan:. raea make is making a finished asset: character, clothes, motion, solid, wear, splat, physics, bake, sounds, component, the kit pipeline and shots. Instruments (check, judge, ask, world, scene faults, light check) stay top-level. With it: the montage pack (MK48-MK51), JavaScriptCore fixes raea goal needs (CommonJS named exports, reserved words too, dynamic import of file URLs, process.exit from a promise, stdin for -), raea-cli-goal and raea-cli-refused split out of raea-cli, and skills at raea-skills 105aede.
61 lines
3.0 KiB
TypeScript
61 lines
3.0 KiB
TypeScript
// 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(<TaskLine task={p.entries[1]} onToggle={() => {}} />)
|
|
expect(html).toContain('data-task="t-rome"')
|
|
expect(html).toContain('role="checkbox" aria-checked="false"')
|
|
expect(html).toContain('<span data-part="priority">A</span>')
|
|
expect(html).toContain('<span data-part="text">Rome storyboard</span>')
|
|
expect(html).toContain('<span data-part="progress">0/1</span>')
|
|
expect(renderToStaticMarkup(<TaskLine task={p.entries[0]} />)).not.toContain("checkbox")
|
|
})
|
|
|
|
test("the outline nests, the board has its lanes, the agenda its days", () => {
|
|
const p = readPlan(TEXT)
|
|
const outline = renderToStaticMarkup(<PlanOutline plan={p} />)
|
|
expect(outline.indexOf("The forum")).toBeGreaterThan(outline.indexOf("Rome storyboard"))
|
|
expect(outline.match(/<ul/g)!.length).toBe(3)
|
|
const board = renderToStaticMarkup(<BoardLanes plan={p} labels={{ todo: "Next" }} />)
|
|
expect(board).toMatch(/data-state="todo"><h3>Next <span data-part="count">2<\/span>/)
|
|
expect(board).toMatch(/data-state="done"><h3>Done <span data-part="count">1<\/span>/)
|
|
const agenda = renderToStaticMarkup(<Agenda plan={p} from="2026-11-14" days={2} />)
|
|
expect(agenda).toMatch(/data-date="2026-11-14"><h3>2026-11-14<\/h3><ul><li data-why="deadline">.*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<typeof usePlan> | undefined
|
|
const Probe = () => {
|
|
seen = usePlan(src)
|
|
return null
|
|
}
|
|
renderToStaticMarkup(<Probe />)
|
|
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(<Probe />)
|
|
expect(seen!.plan.tasks[1].state).toBe("done")
|
|
const Fixed = () => {
|
|
seen = usePlan(value(TEXT))
|
|
return null
|
|
}
|
|
renderToStaticMarkup(<Fixed />)
|
|
expect(() => seen!.edit([])).toThrow(/read-only/)
|
|
})
|
|
})
|