import { describe, expect, test } from "@odoo/hoot";
import { waitFor, waitForNone, press, manuallyDispatchProgrammaticEvent } from "@odoo/hoot-dom";
import { setupEditor, testEditor } from "./_helpers/editor";
import { getContent } from "./_helpers/selection";
import { insertText, splitBlock } from "./_helpers/user_actions";
async function simulateEnter(editor) {
press("enter");
await manuallyDispatchProgrammaticEvent(editor.editable, "beforeinput", {
inputType: "insertParagraph",
});
}
describe("Blockquote", () => {
describe("SplitBlock", () => {
test("should force
in blockquote", async () => {
await testEditor({
contentBefore: "
abc[]", stepFunction: splitBlock, contentAfter: "
abc", }); }); test("should force
[]
abc[]", stepFunction: splitBlock, contentAfter: "
abc", }); }); test("should force
[]
[]", stepFunction: splitBlock, contentAfter: "
", }); }); test("should insert a new paragraph within the blockquote", async () => { await testEditor({ contentBefore: "
[]
", stepFunction: splitBlock, contentAfter: "abc
def[]
", }); }); test("should move an empty paragraph after the blockquote if at the end", async () => { await testEditor({ contentBefore: "abc
def
[]
", stepFunction: splitBlock, contentAfter: "abc
def
[]
abc
def
[]
ab[]`, stepFunction: splitBlock, contentAfter: `
ab`, }); }); test("should insert a new paragraph within the blockquote tag with rtl direction (2)", async () => { await testEditor({ contentBefore: `
[]
`, stepFunction: splitBlock, contentAfter: `abc[]
`, }); }); test("should move an empty paragraph after the blockquote with rtl direction if at the end", async () => { await testEditor({ contentBefore: `abc
[]
`, stepFunction: splitBlock, contentAfter: `abc
[]
abc
[]
`, stepFunction: splitBlock, contentAfter: `abc
[]
abc
[]
ab[]
"); expect(getContent(el)).toBe(`ab[]
`); await insertText(editor, "/"); await waitFor(".o-we-powerbox"); await insertText(editor, "quote"); await press("enter"); await waitForNone(".o-we-powerbox"); expect(getContent(el)).toBe("ab[]"); await insertText(editor, "c"); await simulateEnter(editor); expect(getContent(el)).toBe("
abc"); await insertText(editor, "d"); expect(getContent(el)).toBe("
[]
abc"); await insertText(editor, "ef"); expect(getContent(el)).toBe("
d[]
abc"); }); test("blockquote should create br on Enter (2)", async () => { const { el, editor } = await setupEditor("
def[]
a[]b"); await simulateEnter(editor); expect(getContent(el)).toBe("
a"); }); test("blockquote should create br on 1st Enter then create p", async () => { const { el, editor } = await setupEditor("
[]b
abc"); await simulateEnter(editor); expect(getContent(el)).toBe("
def[]
abc"); await simulateEnter(editor); expect(getContent(el)).toBe( '
def
[]
abc
def
[]