From fa9f865067ae2b4eb48a817f996d30ce61e85c91 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 3 Jan 2023 09:57:03 +0000 Subject: [PATCH] [FIX] web: fix test failing randomly Before this commit, the modified test sometimes failed on runbot, because it might happen that the hashchange event is triggered in the next animation frame (the event isn't triggered synchronously). This commit ensures that we wait for the hashchange event, and for a nextTick before checking that the next action is in the DOM. Fixes runbot issue 6946 closes odoo/odoo#109028 X-original-commit: 6aba445e2b4a1f6321cefb04fb07584df615dfa2 Signed-off-by: Samuel Degueldre --- .../static/tests/webclient/actions/load_state_tests.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/web/static/tests/webclient/actions/load_state_tests.js b/addons/web/static/tests/webclient/actions/load_state_tests.js index 8c49ecc2d35..9d9b9678ce8 100644 --- a/addons/web/static/tests/webclient/actions/load_state_tests.js +++ b/addons/web/static/tests/webclient/actions/load_state_tests.js @@ -15,6 +15,7 @@ import { patchWithCleanup, mount, nextTick, + makeDeferred, } from "../../helpers/utils"; import { toggleFilterMenu, toggleMenuItem } from "@web/../tests/search/helpers"; import { session } from "@web/session"; @@ -1010,12 +1011,14 @@ QUnit.module("ActionManager", (hooks) => { }); QUnit.test("concurrent hashchange during action mounting -- 1", async (assert) => { - assert.expect(5); - + const hashchangeDef = makeDeferred(); class MyAction extends Component { setup() { owl.onMounted(() => { assert.step("myAction mounted"); + browser.addEventListener("hashchange", () => { + hashchangeDef.resolve(); + }); browser.location.hash = "#action=__test__client__action__&menu_id=1"; }); } @@ -1027,7 +1030,10 @@ QUnit.module("ActionManager", (hooks) => { const webClient = await createWebClient({ serverData }); assert.verifySteps(["myAction mounted"]); + assert.containsOnce(target, ".not-here"); + // hashchange event isn't trigerred synchronously, so we have to wait for it + await hashchangeDef; await nextTick(); assert.containsNone(target, ".not-here"); assert.containsOnce(target, ".test_client_action");