[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
This commit is contained in:
Samuel Degueldre
2021-07-14 07:34:18 +00:00
parent db7b485d98
commit 08afc0af8f
10 changed files with 120 additions and 91 deletions
@@ -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) {
'</form>',
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',
@@ -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");
@@ -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) {
@@ -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',
@@ -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) {
@@ -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, {
@@ -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) {
'<field name="name" widget="field_partner_autocomplete"/>' +
'</form>',
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();
});
});
@@ -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) {
@@ -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', {
'<group><field name="foo"/></group>' +
'</form>',
services: {
notification: NotificationService.extend({
notification: {
notify: function (params) {
if (params.type !== 'danger') {
return;
@@ -3609,7 +3608,7 @@ QUnit.module('Views', {
assert.strictEqual(params.message, '<ul><li>Foo</li></ul>',
"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);
}
}),
},
},
});
@@ -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', {
'<field name="bar"/>' +
'</tree>',
services: {
notification: NotificationService.extend({
notification: {
notify: function (params) {
if (params.type === 'danger') {
warnings++;
}
}
}),
},
},
});