]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/services/__tests__/mouse-handling.test.ts
Lexical: Updated URL handling, added mouse handling
[bookstack] / resources / js / wysiwyg / services / __tests__ / mouse-handling.test.ts
1 import {
2     createTestContext, destroyFromContext, dispatchEditorMouseClick,
3 } from "lexical/__tests__/utils";
4 import {
5     $getRoot, LexicalEditor, LexicalNode,
6     ParagraphNode,
7 } from "lexical";
8 import {registerRichText} from "@lexical/rich-text";
9 import {EditorUiContext} from "../../ui/framework/core";
10 import {registerMouseHandling} from "../mouse-handling";
11 import {$createTableNode, TableNode} from "@lexical/table";
12
13 describe('Mouse-handling service tests', () => {
14
15     let context!: EditorUiContext;
16     let editor!: LexicalEditor;
17
18     beforeEach(() => {
19         context = createTestContext();
20         editor = context.editor;
21         registerRichText(editor);
22         registerMouseHandling(context);
23     });
24
25     afterEach(() => {
26         destroyFromContext(context);
27     });
28
29     test('Click below last table inserts new empty paragraph', () => {
30         let tableNode!: TableNode;
31         let lastRootChild!: LexicalNode|null;
32
33         editor.updateAndCommit(() => {
34             tableNode = $createTableNode();
35             $getRoot().append(tableNode);
36             lastRootChild = $getRoot().getLastChild();
37         });
38
39         expect(lastRootChild).toBeInstanceOf(TableNode);
40
41         const tableDOM = editor.getElementByKey(tableNode.getKey());
42         const rect = tableDOM?.getBoundingClientRect();
43         dispatchEditorMouseClick(editor, 0, (rect?.bottom || 0) + 1)
44
45         editor.getEditorState().read(() => {
46             lastRootChild = $getRoot().getLastChild();
47         });
48
49         expect(lastRootChild).toBeInstanceOf(ParagraphNode);
50     });
51 });