import { expect, test } from "@odoo/hoot"; import { animationFrame, tick } from "@odoo/hoot-mock"; import { setupEditor } from "./_helpers/editor"; import { unformat } from "./_helpers/format"; import { getContent, moveSelectionOutsideEditor, setContent, setSelection, } from "./_helpers/selection"; import { insertText } from "./_helpers/user_actions"; test("hints are removed when editor is destroyed", async () => { const { el, editor } = await setupEditor("
[]
", {}); expect(getContent(el)).toBe(`[]
`); editor.destroy(); expect(getContent(el)).toBe("[]
"); }); test("powerbox hint is display when the selection is in the editor", async () => { const { el } = await setupEditor("", {}); expect(getContent(el)).toBe(``); setContent(el, "[]
"); await tick(); expect(getContent(el)).toBe(`[]
`); moveSelectionOutsideEditor(); await tick(); expect(getContent(el)).toBe(``); }); test("placeholder is display when the selection is outside of the editor", async () => { const { el } = await setupEditor("", { config: { placeholder: "test" } }); expect(getContent(el)).toBe(``); setContent(el, "[]
"); await tick(); expect(getContent(el)).toBe(`[]
`); moveSelectionOutsideEditor(); await tick(); expect(getContent(el)).toBe(``); }); test("placeholder must not be visible if there is content in the editor", async () => { const { el } = await setupEditor("Hello
", { config: { placeholder: "test" } }); expect(getContent(el)).toBe(`Hello
`); }); test("placeholder must not be visible if there is content in the editor (2)", async () => { const content = ''; const { el } = await setupEditor(content, { config: { placeholder: "test" } }); // Unchanged, no placeholder hint. expect(getContent(el)).toBe(content); }); test("should not display hint in paragraph with media content", async () => { const content = ''; const { el } = await setupEditor(content); // Unchanged, no empty paragraph hint. expect(getContent(el)).toBe(content); }); test("should not lose track of temporary hints on split block", async () => { const { el, editor } = await setupEditor("[]
", {}); expect(getContent(el)).toBe(`[]
`); editor.shared.split.splitBlock(); editor.shared.history.addStep(); await animationFrame(); expect(getContent(el)).toBe( unformat(`[]
[]
[]
[]
[]
[]
[]"); expect(getContent(el)).toBe(`
[]`); const pre = el.firstElementChild; const hintStyle = getComputedStyle(pre, "::after"); expect(hintStyle.content).toBe('"Code"'); const paddingHint = hintStyle.padding; await insertText(editor, "abc"); expect(hintStyle.content).toBe("none"); const paddingText = getComputedStyle(pre).padding; expect(paddingHint).toBe(paddingText); }); test("hint for blockquote should have the same padding as its text content", async () => { const { el, editor } = await setupEditor("
[]"); expect(getContent(el)).toBe( `
[]` ); const blockquote = el.firstElementChild; const hintStyle = getComputedStyle(blockquote, "::after"); expect(hintStyle.content).toBe('"Quote"'); const paddingHint = hintStyle.padding; await insertText(editor, "abc"); expect(hintStyle.content).toBe("none"); const paddingText = getComputedStyle(blockquote).padding; expect(paddingHint).toBe(paddingText); });