[FIX] web: tests: fix randomly failing load state tests
Before this commit, several qunit load state tests sometimes failed. They all follow the same pattern: - trigger an "hashchange" event to simulate an update of the url - wait twice for nextTick - check the DOM reflects the url change However, waiting for 2 ticks isn't enough. Indeed, when the url hash is set, our mock location object dispatches a "real" hashchange event on window, but it does it after a setTimeout [1]. Then, the webclient is notified (via the router service) of the url change, and reacts by loading the appropriate action. This then requires 2 ticks, because we first clear the DOM with the BlankComponent, and then we mount the requested action/view. This commit makes those tests more robust by waiting for a setTimeout before the 2 nextTicks. [1] https://github.com/odoo/odoo/blob/1882d8f89f760bd1ff8a2bf0ae798939402647a3/addons/web/static/tests/setup.js#L52 Runbot issue~37030 closes odoo/odoo#162939 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
@@ -198,6 +198,8 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
webClient.env.bus.trigger("test:hashchange", {
|
||||
action: "HelloWorldTest",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
// [1] https://github.com/odoo/odoo/blob/1882d8f89f760bd1ff8a2bf0ae798939402647a3/addons/web/static/tests/setup.js#L52
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.strictEqual(
|
||||
@@ -217,6 +219,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
webClient.env.bus.trigger("test:hashchange", {
|
||||
action: 1,
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsOnce(target, ".o_control_panel");
|
||||
@@ -239,6 +242,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
id: 2,
|
||||
model: "partner",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsOnce(target, ".o_form_view");
|
||||
@@ -281,6 +285,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
model: "partner",
|
||||
view_type: "form",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsOnce(target, ".o_form_view");
|
||||
@@ -302,6 +307,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
action: 3,
|
||||
view_type: "kanban",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsNone(target, ".o_list_view");
|
||||
@@ -403,6 +409,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
action: 3,
|
||||
view_type: "kanban",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsNone(target, ".o_list_view");
|
||||
@@ -413,6 +420,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
id: 4,
|
||||
view_type: "form",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsNone(target, ".o_kanban_view");
|
||||
@@ -448,6 +456,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
id: 4,
|
||||
view_type: "form",
|
||||
});
|
||||
await new Promise((r) => setTimeout(r)); // real "hashchange" event is triggered after a setTimeout [1]
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.containsOnce(target, ".o_form_view");
|
||||
|
||||
Reference in New Issue
Block a user