[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 <sad@odoo.com>
This commit is contained in:
Aaron Bohy
2023-01-04 08:11:43 +01:00
parent 880665a6e3
commit fa9f865067
@@ -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");