[FIX] web: fix SelectCreateDialog test failing randomly

Before this commit, the modified test sometimes failed on runbot
because it couldn't click on "Create and edit..." in the many2one
dropdown. Here's what happened:
 1) call editInput to write something in the many2one input
 2) call selectDropdownItem to select "Create and edit..."
This was done without mocking setTimeout.

The problem is that editInput triggers the opening of the dropdown,
but as setTimeout wasn't mocked, that opening was delayed. Then,
selectDropdownItem first clicked on the input to open the dropdown,
and then clicked on the requested item. It might happen that the
click on the input actually closed the dropdown instead of opening
it, if it had been already opened via editInput. In that case, the
test failed because it couldn't click later on on "Create and edit".

This commit also improves the test utils to better log what really
happens: in this case, the dropdown isn't open at all, so we
detect that specific issue and log it with a proper message (which
is different than "the dropdown is open, but I can find the item
you're looking found).

Runbot issue 28207

closes odoo/odoo#143044

X-original-commit: 220d4325866330235ceccd61b8d1d00d8c919ba8
Signed-off-by: Francois Georis (fge) <fge@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2023-11-22 07:43:10 +00:00
parent d3b92f1dc6
commit c9e3866b5f
2 changed files with 14 additions and 3 deletions
+7 -1
View File
@@ -1023,7 +1023,13 @@ export async function clickDropdown(target, fieldName) {
}
export async function clickOpenedDropdownItem(target, fieldName, itemContent) {
const dropdownItems = target.querySelectorAll(`[name='${fieldName}'] .dropdown ul li`);
const dropdowns = target.querySelectorAll(`[name='${fieldName}'] .dropdown .dropdown-menu`);
if (dropdowns.length === 0) {
throw new Error(`No dropdown found for field ${fieldName}`);
} else if (dropdowns.length > 1) {
throw new Error(`Found ${dropdowns.length} dropdowns for field ${fieldName}`);
}
const dropdownItems = dropdowns[0].querySelectorAll("li");
const indexToClick = Array.from(dropdownItems)
.map((html) => html.textContent)
.indexOf(itemContent);
@@ -2,10 +2,10 @@
import {
click,
clickOpenedDropdownItem,
getFixture,
nextTick,
editInput,
selectDropdownItem,
patchWithCleanup,
} from "@web/../tests/helpers/utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
@@ -261,6 +261,11 @@ QUnit.module("ViewDialogs", (hooks) => {
QUnit.test("SelectCreateDialog cascade x2many in create mode", async function (assert) {
assert.expect(5);
patchWithCleanup(browser, {
setTimeout: (fn) => fn(),
});
serverData.views = {
"partner,false,form": `
<form>
@@ -319,7 +324,7 @@ QUnit.module("ViewDialogs", (hooks) => {
await click(target, ".o_field_x2many_list_row_add a");
await editInput(target, ".o_field_widget[name=instrument] input", "ABC");
await selectDropdownItem(target, "instrument", "Create and edit...");
await clickOpenedDropdownItem(target, "instrument", "Create and edit...");
assert.containsOnce(target, ".modal .modal-lg");