import { expect, test } from "@odoo/hoot"; import { click, manuallyDispatchProgrammaticEvent, press, waitFor } from "@odoo/hoot-dom"; import { animationFrame } from "@odoo/hoot-mock"; import { setupEditor } from "./_helpers/editor"; import { getContent, setSelection } from "./_helpers/selection"; import { insertText } from "./_helpers/user_actions"; import { loader } from "@web/core/emoji_picker/emoji_picker"; import { execCommand } from "./_helpers/userCommands"; import { unformat } from "./_helpers/format"; import { expectElementCount } from "./_helpers/ui_expectations"; test("should insert a banner with focus inside followed by a paragraph", async () => { const { el, editor } = await setupEditor("
Test[]
"); await insertText(editor, "/banner"); await animationFrame(); expect(".active .o-we-command-name").toHaveText("Banner Info"); await press("enter"); expect(unformat(getContent(el))).toBe( unformat( `Test[]
"); await insertText(editor, "/bannerinfo"); await press("enter"); await manuallyDispatchProgrammaticEvent(editor.editable, "beforeinput", { inputType: "insertParagraph", }); await insertText(editor, "Test1"); await manuallyDispatchProgrammaticEvent(editor.editable, "beforeinput", { inputType: "insertParagraph", }); await insertText(editor, "Test2"); await press(["ctrl", "a"]); expect(unformat(getContent(el))).toBe( unformat( `Test[]
"); await insertText(editor, "/bannerinfo"); await press("enter"); await manuallyDispatchProgrammaticEvent(editor.editable, "beforeinput", { inputType: "insertParagraph", }); await insertText(editor, "Test1"); await manuallyDispatchProgrammaticEvent(editor.editable, "beforeinput", { inputType: "insertParagraph", }); await insertText(editor, "Test2"); await press(["ctrl", "a"]); expect(unformat(getContent(el))).toBe( unformat( `test[]
"); await insertText(editor, "/bannerinfo"); await press("enter"); expect(unformat(getContent(el))).toBe( unformat( `[]
]
test[]
"); await insertText(editor, "/bannerinfo"); await press("enter"); // Move the selection outside of the banner setSelection({ anchorNode: el.querySelectorAll("p")[2], anchorOffset: 0 }); await insertText(editor, "Test1"); await manuallyDispatchProgrammaticEvent(editor.editable, "beforeinput", { inputType: "insertParagraph", }); await insertText(editor, "Test2"); await press(["ctrl", "a"]); expect(getContent(el)).toBe( `[
Test1
Test2]
`, { message: "should select everything" } ); await press("Backspace"); expect(getContent(el)).toBe( `[]
cd[]
' ); await press(["ctrl", "a"]); expect(getContent(el)).toBe( 'cd]
' ); await press("Backspace"); expect(getContent(el)).toBe( `[]
Test[]
"); await insertText(editor, "/bannerinfo"); await press("enter"); expect("i.o_editor_banner_icon").toHaveText("💡"); await loader.loadEmoji(); await click("i.o_editor_banner_icon"); await waitFor(".o-EmojiPicker"); await click(".o-EmojiPicker .o-Emoji"); await animationFrame(); expect("i.o_editor_banner_icon").toHaveText("😀"); execCommand(editor, "historyUndo"); expect("i.o_editor_banner_icon").toHaveText("💡"); execCommand(editor, "historyRedo"); expect("i.o_editor_banner_icon").toHaveText("😀"); }); test("toolbar should be closed when you open the emojipicker", async () => { const { editor, el } = await setupEditor(`Test
a[]
`); await insertText(editor, "/bannerinfo"); await press("enter"); // Move the selection to open the toolbar const textNode = el.querySelector(".test").childNodes[0]; setSelection({ anchorNode: textNode, anchorOffset: 0, focusNode: textNode, focusOffset: 2 }); await waitFor(".o-we-toolbar"); await loader.loadEmoji(); await click("i.o_editor_banner_icon"); await waitFor(".o-EmojiPicker"); await animationFrame(); await expectElementCount(".o-EmojiPicker", 1); await expectElementCount(".o-we-toolbar", 0); }); test.tags("desktop", "iframe"); test("toolbar should be closed when you open the emojipicker (iframe)", async () => { const { editor, el } = await setupEditor(`Test
a[]
`, { props: { iframe: true }, }); await insertText(editor, "/bannerinfo"); await press("enter"); // Move the selection to open the toolbar const textNode = el.querySelector(".test").childNodes[0]; setSelection({ anchorNode: textNode, anchorOffset: 0, focusNode: textNode, focusOffset: 2 }); await waitFor(".o-we-toolbar"); await loader.loadEmoji(); await click(":iframe i.o_editor_banner_icon"); await waitFor(".o-EmojiPicker"); await animationFrame(); await expectElementCount(".o-EmojiPicker", 1); await expectElementCount(".o-we-toolbar", 0); }); test("add banner inside empty list", async () => { const { el, editor } = await setupEditor("