From 5bd6dcd94477c01d6013bb3862bb58c3f465015d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 17 Nov 2023 14:20:38 +0000 Subject: [PATCH] [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) Signed-off-by: Aaron Bohy (aab) --- .../webclient/mobile/mobile_switch_company_menu_tests.js | 5 +++-- .../web/static/tests/webclient/switch_company_menu_tests.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/web/static/tests/webclient/mobile/mobile_switch_company_menu_tests.js b/addons/web/static/tests/webclient/mobile/mobile_switch_company_menu_tests.js index 21e0c2b9bc7..0206b783816 100644 --- a/addons/web/static/tests/webclient/mobile/mobile_switch_company_menu_tests.js +++ b/addons/web/static/tests/webclient/mobile/mobile_switch_company_menu_tests.js @@ -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"); /** diff --git a/addons/web/static/tests/webclient/switch_company_menu_tests.js b/addons/web/static/tests/webclient/switch_company_menu_tests.js index 23898cbcd9d..13047998168 100644 --- a/addons/web/static/tests/webclient/switch_company_menu_tests.js +++ b/addons/web/static/tests/webclient/switch_company_menu_tests.js @@ -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**