[FIX] web: tests: fix SwitchCompanyMenu tests failing randomly

Before this commit, some tests of the SwitchCompanyMenu sometimes
failed:
   - "companies can be logged in even if some toggled within delay"
   - "can toggle multiple companies at once"

They failed because the debounce delay between the first click to
toggle a company and the moment the company service is notified to
actually select the companies was sometimes too short for the 2 or
3 clicks on the menu to toggle companies to occur, as those clicks
are separated by nextTick(), i.e. a mix of calls to setTimeout and
requestAnimationFrame.

In tests, we patch the debounce delay to 0 by default, and before
this commit we set a delay of 50 in the two faulty tests. This
commit fixes the issue by keeping the real delay in those tests (1s),
as they aim at testing the fact that the user has the time to do
multiple clicks before committing the company changes and reloading.

Fixes runbot error 29962

closes odoo/odoo#142904

X-original-commit: 2ec65691ac11cb4216d873dcab77a84e2c35ba17
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-21 23:24:00 +00:00
parent d099d8c5ae
commit 5bd6dcd944
2 changed files with 6 additions and 4 deletions
@@ -19,6 +19,7 @@ import { session } from "@web/session";
const serviceRegistry = registry.category("services");
let target;
const ORIGINAL_TOGGLE_DELAY = MobileSwitchCompanyMenu.toggleDelay;
async function createSwitchCompanyMenu(routerParams = {}, toggleDelay = 0) {
patchWithCleanup(MobileSwitchCompanyMenu, { toggleDelay });
if (routerParams.onPushState) {
@@ -130,7 +131,7 @@ QUnit.module("MobileSwitchCompanyMenu", (hooks) => {
assert.step(url.split("#")[1]);
prom.resolve();
}
const scMenu = await createSwitchCompanyMenu({ onPushState }, 50);
const scMenu = await createSwitchCompanyMenu({ onPushState }, ORIGINAL_TOGGLE_DELAY);
const scMenuEl = target.querySelector(".o_burger_menu_companies");
/**
@@ -294,7 +295,7 @@ QUnit.module("MobileSwitchCompanyMenu", (hooks) => {
function onPushState(url) {
assert.step(url.split("#")[1]);
}
const scMenu = await createSwitchCompanyMenu({ onPushState }, 50);
const scMenu = await createSwitchCompanyMenu({ onPushState }, ORIGINAL_TOGGLE_DELAY);
const scMenuEl = target.querySelector(".o_burger_menu_companies");
/**
@@ -14,6 +14,7 @@ const serviceRegistry = registry.category("services");
let target;
const ORIGINAL_TOGGLE_DELAY = SwitchCompanyMenu.toggleDelay;
async function createSwitchCompanyMenu(routerParams = {}, toggleDelay = 0) {
patchWithCleanup(SwitchCompanyMenu, { toggleDelay });
if (routerParams.onPushState) {
@@ -149,7 +150,7 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
assert.step(url.split("#")[1]);
prom.resolve();
}
const scMenu = await createSwitchCompanyMenu({ onPushState }, 50);
const scMenu = await createSwitchCompanyMenu({ onPushState }, ORIGINAL_TOGGLE_DELAY);
/**
* [x] **Hermit**
@@ -338,7 +339,7 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
function onPushState(url) {
assert.step(url.split("#")[1]);
}
const scMenu = await createSwitchCompanyMenu({ onPushState }, 50);
const scMenu = await createSwitchCompanyMenu({ onPushState }, ORIGINAL_TOGGLE_DELAY);
/**
* [x] **Hermit**