import { describe, it, expect } from "vitest"; import { createPubScriptEditor } from "./schema.js"; /** Minimal full ProseMirror doc, mirroring a seeded chapter.doc. */ const fullDoc = { type: "doc", content: [ { type: "heading", attrs: { level: 1 }, content: [{ type: "text", text: "The Glass Harbor" }] }, { type: "paragraph", content: [{ type: "text", text: "Salt hung in the air." }] }, ], }; /** Bare array — the exact bug that crashed EditorState.create in the browser. */ const bareArray = fullDoc.content; describe("editor content parsing (regression: bare array vs full doc)", () => { it("builds an editor from a full doc object (the seeded chapter.doc shape)", () => { const editor = createPubScriptEditor({ content: fullDoc }); expect(editor).not.toBeNull(); expect(editor.state.doc.type.name).toBe("doc"); }); it("throws on a bare content array (documents the regression we fixed)", () => { expect(() => createPubScriptEditor({ content: bareArray })).toThrow(); }); });