import { expect, test } from "@odoo/hoot"; import { setupEditor, testEditor } from "../_helpers/editor"; import { getContent } from "../_helpers/selection"; import { em, span } from "../_helpers/tags"; import { italic, tripleClick } from "../_helpers/user_actions"; import { unformat } from "../_helpers/format"; test("should make a few characters italic", async () => { await testEditor({ contentBefore: `

ab[cde]fg

`, stepFunction: italic, contentAfter: `

ab${em(`[cde]`)}fg

`, }); }); test("should make a few characters not italic", async () => { await testEditor({ contentBefore: `

${em(`ab[cde]fg`)}

`, stepFunction: italic, contentAfter: `

${em(`ab`)}[cde]${em(`fg`)}

`, }); }); test("should make two paragraphs italic", async () => { await testEditor({ contentBefore: "

[abc

def]

", stepFunction: italic, contentAfter: `

${em(`[abc`)}

${em(`def]`)}

`, }); }); test("should make two paragraphs not italic", async () => { await testEditor({ contentBefore: `

${em(`[abc`)}

${em(`def]`)}

`, stepFunction: italic, contentAfter: `

[abc

def]

`, }); }); test("should make qweb tag italic", async () => { await testEditor({ contentBefore: `

[Test]

`, stepFunction: italic, contentAfter: `
[

Test

]
`, }); }); test("should make a whole heading italic after a triple click", async () => { await testEditor({ contentBefore: `

[ab

]cd

`, stepFunction: italic, contentAfter: `

${em(`[ab]`)}

cd

`, }); }); test("should make a whole heading not italic after a triple click", async () => { const { el, editor } = await setupEditor(`

${em(`[ab`)}

]cd

`); await tripleClick(el.querySelector("h1")); italic(editor); expect(getContent(el)).toBe(`

[ab]

cd

`); }); test("should make a selection starting with italic text fully italic", async () => { await testEditor({ contentBefore: `

${em(`[ab`)}

c]d

`, stepFunction: italic, contentAfter: `

${em(`[ab`)}

${em(`c]`)}d

`, }); }); test("should make a selection with italic text in the middle fully italic", async () => { await testEditor({ contentBefore: `

[a${em(`b`)}

${em(`c`)}d]e

`, stepFunction: italic, contentAfter: `

${em(`[ab`)}

${em(`cd]`)}e

`, }); }); test("should make a selection ending with italic text fully italic", async () => { await testEditor({ contentBefore: `

[ab

${em(`c]d`)}

`, stepFunction: italic, contentAfter: `

${em(`[ab`)}

${em(`c]d`)}

`, }); }); test("should get ready to type in italic", async () => { await testEditor({ contentBefore: `

ab[]cd

`, stepFunction: italic, contentAfterEdit: `

ab${em(`[]\u200B`, "first")}cd

`, contentAfter: `

ab[]cd

`, }); }); test("should get ready to type in not italic", async () => { await testEditor({ contentBefore: `

${em(`ab[]cd`)}

`, stepFunction: italic, contentAfterEdit: `

${em(`ab`)}${span(`[]\u200B`, "first")}${em(`cd`)}

`, contentAfter: `

${em(`ab[]cd`)}

`, }); }); test("should not format non-editable text (italic)", async () => { await testEditor({ contentBefore: '

[a

b

c]

', stepFunction: italic, contentAfter: `

${em("[a")}

b

${em("c]")}

`, }); }); test("should make a few characters italic inside table (italic)", async () => { await testEditor({ contentBefore: unformat(`

[abc



def



]



` ), stepFunction: italic, contentAfterEdit: unformat(`

${em(`[abc`)}



${em(`def`)}



${em(`]
`)}



` ), }); });