Skip to content
File

Blob: tests/client/components/editor/extensions/post-drop-selection.test.ts

typescript41 lines
1import { describe, expect, it } from "vitest";
2import { TextSelection, NodeSelection } from "@tiptap/pm/state";
3import { schema } from "prosemirror-schema-basic";
4import { getMovedTextblockCursorPos } from "@/client/components/editor/lib/moved-textblock-selection";
5 
6describe("post-drop selection", () => {
7 it("returns a caret position inside dropped textblocks", () => {
8 const doc = schema.node("doc", null, [schema.node("paragraph", null, [schema.text("hello")])]);
9 
10 const selection = NodeSelection.create(doc, 0);
11 
12 expect(getMovedTextblockCursorPos(selection)).toBe(selection.to - 1);
13 });
14 
15 it("returns the only valid cursor position for empty paragraphs", () => {
16 const doc = schema.node("doc", null, [schema.node("paragraph")]);
17 
18 const selection = NodeSelection.create(doc, 0);
19 
20 expect(getMovedTextblockCursorPos(selection)).toBe(selection.from + 1);
21 });
22 
23 it("ignores non-textblock node selections", () => {
24 const doc = schema.node("doc", null, [
25 schema.node("blockquote", null, [schema.node("paragraph", null, [schema.text("hello")])]),
26 ]);
27 
28 const selection = NodeSelection.create(doc, 0);
29 
30 expect(getMovedTextblockCursorPos(selection)).toBeNull();
31 });
32 
33 it("ignores non-node selections", () => {
34 const doc = schema.node("doc", null, [schema.node("paragraph", null, [schema.text("hello")])]);
35 
36 const selection = TextSelection.create(doc, 1);
37 
38 expect(getMovedTextblockCursorPos(selection)).toBeNull();
39 });
40});