1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00
Files
bookstack/resources/js/wysiwyg/services/__tests__/mouse-handling.test.ts
Dan Brown c54101c603 Lexical: Updated URL handling, added mouse handling
- Removed URL protocol allow-list to allow any as per old editor.
- Added mouse handling, so that clicks below many last hard-to-escape
  block types will add an empty new paragraph for easy escaping &
  editing.
2025-07-25 13:58:48 +01:00

51 lines
1.5 KiB
TypeScript

import {
createTestContext, destroyFromContext, dispatchEditorMouseClick,
} from "lexical/__tests__/utils";
import {
$getRoot, LexicalEditor, LexicalNode,
ParagraphNode,
} from "lexical";
import {registerRichText} from "@lexical/rich-text";
import {EditorUiContext} from "../../ui/framework/core";
import {registerMouseHandling} from "../mouse-handling";
import {$createTableNode, TableNode} from "@lexical/table";
describe('Mouse-handling service tests', () => {
let context!: EditorUiContext;
let editor!: LexicalEditor;
beforeEach(() => {
context = createTestContext();
editor = context.editor;
registerRichText(editor);
registerMouseHandling(context);
});
afterEach(() => {
destroyFromContext(context);
});
test('Click below last table inserts new empty paragraph', () => {
let tableNode!: TableNode;
let lastRootChild!: LexicalNode|null;
editor.updateAndCommit(() => {
tableNode = $createTableNode();
$getRoot().append(tableNode);
lastRootChild = $getRoot().getLastChild();
});
expect(lastRootChild).toBeInstanceOf(TableNode);
const tableDOM = editor.getElementByKey(tableNode.getKey());
const rect = tableDOM?.getBoundingClientRect();
dispatchEditorMouseClick(editor, 0, (rect?.bottom || 0) + 1)
editor.getEditorState().read(() => {
lastRootChild = $getRoot().getLastChild();
});
expect(lastRootChild).toBeInstanceOf(ParagraphNode);
});
});