From 65a9e730b0d76e1ee4de9b815c1dc2abf78ada1b Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Mon, 5 Sep 2022 14:44:41 +0000 Subject: [PATCH] [FIX] bus: fix display reconnect notification test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `displays reconnect notification` bus test relies on a `nextTick` to assert that a notification is present after the websocket disconnection. The issue is that we can't be sure that the notification will be displayed after this tick. Indeed, we need to wait for: the `postMessage` to reach the bus service, the notification to be added, the notification to be added in the DOM. This commit solves this issue, by waiting for the next render after the `simulateConnectionLost` method to occur. closes odoo/odoo#99590 Signed-off-by: Sébastien Theys (seb) --- addons/bus/static/tests/bus_tests.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/addons/bus/static/tests/bus_tests.js b/addons/bus/static/tests/bus_tests.js index 64981375500..72d8f7609a8 100644 --- a/addons/bus/static/tests/bus_tests.js +++ b/addons/bus/static/tests/bus_tests.js @@ -8,13 +8,14 @@ const { WEBSOCKET_CLOSE_CODES } = require("@bus/workers/websocket_worker"); const { startServer } = require('@bus/../tests/helpers/mock_python_environment'); const { patchWebsocketWorkerWithCleanup } = require("@bus/../tests/helpers/mock_websocket"); -var testUtils = require('web.test_utils'); const { browser } = require("@web/core/browser/browser"); const { registry } = require("@web/core/registry"); const { makeDeferred, nextTick, patchWithCleanup } = require("@web/../tests/helpers/utils"); const { makeTestEnv } = require('@web/../tests/helpers/mock_env'); const { createWebClient } = require("@web/../tests/webclient/helpers"); +const { afterNextRender } = owl.App; + QUnit.module('Bus', { beforeEach: function () { const customMultiTabService = { @@ -41,10 +42,10 @@ QUnit.module('Bus', { }); env.services['bus_service'].addChannel('lambda'); pyEnv['bus.bus']._sendone('lambda', 'notifType', 'beta'); - await testUtils.nextTick(); + await nextTick(); pyEnv['bus.bus']._sendone('lambda', 'notifType', 'epsilon'); - await testUtils.nextTick(); + await nextTick(); assert.verifySteps([ 'notification - beta', @@ -136,7 +137,7 @@ QUnit.module('Bus', { slaveEnv.services['bus_service'].addChannel('lambda'); pyEnv['bus.bus']._sendone('lambda', 'notifType', 'beta'); - await testUtils.nextTick(); + await nextTick(); assert.verifySteps([ 'main - notification - beta', @@ -171,14 +172,14 @@ QUnit.module('Bus', { }); secondEnv.services['bus_service'].addChannel('lambda'); pyEnv['bus.bus']._sendone('lambda', 'notifType', 'beta'); - await testUtils.nextTick(); + await nextTick(); // simulate unloading main window.dispatchEvent(new Event('unload')); await nextTick(); pyEnv['bus.bus']._sendone('lambda', 'notifType', 'gamma'); - await testUtils.nextTick(); + await nextTick(); assert.verifySteps([ 'main - notification - beta', @@ -321,8 +322,7 @@ QUnit.module('Bus', { // prevent websocket to connect and notification to disappear // before the assertion. startPromise = makeDeferred(); - pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.ABNORMAL_CLOSURE); - await nextTick(); + await afterNextRender(() => pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.ABNORMAL_CLOSURE)); assert.containsOnce(document.body, '.o_notification'); assert.strictEqual( @@ -331,9 +331,7 @@ QUnit.module('Bus', { ); // Wait for the worker to reconnect, post a message and the // bus_service to receive it and remove the notification. - const { afterNextRender } = owl.App; - startPromise.resolve(); - await afterNextRender(() => {}); + await afterNextRender(() => startPromise.resolve()); assert.containsNone(document.body, '.o_notification'); });