From 677eee90a97665838b63cfefcd011733618e43cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 24 May 2022 14:54:11 +0000 Subject: [PATCH] [FIX] mail: fix potential issues with notification request This patch was previously defined globally, but it has been removed at some point. This absence prevents from running some tests that relied on it when the current browser value does not match what the test is expecting. Part of task-2810734 Part-of: odoo/odoo#92193 --- .../static/src/models/notification_request_view.js | 6 +++++- .../components/messaging_menu_tests.js | 12 ++++++++++++ .../qunit_suite_tests/models/messaging_menu_tests.js | 9 +++++++++ .../widgets/notification_alert_tests.js | 5 ++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/models/notification_request_view.js b/addons/mail/static/src/models/notification_request_view.js index d8ed5b71120..aa694e2383f 100644 --- a/addons/mail/static/src/models/notification_request_view.js +++ b/addons/mail/static/src/models/notification_request_view.js @@ -2,6 +2,7 @@ import { registerModel } from '@mail/model/model_core'; import { attr, one } from '@mail/model/model_field'; +import { clear } from '@mail/model/model_field_command'; import { sprintf } from '@web/core/utils/strings'; @@ -11,9 +12,12 @@ registerModel({ recordMethods: { /** * @private - * @returns {string} + * @returns {string|FieldCommand} */ _computeHeaderText() { + if (!this.messaging.partnerRoot) { + return clear(); + } return sprintf( this.env._t("%(odoobotName)s has a request"), { odoobotName: this.messaging.partnerRoot.nameOrDisplayName }, diff --git a/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js index f58edc302b0..788a72075f2 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/messaging_menu_tests.js @@ -109,6 +109,12 @@ QUnit.test('messaging becomes initialized', async function (assert) { QUnit.test('basic rendering', async function (assert) { assert.expect(21); + patchWithCleanup(browser, { + Notification: { + ...browser.Notification, + permission: 'denied', + }, + }); const { click, createMessagingMenuComponent } = await start(); await createMessagingMenuComponent(); assert.strictEqual( @@ -234,6 +240,12 @@ QUnit.test('basic rendering', async function (assert) { QUnit.test('counter is taking into account failure notification', async function (assert) { assert.expect(2); + patchWithCleanup(browser, { + Notification: { + ...browser.Notification, + permission: 'denied', + }, + }); const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); const mailMessageId1 = pyEnv['mail.message'].create({ diff --git a/addons/mail/static/tests/qunit_suite_tests/models/messaging_menu_tests.js b/addons/mail/static/tests/qunit_suite_tests/models/messaging_menu_tests.js index 195162f0b86..c0c7c553352 100644 --- a/addons/mail/static/tests/qunit_suite_tests/models/messaging_menu_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/models/messaging_menu_tests.js @@ -2,6 +2,9 @@ import { start } from '@mail/../tests/helpers/test_utils'; +import { browser } from '@web/core/browser/browser'; +import { patchWithCleanup } from '@web/../tests/helpers/utils'; + QUnit.module('mail', {}, function () { QUnit.module('models', {}, function () { QUnit.module('messaging_menu_tests.js'); @@ -9,6 +12,12 @@ QUnit.module('messaging_menu_tests.js'); QUnit.test('messaging menu counter should ignore unread messages in channels that are unpinned', async function (assert) { assert.expect(1); + patchWithCleanup(browser, { + Notification: { + ...browser.Notification, + permission: 'denied', + }, + }); const { messaging } = await start(); messaging.models['Thread'].create({ id: 31, diff --git a/addons/mail/static/tests/qunit_suite_tests/widgets/notification_alert_tests.js b/addons/mail/static/tests/qunit_suite_tests/widgets/notification_alert_tests.js index 7eca2f869ad..d6109aa3a0a 100644 --- a/addons/mail/static/tests/qunit_suite_tests/widgets/notification_alert_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/widgets/notification_alert_tests.js @@ -18,7 +18,10 @@ QUnit.skip('notification_alert widget: display blocked notification alert', asyn assert.expect(1); patchWithCleanup(browser, { - Notification: 'denied', + Notification: { + ...browser.Notification, + permission: 'denied', + }, }); await start({ arch: `