import { describe, expect, test } from "@odoo/hoot"; import { setupEditor } from "../_helpers/editor"; import { press } from "@odoo/hoot-dom"; import { getContent } from "../_helpers/selection"; import { execCommand } from "../_helpers/userCommands"; describe("delete backward", () => { test("should register a history step (collapsed selection)", async () => { const { el, editor } = await setupEditor("

ab[]cd

"); await press("Backspace"); expect(getContent(el)).toBe("

a[]cd

"); execCommand(editor, "historyUndo"); expect(getContent(el)).toBe("

ab[]cd

"); execCommand(editor, "historyRedo"); expect(getContent(el)).toBe("

a[]cd

"); }); test("should register a history step (non-collapsed selection)", async () => { const { el, editor } = await setupEditor("

ab[cd]ef

"); await press("Backspace"); expect(getContent(el)).toBe("

ab[]ef

"); execCommand(editor, "historyUndo"); expect(getContent(el)).toBe("

ab[cd]ef

"); execCommand(editor, "historyRedo"); expect(getContent(el)).toBe("

ab[]ef

"); }); }); describe("delete forward", () => { test("should register a history step (collapsed selection)", async () => { const { el, editor } = await setupEditor("

ab[]cd

"); await press("Delete"); expect(getContent(el)).toBe("

ab[]d

"); execCommand(editor, "historyUndo"); expect(getContent(el)).toBe("

ab[]cd

"); execCommand(editor, "historyRedo"); expect(getContent(el)).toBe("

ab[]d

"); }); test("should register a history step (non-collapsed selection)", async () => { const { el, editor } = await setupEditor("

ab[cd]ef

"); await press("Delete"); expect(getContent(el)).toBe("

ab[]ef

"); execCommand(editor, "historyUndo"); expect(getContent(el)).toBe("

ab[cd]ef

"); execCommand(editor, "historyRedo"); expect(getContent(el)).toBe("

ab[]ef

"); }); });