import { describe, expect, test } from "@odoo/hoot"; import { setupEditor, testEditor } from "../_helpers/editor"; import { deleteBackward, insertText } from "../_helpers/user_actions"; import { getContent } from "../_helpers/selection"; import { execCommand } from "../_helpers/userCommands"; import { press } from "@odoo/hoot-dom"; describe("collapsed selection", () => { test("should insert a char into an empty span without removing the zws", async () => { await testEditor({ contentBefore: '
ab[]\u200Bcd
', stepFunction: async (editor) => { await insertText(editor, "x"); }, contentAfter: 'abx[]\u200Bcd
', }); }); test("should insert a char into an empty span surrounded by space without removing the zws", async () => { await testEditor({ contentBefore: 'ab []\u200B cd
', stepFunction: async (editor) => { await insertText(editor, "x"); }, contentAfter: 'ab x[]\u200B cd
', }); }); test("should insert a char into a data-oe-zws-empty-inline span removing the zws and data-oe-zws-empty-inline", async () => { await testEditor({ contentBefore: 'ab[]\u200Bcd
', stepFunction: async (editor) => { await insertText(editor, "x"); }, contentAfter: "abx[]cd
", }); }); test("should insert a char into a data-oe-zws-empty-inline span surrounded by space without removing the zws and data-oe-zws-empty-inline", async () => { await testEditor({ contentBefore: 'ab[]\u200Bcd
', stepFunction: async (editor) => { await insertText(editor, "x"); }, contentAfter: "abx[]cd
", }); }); test("should insert text within heading after selecting a heading using ctrl+A", async () => { await testEditor({ contentBefore: "def
", stepFunction: async (editor) => { await press(["ctrl", "a"]); await insertText(editor, "x"); }, contentAfter: "def
', stepFunction: async (editor) => await insertText(editor, "g"), contentAfter: 'def
', }); await testEditor({ contentBefore: 'def
', stepFunction: async (editor) => { deleteBackward(editor); await insertText(editor, "g"); }, contentAfter: 'def
', }); }); test("should transform the space node preceded by a styled element to ", async () => { await testEditor({ contentBefore: `ab [cd]
`, stepFunction: async (editor) => { await insertText(editor, "x"); }, contentAfter: `ab x[]
`, }); }); test("should replace text and be a undoable step", async () => { const { editor, el } = await setupEditor("[abc]def
"); await insertText(editor, "x"); expect(getContent(el)).toBe("x[]def
"); execCommand(editor, "historyUndo"); expect(getContent(el)).toBe("[abc]def
"); }); });