Editor_test.res.mjs

  1// Generated by ReScript, PLEASE EDIT WITH CARE
  2
  3import * as Yjs from "yjs";
  4import * as Editor from "../src/ui/Editor.res.mjs";
  5import * as Tiptap from "../src/ffi/Tiptap.res.mjs";
  6import * as Vitest from "vitest";
  7import * as Core from "@tiptap/core";
  8import * as React from "@tiptap/react";
  9import * as Signals from "@preact/signals";
 10import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
 11import * as JsxRuntime from "preact/jsx-runtime";
 12import * as Menus from "@tiptap/react/menus";
 13
 14function Editor_test$TestInsertComponent(props) {
 15  let editor = props.editor;
 16  return JsxRuntime.jsx("button", {
 17    children: "Insert Content",
 18    className: "insert-btn",
 19    onClick: param => {
 20      let paragraphContent = JSON.parse(`{"type":"paragraph","content":[{"type":"text","text":"Inserted text"}]}`);
 21      editor.commands.insertContent(paragraphContent);
 22    }
 23  });
 24}
 25
 26let TestInsertComponent = {
 27  make: Editor_test$TestInsertComponent
 28};
 29
 30function Editor_test$TestUpdateComponent(props) {
 31  let editor = props.editor;
 32  return JsxRuntime.jsx("button", {
 33    children: "Update Content",
 34    className: "update-btn",
 35    onClick: param => {
 36      let newContent = JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Updated content"}]}]}`);
 37      editor.commands.setContent(newContent);
 38    }
 39  });
 40}
 41
 42let TestUpdateComponent = {
 43  make: Editor_test$TestUpdateComponent
 44};
 45
 46Vitest.describe("TipTap Editor Integration", () => {
 47  Vitest.test("should render editor with initial content", async t => {
 48    let editor = new Core.Editor({
 49      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
 50      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Initial content"}]}]}`)
 51    });
 52    t.expect(editor).toEqual(editor);
 53    t.expect(editor.isEditable).toEqual(true);
 54    t.expect(editor.isEmpty).toEqual(true);
 55  });
 56  Vitest.test("should get content as JSON", async t => {
 57    let editor = new Core.Editor({
 58      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
 59      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Test content"}]}]}`)
 60    });
 61    let json = editor.getJSON();
 62    t.expect(json).toEqual(json);
 63  });
 64  Vitest.test("should update content via setContent", async t => {
 65    let editor = new Core.Editor({
 66      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
 67      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Initial"}]}]}`)
 68    });
 69    let newContent = JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Updated"}]}]}`);
 70    editor.commands.setContent(newContent);
 71    t.expect().toEqual();
 72    t.expect(editor.isEditable).toEqual(true);
 73  });
 74  Vitest.test("should insert content at current position", async t => {
 75    let editor = new Core.Editor({
 76      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
 77      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Hello"}]}]}`)
 78    });
 79    let insertContent = JSON.parse(`{"type":"text","text":" World"}`);
 80    editor.commands.insertContent(insertContent);
 81    t.expect().toEqual();
 82  });
 83  Vitest.test("should insert content at specific position", async t => {
 84    let editor = new Core.Editor({
 85      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
 86      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"AB"}]}]}`)
 87    });
 88    let insertContent = JSON.parse(`{"type":"text","text":"X"}`);
 89    editor.commands.insertContentAt(1, insertContent);
 90    t.expect().toEqual();
 91  });
 92  Vitest.test("should handle editor lifecycle (destroy)", async t => {
 93    let editor = new Core.Editor({
 94      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
 95      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph"}]}`)
 96    });
 97    t.expect(editor.isDestroyed).toEqual(false);
 98    editor.destroy();
 99    t.expect(editor.isDestroyed).toEqual(true);
