oca-ocb-web/odoo-bringout-oca-ocb-html_builder/html_builder/static/tests/utils.test.js
Ernad Husremovic f866779561 replace stale web_editor with html_editor and html_builder for 19.0
web_editor was removed in Odoo 19.0 and replaced by html_editor
and html_builder. The old web_editor was incorrectly included in
the 19.0 vanilla import.

🤖 assisted by claude
2026-03-09 15:31:13 +01:00

55 lines
2.2 KiB
JavaScript

import { addBuilderOption, setupHTMLBuilder } from "@html_builder/../tests/helpers";
import { BaseOptionComponent, useDomState } from "@html_builder/core/utils";
import { describe, expect, test } from "@odoo/hoot";
import { animationFrame } from "@odoo/hoot-dom";
import { xml } from "@odoo/owl";
import { contains } from "@web/../tests/web_test_helpers";
describe.current.tags("desktop");
describe("useDomState", () => {
test("Should not update the state of an async useDomState if a new step has been made", async () => {
let currentResolve;
addBuilderOption({
selector: ".test-options-target",
Component: class extends BaseOptionComponent {
static template = xml`<div t-att-data-letter="getLetter()"/>`;
setup() {
super.setup(...arguments);
this.state = useDomState(async () => {
const letter = await new Promise((resolve) => {
currentResolve = resolve;
});
return {
delay: `${letter}`,
};
});
}
getLetter() {
expect.step(`state: ${this.state.delay}`);
return this.state.delay;
}
},
});
const { getEditor } = await setupHTMLBuilder(`<div class="test-options-target">a</div>`);
await animationFrame();
await contains(":iframe .test-options-target").click();
const editor = getEditor();
const resolve1 = currentResolve;
resolve1("x");
await animationFrame();
editor.editable.querySelector(".test-options-target").textContent = "b";
editor.shared.history.addStep();
const resolve2 = currentResolve;
editor.editable.querySelector(".test-options-target").textContent = "c";
editor.shared.history.addStep();
const resolve3 = currentResolve;
resolve3("z");
await animationFrame();
resolve2("y");
await animationFrame();
expect.verifySteps(["state: x", "state: z"]);
});
});