75 lines · 4.1 KB · TypeScriptRaw
/** * Home's fan deals the tools that hold no rows after Settings, in the kit's * order, and a tool with rows keeps its place (owner, 26 Oct 2026). The * object decides — it holds every row — and says so on the home board it * serves; the phone deals what it is served. */import { describe, expect, it } from "vitest";import { emptyTools, tablesOf, withEmpty } from "../src/fan.ts";import { PERSONAL } from "../src/kits.ts";import { served } from "../src/retired.ts";// As the object is laid: without the tools held as retired (TABLE DROP 1).const KIT_TOOLS = served(PERSONAL).tools;import { http, personalObject, TODOS_OPEN, PEOPLE_OPEN } from "./personal.ts";type Doc = Record<string, unknown>;type Defs = { boards: Doc[] };const toolsPart = (home: Doc): Doc => (home.parts as Doc[]).find((p) => p.kind === "tools")!;describe("the home board a personal object serves", () => { const SLUG = "fan-empty"; it("names every kit tool whose tables hold no rows as empty, in the kit's order, and drops one once it holds a row", async () => { const { credential } = await personalObject(SLUG, { open: [...TODOS_OPEN, ...PEOPLE_OPEN.open] }); const auth = { authorization: `Bearer ${credential}` }; const first = (await http<Defs>(SLUG, "GET", "/v1/definitions", undefined, auth)).body; const empty = toolsPart(first.boards.find((b) => b.id === "home")!).empty as string[]; const order = KIT_TOOLS.map((t) => String(t.id)); // A new object holds one thing: its owner, a person with their phone (src/owner.ts). const holdsOwner = (id: string): boolean => tablesOf(KIT_TOOLS.find((t) => t.id === id)!).some((t) => t === "person" || t === "person_handle"); expect(empty, "a new object's kit tools hold nothing but the owner").toEqual(order.filter((id) => tablesOf(KIT_TOOLS.find((t) => t.id === id)!).length > 0 && !holdsOwner(id))); expect(empty.includes("people")).toBe(false); expect(empty.includes("todos")).toBe(true); const made = await http(SLUG, "POST", "/v1/act", { act: "create", args: { table: "todo", data: { title: "the first" } } }, auth); expect(made.status, JSON.stringify(made.body)).toBe(200); const after = (await http<Defs>(SLUG, "GET", "/v1/definitions", undefined, auth)).body; const now = toolsPart(after.boards.find((b) => b.id === "home")!).empty as string[]; // The row fills every tool that reads `todo`: Todos, and Meetings, whose actions are todos. const readsTodo = (id: string): boolean => tablesOf(KIT_TOOLS.find((t) => t.id === id)!).includes("todo"); expect(now).toEqual(empty.filter((id) => !readsTodo(id))); expect(empty.filter(readsTodo)).toContain("todos"); });});describe("which tools are empty", () => { const tools = [ { id: "personal", tables: ["a"] }, { id: "b", tables: ["b"] }, { id: "a", tables: ["a"], views: [{ read: { table: "c" } }] }, { id: "z", tables: ["z"] }, { id: "none", tables: [] }, ]; it("is every card tool whose every table holds nothing, the kit's first, then by id", () => { const rows = new Set(["c"]); expect(emptyTools(tools, ["b", "a"], (t) => t.id !== "personal", (t) => rows.has(t))).toEqual(["b", "z"]); expect(emptyTools(tools, ["z", "b"], (t) => t.id !== "personal", () => false)).toEqual(["z", "b", "a"]); }); it("is said on a whole board's tools part, and as a change on a board kept as changes", () => { const whole = { id: "home", parts: [{ kind: "head" }, { kind: "tools", size: "large" }] }; expect(withEmpty(whole, ["b"])).toEqual({ id: "home", parts: [{ kind: "head" }, { kind: "tools", size: "large", empty: ["b"] }] }); const overlay = { id: "home", board_overlay: 2, changes: { fields: { picture: { value: "object-x" } }, removed: [] }, dropped: [] }; expect(withEmpty(overlay, ["b"])).toEqual({ id: "home", board_overlay: 2, changes: { fields: { picture: { value: "object-x" }, parts: { items: { tools: { fields: { empty: { value: ["b"] } }, removed: [] } }, removed: [] } }, removed: [] }, dropped: [], }); expect(withEmpty({ ...overlay, dropped: ["tools"] }, ["b"])).toEqual({ ...overlay, dropped: ["tools"] }); });});