import { Plugin } from "@html_editor/plugin"; import { MAIN_PLUGINS } from "@html_editor/plugin_sets"; import { closestElement } from "@html_editor/utils/dom_traversal"; import { expect, test } from "@odoo/hoot"; import { setupEditor } from "./_helpers/editor"; import { insertText } from "./_helpers/user_actions"; import { getContent } from "./_helpers/selection"; test("can get content of an Editor", async () => { const { el, editor } = await setupEditor("
hel[lo] world
", {}); expect(el.innerHTML).toBe(`hello world
`); expect(editor.getContent()).toBe(`hello world
`); }); test("can get content of an empty paragraph", async () => { const { el, editor } = await setupEditor("[]
", {}); expect(el.innerHTML).toBe( `` ); expect(editor.getContent()).toBe(``); }); test("is notified when content is changed", async () => { let n = 0; const { editor } = await setupEditor("hello[] world
", { config: { onChange: () => n++ }, }); expect(n).toBe(0); await insertText(editor, "a"); expect(editor.getContent()).toBe(`helloa world
`); expect(n).toBe(1); }); test("plugin destruction is reverse of instantiation order", async () => { function makeTestPlugin(id, dependencies = []) { return class TestPlugin extends Plugin { static id = id; static dependencies = dependencies; setup() { expect.step(`setup: ${id}`); } destroy() { expect.step(`destroy: ${id}`); } }; } const Plugins = [...MAIN_PLUGINS, makeTestPlugin("first"), makeTestPlugin("second", ["first"])]; const { editor } = await setupEditor(`[]
`, { config: { Plugins } }); expect.verifySteps(["setup: first", "setup: second"]); editor.destroy(); expect.verifySteps(["destroy: second", "destroy: first"]); }); test("Remove odoo-editor-editable class after every plugin is destroyed", async () => { class TestPlugin extends Plugin { static id = "test"; destroy() { const p = this.editable.querySelector("p"); if (closestElement(p, "div")) { expect.step("operation"); } } } const Plugins = [...MAIN_PLUGINS, TestPlugin]; const { editor } = await setupEditor(`a