From 08afc0af8f8a9e562b6fc7b2ddb3c329be1bf7bb Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Mon, 5 Jul 2021 09:37:11 +0000 Subject: [PATCH] [REF] *: remove use of legacy notifications from tests When writing the new webclient, the notification service was rewritten, and all of its uses in production code were changed to use the new services, however, some tests were still reliant on the old notification service. This commit removes references to the legacy notification service so that we can be one step closer to removing it from the code base. Part of #72675 --- addons/barcodes/static/tests/barcode_tests.js | 9 ++- .../static/tests/m2x_avatar_employee_tests.js | 51 ++++++++++------- .../components/discuss/tests/discuss_tests.js | 24 +++++--- .../messaging_menu/messaging_menu_tests.js | 20 +++++-- .../src/models/messaging/messaging_tests.js | 56 +++++++++++-------- addons/mail/static/src/utils/test_utils.js | 2 - .../tests/partner_autocomplete_tests.js | 13 +++-- .../relational_fields/field_one2many_tests.js | 6 +- .../static/tests/legacy/views/form_tests.js | 9 ++- .../static/tests/legacy/views/list_tests.js | 21 ++++--- 10 files changed, 120 insertions(+), 91 deletions(-) diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js index aefc90bb5ba..8ba4b92c3a7 100644 --- a/addons/barcodes/static/tests/barcode_tests.js +++ b/addons/barcodes/static/tests/barcode_tests.js @@ -8,7 +8,6 @@ var fieldRegistry = require('web.field_registry'); var FormController = require('web.FormController'); var FormView = require('web.FormView'); var testUtils = require('web.test_utils'); -var NotificationService = require('web.NotificationService'); var createView = testUtils.createView; var triggerKeypressEvent = testUtils.dom.triggerKeypressEvent; @@ -66,11 +65,11 @@ QUnit.test('Button with barcode_trigger', async function (assert) { '', res_id: 2, services: { - notification: NotificationService.extend({ + notification: { notify: function (params) { assert.step(params.type); } - }), + }, }, intercepts: { execute_action: function (event) { @@ -536,11 +535,11 @@ QUnit.test('barcode_scanned only trigger error for active view', async function }, res_id: 1, services: { - notification: NotificationService.extend({ + notification: { notify: function (params) { assert.step(params.type); } - }), + }, }, viewOptions: { mode: 'edit', diff --git a/addons/hr/static/tests/m2x_avatar_employee_tests.js b/addons/hr/static/tests/m2x_avatar_employee_tests.js index f1787312b87..8e943ed5f08 100644 --- a/addons/hr/static/tests/m2x_avatar_employee_tests.js +++ b/addons/hr/static/tests/m2x_avatar_employee_tests.js @@ -182,6 +182,21 @@ QUnit.module('hr', {}, function () { return this._super(...arguments); }, res_id: 1, + services: { + notification: { + notify(notification) { + assert.ok( + true, + "should display a toast notification after failing to open chat" + ); + assert.strictEqual( + notification.message, + "You can only chat with employees that have a dedicated user.", + "should display the correct information in the notification" + ); + }, + }, + }, }); mock.intercept(form, 'call_service', (ev) => { @@ -199,17 +214,6 @@ QUnit.module('hr', {}, function () { 'read hr.employee.public 11', ]); - assert.containsOnce( - document.body, - '.toast .o_notification_content', - "should display a toast notification after failing to open chat" - ); - assert.strictEqual( - document.querySelector('.o_notification_content').textContent, - "You can only chat with employees that have a dedicated user.", - "should display the correct information in the notification" - ); - form.destroy(); }); @@ -339,6 +343,21 @@ QUnit.module('hr', {}, function () { return this._super(...arguments); }, res_id: 1, + services: { + notification: { + notify(notification) { + assert.ok( + true, + "should display a toast notification after failing to open chat" + ); + assert.strictEqual( + notification.message, + "You can only chat with employees that have a dedicated user.", + "should display the correct information in the notification" + ); + }, + }, + }, }); mock.intercept(form, 'call_service', (ev) => { @@ -363,16 +382,6 @@ QUnit.module('hr', {}, function () { "read hr.employee.public 23" ]); - assert.containsOnce( - document.body, - '.toast .o_notification_content', - "should display a toast notification after failing to open chat" - ); - assert.strictEqual( - document.querySelector('.o_notification_content').textContent, - "You can only chat with employees that have a dedicated user.", - "should display the correct information in the notification" - ); assert.containsOnce(document.body, '.o_ChatWindowHeader_name', "should have 1 chat window"); diff --git a/addons/mail/static/src/components/discuss/tests/discuss_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_tests.js index 6858974b896..0d3d8af6094 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -3235,6 +3235,21 @@ QUnit.test('reply to message from inbox (message linked to document)', async fun } return this._super(...arguments); }, + services: { + notification: { + notify(notification) { + assert.ok( + true, + "should display a notification after posting reply" + ); + assert.strictEqual( + notification.message, + "Message posted on \"Refactoring\"", + "notification should tell that message has been posted to the record 'Refactoring'" + ); + } + } + }, }); assert.strictEqual( document.querySelectorAll('.o_Message').length, @@ -3299,15 +3314,6 @@ QUnit.test('reply to message from inbox (message linked to document)', async fun document.querySelector('.o_Message').classList.contains('o-selected'), "message should not longer be selected after posting reply" ); - assert.ok( - document.querySelector('.o_notification'), - "should display a notification after posting reply" - ); - assert.strictEqual( - document.querySelector('.o_notification_content').textContent, - "Message posted on \"Refactoring\"", - "notification should tell that message has been posted to the record 'Refactoring'" - ); }); QUnit.test('load recent messages from thread (already loaded some old messages)', async function (assert) { diff --git a/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js b/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js index 7db5fab7285..be66f735685 100644 --- a/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js +++ b/addons/mail/static/src/components/messaging_menu/messaging_menu_tests.js @@ -988,7 +988,7 @@ QUnit.test('rendering without OdooBot has a request (accepted)', async function }); QUnit.test('respond to notification prompt (denied)', async function (assert) { - assert.expect(3); + assert.expect(4); await this.start({ env: { @@ -1001,6 +1001,15 @@ QUnit.test('respond to notification prompt (denied)', async function (assert) { }, }, }, + services: { + notification: { + notify() { + assert.step( + "should display a toast notification with the deny confirmation" + ); + } + } + } }, }); @@ -1010,11 +1019,10 @@ QUnit.test('respond to notification prompt (denied)', async function (assert) { await afterNextRender(() => document.querySelector('.o_NotificationRequest').click() ); - assert.containsOnce( - document.body, - '.toast .o_notification_content', - "should display a toast notification with the deny confirmation" - ); + assert.verifySteps([ + "should display a toast notification with the deny confirmation", + ]); + assert.containsNone( document.body, '.o_MessagingMenu_counter', diff --git a/addons/mail/static/src/models/messaging/messaging_tests.js b/addons/mail/static/src/models/messaging/messaging_tests.js index 92b3e32fd63..5d3dccf5846 100644 --- a/addons/mail/static/src/models/messaging/messaging_tests.js +++ b/addons/mail/static/src/models/messaging/messaging_tests.js @@ -26,38 +26,50 @@ QUnit.test('openChat: display notification for partner without user', async func assert.expect(2); this.data['res.partner'].records.push({ id: 14 }); - await this.start(); + await this.start({ + services: { + notification: { + notify(notification) { + assert.ok( + true, + "should display a toast notification after failing to open chat" + ); + assert.strictEqual( + notification.message, + "You can only chat with partners that have a dedicated user.", + "should display the correct information in the notification" + ); + }, + }, + }, + }); await this.env.messaging.openChat({ partnerId: 14 }); - assert.containsOnce( - document.body, - '.toast .o_notification_content', - "should display a toast notification after failing to open chat" - ); - assert.strictEqual( - document.querySelector('.o_notification_content').textContent, - "You can only chat with partners that have a dedicated user.", - "should display the correct information in the notification" - ); }); QUnit.test('openChat: display notification for wrong user', async function (assert) { assert.expect(2); - await this.start(); + await this.start({ + services: { + notification: { + notify(notification) { + assert.ok( + true, + "should display a toast notification after failing to open chat" + ); + assert.strictEqual( + notification.message, + "You can only chat with existing users.", + "should display the correct information in the notification" + ); + }, + }, + }, + }); // user id not in this.data await this.env.messaging.openChat({ userId: 14 }); - assert.containsOnce( - document.body, - '.toast .o_notification_content', - "should display a toast notification after failing to open chat" - ); - assert.strictEqual( - document.querySelector('.o_notification_content').textContent, - "You can only chat with existing users.", - "should display the correct information in the notification" - ); }); QUnit.test('openChat: open new chat for user', async function (assert) { diff --git a/addons/mail/static/src/utils/test_utils.js b/addons/mail/static/src/utils/test_utils.js index cc288f2f49f..a5c1d6b1770 100644 --- a/addons/mail/static/src/utils/test_utils.js +++ b/addons/mail/static/src/utils/test_utils.js @@ -15,7 +15,6 @@ import MessagingMenuWidget from '@mail/widgets/messaging_menu/messaging_menu'; import { MockModels } from '@mail/../tests/helpers/mock_models'; import AbstractStorageService from 'web.AbstractStorageService'; -import NotificationService from 'web.NotificationService'; import RamStorage from 'web.RamStorage'; import { createView, @@ -523,7 +522,6 @@ async function start(param0 = {}) { _listenHomeMenu: () => {}, }), local_storage: AbstractStorageService.extend({ storage: new RamStorage() }), - notification: NotificationService.extend(), }, param0.services); const kwargs = Object.assign({}, param0, { diff --git a/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js b/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js index af7ee95e274..00a4e8aa03e 100644 --- a/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js +++ b/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js @@ -6,7 +6,6 @@ odoo.define('partner_autocomplete.tests', function (require) { var testUtils = require("web.test_utils"); var AutocompleteField = require('partner.autocomplete.fieldchar'); var PartnerField = require('partner.autocomplete.many2one'); - var NotificationService = require('web.NotificationService'); var createView = testUtils.createView; @@ -377,7 +376,7 @@ odoo.define('partner_autocomplete.tests', function (require) { }); QUnit.test("Partner autocomplete : Notify not enough credits", async function (assert) { - assert.expect(1); + assert.expect(2); enrichData = { error: true, @@ -394,7 +393,12 @@ odoo.define('partner_autocomplete.tests', function (require) { '' + '', services: { - notification: NotificationService, + notification: { + notify(notification) { + assert.equal(notification.type, "warning"); + assert.equal(notification.className, "o_partner_autocomplete_test_notify"); + }, + }, }, mockRPC: function (route, args) { if (args.method === "get_credits_url"){ @@ -413,9 +417,6 @@ odoo.define('partner_autocomplete.tests', function (require) { var $dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible"); await testUtils.dom.click($dropdown.find("a").first()); - var $notify = $(".o_partner_autocomplete_test_notify"); - assert.isVisible($notify, "there should be an 'Insufficient Credit' notification"); - form.destroy(); }); }); diff --git a/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js index aea12de8184..c25a871e586 100644 --- a/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js @@ -6,11 +6,9 @@ var AbstractField = require('web.AbstractField'); var AbstractStorageService = require('web.AbstractStorageService'); const ControlPanel = require('web.ControlPanel'); const fieldRegistry = require('web.field_registry'); -var FormController = require('web.FormController'); var FormView = require('web.FormView'); var KanbanRecord = require('web.KanbanRecord'); var ListRenderer = require('web.ListRenderer'); -var NotificationService = require('web.NotificationService'); var RamStorage = require('web.RamStorage'); var relationalFields = require('web.relational_fields'); var testUtils = require('web.test_utils'); @@ -5832,11 +5830,11 @@ QUnit.module('fields', {}, function () { }, res_id: 1, services: { - notification: NotificationService.extend({ + notification: { notify: function (params) { assert.step(params.type); } - }), + }, }, intercepts: { execute_action: function (event) { diff --git a/addons/web/static/tests/legacy/views/form_tests.js b/addons/web/static/tests/legacy/views/form_tests.js index cf79de76a93..395b290b4c3 100644 --- a/addons/web/static/tests/legacy/views/form_tests.js +++ b/addons/web/static/tests/legacy/views/form_tests.js @@ -11,7 +11,6 @@ const fieldRegistryOwl = require('web.field_registry_owl'); const FormRenderer = require('web.FormRenderer'); var FormView = require('web.FormView'); var mixins = require('web.mixins'); -var NotificationService = require('web.NotificationService'); var pyUtils = require('web.py_utils'); var RamStorage = require('web.RamStorage'); var testUtils = require('web.test_utils'); @@ -3599,7 +3598,7 @@ QUnit.module('Views', { '' + '', services: { - notification: NotificationService.extend({ + notification: { notify: function (params) { if (params.type !== 'danger') { return; @@ -3609,7 +3608,7 @@ QUnit.module('Views', { assert.strictEqual(params.message, '', "should have a warning with correct message"); } - }), + }, }, }); @@ -6140,11 +6139,11 @@ QUnit.module('Views', { return result; }, services: { - notification: NotificationService.extend({ + notification: { notify: function (params) { assert.step(params.type); } - }), + }, }, }); diff --git a/addons/web/static/tests/legacy/views/list_tests.js b/addons/web/static/tests/legacy/views/list_tests.js index 6ddcb1862a3..e3fe29ae32a 100644 --- a/addons/web/static/tests/legacy/views/list_tests.js +++ b/addons/web/static/tests/legacy/views/list_tests.js @@ -13,7 +13,6 @@ var FormView = require('web.FormView'); var ListRenderer = require('web.ListRenderer'); var ListView = require('web.ListView'); var mixins = require('web.mixins'); -var NotificationService = require('web.NotificationService'); var RamStorage = require('web.RamStorage'); var testUtils = require('web.test_utils'); const { patch, unpatch } = require('web.utils'); @@ -3463,11 +3462,11 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, services: { - notification: NotificationService.extend({ + notification: { notify: function () { throw new Error('should not display a notification'); }, - }), + }, }, viewOptions: { hasActionMenus: true, @@ -3511,11 +3510,11 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, services: { - notification: NotificationService.extend({ + notification: { notify: function () { assert.step('notify'); }, - }), + }, }, session: { active_ids_limit: 4, @@ -3613,11 +3612,11 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, services: { - notification: NotificationService.extend({ + notification: { notify: function () { throw new Error('should not display a notification'); }, - }), + }, }, viewOptions: { hasActionMenus: true, @@ -3664,11 +3663,11 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, services: { - notification: NotificationService.extend({ + notification: { notify: function () { assert.step('notify'); }, - }), + }, }, session: { active_ids_limit: 4, @@ -5771,13 +5770,13 @@ QUnit.module('Views', { '' + '', services: { - notification: NotificationService.extend({ + notification: { notify: function (params) { if (params.type === 'danger') { warnings++; } } - }), + }, }, });