/* Adding a row at the gate, and what shape it arrives in. The editor could delete and could not add, which makes the gate a place to cut a design down and never to correct it - and a محور the reader left out is as wrong as one they did not want. The shape matters as much as the button. A new chapter added as a bare title reaches the next step missing every field that step reads, so it is built from the rows already beside it: same keys, emptied. */ import { describe, expect, it } from "vitest"; import { blankLike } from "./BlueprintReview"; /** `blankLike` returns the editor's own `Json`, which is `unknown`. */ const row = (value: unknown) => value as Record; const CHAPTERS = [ { chapter_title: "الفصل الأول", outcome: "أن يميّز القارئ بين الأتمتة والمساعدة", sections: [{ title: "محور", subsections: [] }], }, ]; describe("blankLike", () => { it("gives a new row every field its siblings have", () => { expect(Object.keys(row(blankLike(CHAPTERS, 1))).sort()).toEqual( ["chapter_title", "outcome", "sections"].sort(), ); }); it("empties the text rather than copying it", () => { const made = row(blankLike(CHAPTERS, 1)); expect(made.chapter_title).toBe(""); expect(made.outcome).toBe(""); }); it("starts nested lists empty, not shared with the row it copied", () => { const made = row(blankLike(CHAPTERS, 1)); expect(made.sections).toEqual([]); expect(made.sections).not.toBe(CHAPTERS[0].sections); }); it("carries on a number that counts the row", () => { const days = [{ day_number: 1, sessions: [] }]; expect(row(blankLike(days, 1)).day_number).toBe(2); expect(row(blankLike(days, 4)).day_number).toBe(5); }); it("zeroes a number that measures rather than counts", () => { const subs = [{ title: "موضوع", est_pages: 3 }]; expect(row(blankLike(subs, 1)).est_pages).toBe(0); }); it("adds a string to a list of strings", () => { expect(blankLike(["موضوع أول", "موضوع ثان"], 2)).toBe(""); }); it("adds a string to an empty list, having nothing to copy", () => { expect(blankLike([], 0)).toBe(""); }); it("reads the shape past a stray string in a list of objects", () => { const mixed = ["نص خام", { title: "محور", subsections: [] }]; expect(Object.keys(row(blankLike(mixed, 2))).sort()).toEqual([ "subsections", "title", ]); }); });