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: "

abc[]

def

", stepFunction: async (editor) => { await press(["ctrl", "a"]); await insertText(editor, "x"); }, contentAfter: "

x[]

", }); }); }); describe("not collapsed selection", () => { test("should insert a character in a fully selected font in a heading, preserving its style", async () => { await testEditor({ contentBefore: '

[abc]

def

', stepFunction: async (editor) => await insertText(editor, "g"), contentAfter: '

g[]

def

', }); await testEditor({ contentBefore: '

[abc]

def

', stepFunction: async (editor) => { deleteBackward(editor); await insertText(editor, "g"); }, contentAfter: '

g[]

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

"); }); });