import { describe, expect, test } from "@odoo/hoot"; import { setupEditor, testEditor } from "../_helpers/editor"; import { cleanLinkArtifacts, unformat } from "../_helpers/format"; import { animationFrame, click, select, waitFor, waitForNone } from "@odoo/hoot-dom"; import { getContent, simulateDoubleClickSelect } from "../_helpers/selection"; import { insertText } from "../_helpers/user_actions"; import { contains } from "@web/../tests/web_test_helpers"; describe("button style", () => { test("editable button should have cursor text", async () => { const { el } = await setupEditor( '

Link styled as button

' ); const button = el.querySelector("a"); expect(button).toHaveStyle({ cursor: "text" }); }); test("non-editable .btn-link should have cursor pointer", async () => { const { el } = await setupEditor( // A simpliflied version of an embedded component with toolbar // buttons, as it happens in certain flows in Knowledge. unformat(`
`) ); const button = el.querySelector(".o_embedded_toolbar button"); expect(button).toHaveStyle({ cursor: "pointer" }); }); test("Button styling should not override inner font size", async () => { const { el } = await setupEditor( unformat(`
a[b]c
`) ); await waitFor(".o-we-toolbar"); await click("button[name='link']"); await animationFrame(); await click('select[name="link_type"]'); await animationFrame(); await select("primary"); await animationFrame(); await contains(".o-we-linkpopover input.o_we_href_input_link").edit("#"); // Ensure `.display-1-fs` overrides the `.btn`'s default font size. const link = el.querySelector("a.btn"); const span = el.querySelector("span.display-1-fs"); expect(getComputedStyle(link).fontSize).toBe(getComputedStyle(span).fontSize); expect(el).toHaveInnerHTML( unformat(`
a\ufeff\ufeffb\ufeff\ufeffc
`) ); }); test("Should be able to change button style", async () => { await testEditor({ contentBefore: unformat(`
a[b]c
`), stepFunction: (editor) => { editor.shared.format.formatSelection("setFontSizeClassName", { formatProps: { className: "h1-fs" }, applyStyle: true, }); }, contentAfter: unformat(`
a [b] c
`), }); }); }); describe("button edit", () => { test("button link should be editable with double click select", async () => { const { el, editor } = await setupEditor('

this is a link

'); await waitForNone(".o-we-linkpopover"); const button = el.querySelector("a"); // simulate double click selection await simulateDoubleClickSelect(button); expect(getContent(el)).toBe( '

this is a \ufeff[\ufefflink]\ufeff\ufeff

' ); expect(cleanLinkArtifacts(getContent(el))).toBe('

this is a [link]

'); await insertText(editor, "X"); expect(cleanLinkArtifacts(getContent(el))).toBe('

this is a X[]

'); }); });