import { HtmlField } from "@html_editor/fields/html_field"; import { htmlEditorVersions } from "@html_editor/html_migrations/html_migrations_utils"; import { beforeEach, describe, expect, getFixture, test } from "@odoo/hoot"; import { defineModels, fields, models, mountView, patchWithCleanup, } from "@web/../tests/web_test_helpers"; const VERSIONS = htmlEditorVersions(); const CURRENT_VERSION = VERSIONS.at(-1); class Partner extends models.Model { txt = fields.Html({ trim: true }); name = fields.Char(); _records = [ { id: 1, name: "excalidraw", txt: `

Hello World

`, }, { id: 2, name: "banner", txt: `

test

💡

content

`, }, ]; } async function mountViewWithRecord({ resId, readonly }) { return mountView({ type: "form", resId, resModel: "partner", arch: `
`, }); } defineModels([Partner]); describe("test the migration process", () => { let htmlFieldComponent; beforeEach(() => { patchWithCleanup(HtmlField.prototype, { setup() { super.setup(); htmlFieldComponent = this; }, }); }); describe("In html field", () => { test("Excalidraw EmbeddedComponent is replaced by a link (editable)", async () => { await mountViewWithRecord({ resId: 1 }); expect("[data-embedded='draw']").toHaveCount(0); expect("a[href='https://excalidraw.com']").toHaveCount(1); expect(htmlFieldComponent.editor.getContent()).toBe( `

Hello World

https://excalidraw.com

` ); }); test("Banner classes are properly updated (editable)", async () => { await mountViewWithRecord({ resId: 2 }); const fixture = getFixture(); expect(fixture.querySelector(".odoo-editor-editable")).toHaveInnerHTML( `

test

💡

content

` ); expect(htmlFieldComponent.editor.getContent()).toBe( `

test

💡

content

` ); }); }); describe("In html viewer", () => { test("Excalidraw EmbeddedComponent is replaced by a link (readonly)", async () => { await mountViewWithRecord({ resId: 1, readonly: true }); expect("[data-embedded='draw']").toHaveCount(0); expect("a[href='https://excalidraw.com']").toHaveCount(1); }); test("Banner classes are properly updated (readonly)", async () => { await mountViewWithRecord({ resId: 2, readonly: true }); const fixture = getFixture(); expect(fixture.querySelector(".o_readonly")).toHaveInnerHTML( `

test

💡

content

` ); }); }); });