fix(web): pass full ProseMirror doc to editor, not bare array
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.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// @vitest-environment jsdom
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { getSchema } from "@tiptap/core";
|
||||
import { pubScriptExtensions, PubScriptSchema, createPubScriptEditor } from "@pubscript/editor";
|
||||
|
||||
describe("editor schema + instantiation", () => {
|
||||
it("getSchema returns valid schema", () => {
|
||||
console.log("PubScriptSchema nodes:", PubScriptSchema ? Object.keys(PubScriptSchema.nodes).join(",") : "UNDEFINED");
|
||||
console.log("PubScriptSchema marks:", PubScriptSchema ? Object.keys(PubScriptSchema.marks).join(",") : "UNDEFINED");
|
||||
expect(PubScriptSchema).toBeTruthy();
|
||||
expect(PubScriptSchema.nodes.sceneBreak).toBeTruthy();
|
||||
expect(PubScriptSchema.nodes.footnote).toBeTruthy();
|
||||
expect(PubScriptSchema.nodes.footnoteArea).toBeTruthy();
|
||||
expect(PubScriptSchema.nodes.characterMention).toBeTruthy();
|
||||
});
|
||||
|
||||
it("getSchema(pubScriptExtensions) matches PubScriptSchema", () => {
|
||||
const s = getSchema(pubScriptExtensions);
|
||||
console.log("inline getSchema nodes:", Object.keys(s.nodes).join(","));
|
||||
expect(s).toBeTruthy();
|
||||
});
|
||||
|
||||
it("createPubScriptEditor does not throw", () => {
|
||||
let editor;
|
||||
try {
|
||||
editor = createPubScriptEditor();
|
||||
console.log("editor created, schema defined:", !!editor?.schema);
|
||||
console.log("editor doc type:", editor?.state?.doc?.type?.name);
|
||||
} catch (e) {
|
||||
console.log("createPubScriptEditor THREW:", (e as Error).message);
|
||||
throw e;
|
||||
}
|
||||
expect(editor).toBeTruthy();
|
||||
expect(editor.schema).toBeTruthy();
|
||||
expect(editor.state.doc.type).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user