015e18ff96
WritingView passed chapter.doc.content (a bare ProseMirror node array)
as the editor content, which made EditorState.create build a doc node
with an undefined type, throwing 'Cannot read properties of undefined
(reading schema)' and unmounting the write view. Pass the full doc
object ({ type: 'doc', content }) on init and on setContent sync.
Add editor regression tests covering schema instantiation, node
registration, and doc-content round-trip.
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
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();
|
|
});
|
|
});
|