100  });
101});
102
103Vitest.describe("Editor Component Integration", () => {
104  Vitest.test("should render Editor component with Content", async t => {
105    let disabled = Signals.signal(false);
106    let component = JsxRuntime.jsx(Editor.make, {
107      doc: "test-doc-1",
108      children: JsxRuntime.jsx(React.Tiptap.Content, {}),
109      disabled: Primitive_option.some(disabled)
110    });
111    t.expect(component).toEqual(component);
112  });
113  Vitest.test("should render Editor with BubbleMenu", async t => {
114    let disabled = Signals.signal(false);
115    let component = JsxRuntime.jsxs(Editor.make, {
116      doc: "test-doc-2",
117      children: [
118        JsxRuntime.jsx(React.Tiptap.Content, {}),
119        JsxRuntime.jsx(Menus.BubbleMenu, {
120          options: {
121            strategy: "fixed",
122            placement: "top",
123            offset: {
124              TAG: "Pixels",
125              _0: 10
126            }
127          },
128          children: JsxRuntime.jsx("button", {
129            children: "Bold"
130          })
131        })
132      ],
133      disabled: Primitive_option.some(disabled)
134    });
135    t.expect(component).toEqual(component);
136  });
137  Vitest.test("should render Editor with FloatingMenu", async t => {
138    let disabled = Signals.signal(false);
139    let component = JsxRuntime.jsxs(Editor.make, {
140      doc: "test-doc-3",
141      children: [
142        JsxRuntime.jsx(React.Tiptap.Content, {}),
143        JsxRuntime.jsx(Menus.FloatingMenu, {
144          options: {
145            placement: "left-start"
146          },
147          children: JsxRuntime.jsx("button", {
148            children: "Heading"
149          })
150        })
151      ],
152      disabled: Primitive_option.some(disabled)
153    });
154    t.expect(component).toEqual(component);
155  });
156});
157
158Vitest.describe("Full Editor Workflow", () => {
159  Vitest.test("complete workflow: create -> set -> insert -> verify", async t => {
160    let editor = new Core.Editor({
161      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
162      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Start"}]}]}`)
163    });
164    t.expect(editor.isEditable).toEqual(true);
165    let content1 = JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"First update"}]}]}`);
166    editor.commands.setContent(content1);
167    t.expect().toEqual();
168    let content2 = JSON.parse(`{"type":"text","text":" + insert"}`);
169    editor.commands.insertContent(content2);
170    t.expect().toEqual();
171    t.expect(editor.isEmpty).toEqual(false);
172    t.expect(editor.isDestroyed).toEqual(false);
173    let json = editor.getJSON();
174    t.expect(json).toEqual(json);
175    editor.commands.focus();
176    t.expect().toEqual();
177    editor.commands.blur();
178    t.expect().toEqual();
179    editor.setEditable(false);
180    t.expect(editor.isEditable).toEqual(false);
181    editor.setEditable(true);
182    t.expect(editor.isEditable).toEqual(true);
183    editor.destroy();
184    t.expect(editor.isDestroyed).toEqual(true);
185  });
186  Vitest.test("child component can access and modify editor", async t => {
187    let disabled = Signals.signal(false);
188    let editor = new Core.Editor({
189      extensions: Tiptap.extensions(new Yjs.Doc(), "test"),
190      content: JSON.parse(`{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Initial"}]}]}`)
191    });
192    let testComponent = JsxRuntime.jsxs(Editor.make, {
193      doc: "test-doc-4",
194      children: [
195        JsxRuntime.jsx(Editor_test$TestInsertComponent, {
196          editor: editor
197        }),
198        JsxRuntime.jsx(Editor_test$TestUpdateComponent, {
199          editor: editor
200        })
201      ],
202      disabled: Primitive_option.some(disabled)
203    });
204    t.expect(testComponent).toEqual(testComponent);
205  });
206});
207
208Vitest.describe("Editor Waypoint Search Integration", () => {
209  Vitest.test("Editor renders correctly", async t => {
210    let disabled = Signals.signal(false);
211    let component = JsxRuntime.jsx(Editor.make, {
212      doc: "test-doc-waypoint-1",
213      children: JsxRuntime.jsx(React.Tiptap.Content, {}),
214      disabled: Primitive_option.some(disabled)
215    });
216    t.expect(component).toEqual(component);
217  });
218  Vitest.test("Editor renders WaypointSearch when search is active", async t => {
219    let disabled = Signals.signal(false);
220    let component = JsxRuntime.jsx(Editor.make, {
221      doc: "test-doc-waypoint-2",
222      children: JsxRuntime.jsx(React.Tiptap.Content, {}),
223      disabled: Primitive_option.some(disabled)
224    });
225    t.expect(component).toEqual(component);
226  });
227  Vitest.test("Editor works correctly", async t => {
228    let disabled = Signals.signal(false);
229    let component = JsxRuntime.jsx(Editor.make, {
230      doc: "test-doc-waypoint-3",
231      children: JsxRuntime.jsx(React.Tiptap.Content, {}),
232      disabled: Primitive_option.some(disabled)
233    });
234    t.expect(component).toEqual(component);
235  });
236  Vitest.test("Editor component structure includes search integration", async t => {
237    let disabled = Signals.signal(false);
238    let component = JsxRuntime.jsxs(Editor.make, {
239      doc: "test-doc-waypoint-4",
240      children: [
241        JsxRuntime.jsx(React.Tiptap.Content, {}),
242        JsxRuntime.jsx(Menus.BubbleMenu, {
243          children: JsxRuntime.jsx("button", {
244            children: "Bold"
245          })
246        })
247      ],
248      disabled: Primitive_option.some(disabled)
249    });
250    t.expect(component).toEqual(component);
251  });
252});
253
254export {
255  TestInsertComponent,
256  TestUpdateComponent,
257}
258/*  Not a pure module */