2 createTestContext, destroyFromContext, dispatchEditorMouseClick,
3 } from "lexical/__tests__/utils";
5 $getRoot, LexicalEditor, LexicalNode,
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";
13 describe('Mouse-handling service tests', () => {
15 let context!: EditorUiContext;
16 let editor!: LexicalEditor;
19 context = createTestContext();
20 editor = context.editor;
21 registerRichText(editor);
22 registerMouseHandling(context);
26 destroyFromContext(context);
29 test('Click below last table inserts new empty paragraph', () => {
30 let tableNode!: TableNode;
31 let lastRootChild!: LexicalNode|null;
33 editor.updateAndCommit(() => {
34 tableNode = $createTableNode();
35 $getRoot().append(tableNode);
36 lastRootChild = $getRoot().getLastChild();
39 expect(lastRootChild).toBeInstanceOf(TableNode);
41 const tableDOM = editor.getElementByKey(tableNode.getKey());
42 const rect = tableDOM?.getBoundingClientRect();
43 dispatchEditorMouseClick(editor, 0, (rect?.bottom || 0) + 1)
45 editor.getEditorState().read(() => {
46 lastRootChild = $getRoot().getLastChild();
49 expect(lastRootChild).toBeInstanceOf(ParagraphNode);