import { setupHTMLBuilder } from "@html_builder/../tests/helpers";
import { expect, test, describe } from "@odoo/hoot";
import { animationFrame, press } from "@odoo/hoot-dom";
import { contains, onRpc } from "@web/../tests/web_test_helpers";
describe.current.tags("desktop");
test("should prevent edition in many2one field", async () => {
await setupHTMLBuilder(
`
Travel
`
);
expect(":iframe a").toHaveProperty("isContentEditable", false);
});
test.tags("desktop"); // NavigationItem only react to mouvemove which is not triggered in test for mobile
test("Preview changes of many2one option", async () => {
onRpc(
"ir.qweb.field.contact",
"get_record_to_html",
({ args: [[id]], kwargs }) => `The ${kwargs.options.option} of ${id}`
);
await setupHTMLBuilder(`
The Name of 3
The Address of 3
The Address of 3
Other
`);
await contains(":iframe .span-1").click();
expect("button.btn.dropdown").toHaveCount(1);
await contains("button.btn.dropdown").click();
await contains("span.o-dropdown-item.dropdown-item").hover();
expect(":iframe span.span-1 > span").toHaveText("The Name of 1");
expect(":iframe span.span-2 > span").toHaveText("The Address of 1");
expect(":iframe span.span-3 > span").toHaveText("The Address of 3"); // author of other post is not changed
expect(":iframe span.span-4").toHaveText("Hermit");
await press("esc"); // This causes the dropdown to close, and thus the preview to be reverted
await animationFrame();
expect(":iframe span.span-1 > span").toHaveText("The Name of 3");
expect(":iframe span.span-2 > span").toHaveText("The Address of 3");
expect(":iframe span.span-4").toHaveText("Other");
});