[IMP] mail: adapt remaining tests data seeding

task-2792108

closes odoo/odoo#87430

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
tsm-odoo
2022-03-30 13:04:58 +02:00
parent 0097bd77e9
commit 1da8863a7d
22 changed files with 398 additions and 622 deletions
@@ -1,112 +1,22 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import FormView from 'web.FormView';
import ListView from 'web.ListView';
import testUtils from 'web.test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('Chatter', {
async beforeEach() {
await beforeEach(this);
this.data['res.partner'].records.push({ id: 11, im_status: 'online' });
this.data['mail.activity.type'].records.push(
{ id: 1, name: "Type 1" },
{ id: 2, name: "Type 2" },
{ id: 3, name: "Type 3", category: 'upload_file' },
{ id: 4, name: "Exception", decoration_type: "warning", icon: "fa-warning" }
);
this.data['ir.attachment'].records.push(
{
id: 1,
mimetype: 'image/png',
name: 'filename.jpg',
res_id: 7,
res_model: 'res.users',
type: 'url',
},
{
id: 2,
mimetype: "application/x-msdos-program",
name: "file2.txt",
res_id: 7,
res_model: 'res.users',
type: 'binary',
},
{
id: 3,
mimetype: "application/x-msdos-program",
name: "file3.txt",
res_id: 5,
res_model: 'res.users',
type: 'binary',
},
);
Object.assign(this.data['res.users'].fields, {
activity_exception_decoration: {
string: 'Decoration',
type: 'selection',
selection: [['warning', 'Alert'], ['danger', 'Error']],
},
activity_exception_icon: {
string: 'icon',
type: 'char',
},
activity_ids: {
string: 'Activities',
type: 'one2many',
relation: 'mail.activity',
relation_field: 'res_id',
},
activity_state: {
string: 'State',
type: 'selection',
selection: [['overdue', 'Overdue'], ['today', 'Today'], ['planned', 'Planned']],
},
activity_summary: {
string: "Next Activity Summary",
type: 'char',
},
activity_type_icon: {
string: "Activity Type Icon",
type: 'char',
},
activity_type_id: {
string: "Activity type",
type: "many2one",
relation: "mail.activity.type",
},
foo: { string: "Foo", type: "char", default: "My little Foo Value" },
message_attachment_count: {
string: 'Attachment count',
type: 'integer',
},
message_follower_ids: {
string: "Followers",
type: "one2many",
relation: 'mail.followers',
relation_field: "res_id",
},
message_ids: {
string: "messages",
type: "one2many",
relation: 'mail.message',
relation_field: "res_id",
},
});
},
});
QUnit.module('Chatter');
QUnit.test('list activity widget with no activity', async function (assert) {
assert.expect(4);
const pyEnv = await startServer();
const { widget: list } = await start({
hasView: true,
View: ListView,
model: 'res.users',
data: this.data,
arch: '<list><field name="activity_ids" widget="list_activity"/></list>',
mockRPC: function (route) {
if (!['/mail/init_messaging', '/mail/load_message_failures'].includes(route)) {
@@ -114,7 +24,7 @@ QUnit.test('list activity widget with no activity', async function (assert) {
}
return this._super(...arguments);
},
session: { uid: 2 },
session: { uid: pyEnv.currentUserId },
});
assert.containsOnce(list, '.o_mail_activity .o_activity_color_default');
@@ -128,30 +38,30 @@ QUnit.test('list activity widget with no activity', async function (assert) {
QUnit.test('list activity widget with activities', async function (assert) {
assert.expect(6);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
const pyEnv = await startServer();
const [mailActivityId1, mailActivityId2] = pyEnv['mail.activity'].create([{}, {}]);
const [mailActivityTypeId1, mailActivityTypeId2] = pyEnv['mail.activity.type'].create(
[{ name: 'Type 1' }, { name: 'Type 2' }],
);
Object.assign(currentUser, {
activity_ids: [1, 4],
pyEnv['res.users'].write([pyEnv.currentUserId], {
activity_ids: [mailActivityId1, mailActivityId2],
activity_state: 'today',
activity_summary: 'Call with Al',
activity_type_id: 3,
activity_type_id: mailActivityTypeId1,
activity_type_icon: 'fa-phone',
});
this.data['res.users'].records.push({
id: 44,
activity_ids: [2],
pyEnv['res.users'].create({
activity_ids: [mailActivityId2],
activity_state: 'planned',
activity_summary: false,
activity_type_id: 2,
activity_type_id: mailActivityTypeId2,
});
const { widget: list } = await start({
hasView: true,
View: ListView,
model: 'res.users',
data: this.data,
arch: '<list><field name="activity_ids" widget="list_activity"/></list>',
mockRPC: function (route) {
if (!['/mail/init_messaging', '/mail/load_message_failures'].includes(route)) {
@@ -177,14 +87,14 @@ QUnit.test('list activity widget with activities', async function (assert) {
QUnit.test('list activity widget with exception', async function (assert) {
assert.expect(4);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
);
Object.assign(currentUser, {
activity_ids: [1],
const pyEnv = await startServer();
const mailActivityId1 = pyEnv['mail.activity'].create();
const mailActivityTypeId1 = pyEnv['mail.activity.type'].create();
pyEnv['res.users'].write([pyEnv.currentUserId], {
activity_ids: [mailActivityId1],
activity_state: 'today',
activity_summary: 'Call with Al',
activity_type_id: 3,
activity_type_id: mailActivityTypeId1,
activity_exception_decoration: 'warning',
activity_exception_icon: 'fa-warning',
});
@@ -193,7 +103,6 @@ QUnit.test('list activity widget with exception', async function (assert) {
hasView: true,
View: ListView,
model: 'res.users',
data: this.data,
arch: '<list><field name="activity_ids" widget="list_activity"/></list>',
mockRPC: function (route) {
if (!['/mail/init_messaging', '/mail/load_message_failures'].includes(route)) {
@@ -214,46 +123,41 @@ QUnit.test('list activity widget with exception', async function (assert) {
QUnit.test('list activity widget: open dropdown', async function (assert) {
assert.expect(9);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
);
Object.assign(currentUser, {
activity_ids: [1, 4],
activity_state: 'today',
activity_summary: 'Call with Al',
activity_type_id: 3,
});
this.data['mail.activity'].records.push(
const pyEnv = await startServer();
const [mailActivityTypeId1, mailActivityTypeId2] = pyEnv['mail.activity.type'].create([{}, {}]);
const [mailActivityId1, mailActivityId2] = pyEnv['mail.activity'].create([
{
id: 1,
display_name: "Call with Al",
date_deadline: moment().format("YYYY-MM-DD"), // now
can_write: true,
state: "today",
user_id: this.data.currentUserId,
create_uid: this.data.currentUserId,
activity_type_id: 3,
user_id: pyEnv.currentUserId,
create_uid: pyEnv.currentUserId,
activity_type_id: mailActivityTypeId1,
},
{
id: 4,
display_name: "Meet FP",
date_deadline: moment().add(1, 'day').format("YYYY-MM-DD"), // tomorrow
can_write: true,
state: "planned",
user_id: this.data.currentUserId,
create_uid: this.data.currentUserId,
activity_type_id: 1,
user_id: pyEnv.currentUserId,
create_uid: pyEnv.currentUserId,
activity_type_id: mailActivityTypeId2,
}
);
]);
pyEnv['res.users'].write([pyEnv.currentUserId], {
activity_ids: [mailActivityId1, mailActivityId2],
activity_state: 'today',
activity_summary: 'Call with Al',
activity_type_id: mailActivityTypeId2,
});
const { widget: list } = await start({
hasView: true,
View: ListView,
model: 'res.users',
data: this.data,
arch: `
<list>
<field name="foo"/>
<field name="activity_ids" widget="list_activity"/>
</list>`,
mockRPC: function (route, args) {
@@ -261,14 +165,11 @@ QUnit.test('list activity widget: open dropdown', async function (assert) {
assert.step(args.method || route);
}
if (args.method === 'action_feedback') {
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.currentUserId
);
Object.assign(currentUser, {
activity_ids: [4],
pyEnv['res.users'].write([pyEnv.currentUserId], {
activity_ids: [mailActivityId2],
activity_state: 'planned',
activity_summary: 'Meet FP',
activity_type_id: 1,
activity_type_id: mailActivityTypeId1,
});
return Promise.resolve();
}
@@ -310,51 +211,44 @@ QUnit.test('list activity widget: open dropdown', async function (assert) {
QUnit.test('list activity exception widget with activity', async function (assert) {
assert.expect(3);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
);
currentUser.activity_ids = [1];
this.data['res.users'].records.push({
id: 13,
message_attachment_count: 3,
display_name: "second partner",
foo: "Tommy",
message_follower_ids: [],
message_ids: [],
activity_ids: [2],
activity_exception_decoration: 'warning',
activity_exception_icon: 'fa-warning',
});
this.data['mail.activity'].records.push(
const pyEnv = await startServer();
const [mailActivityTypeId1, mailActivityTypeId2] = pyEnv['mail.activity.type'].create([{}, {}]);
const [mailActivityId1, mailActivityId2] = pyEnv['mail.activity'].create([
{
id: 1,
display_name: "An activity",
date_deadline: moment().format("YYYY-MM-DD"), // now
can_write: true,
state: "today",
user_id: 2,
create_uid: 2,
activity_type_id: 1,
user_id: pyEnv.currentUserId,
create_uid: pyEnv.currentUserId,
activity_type_id: mailActivityTypeId1,
},
{
id: 2,
display_name: "An exception activity",
date_deadline: moment().format("YYYY-MM-DD"), // now
can_write: true,
state: "today",
user_id: 2,
create_uid: 2,
activity_type_id: 4,
user_id: pyEnv.currentUserId,
create_uid: pyEnv.currentUserId,
activity_type_id: mailActivityTypeId2,
}
);
]);
pyEnv['res.users'].write([pyEnv.currentUserId], { activity_ids: [mailActivityId1] });
pyEnv['res.users'].create({
message_attachment_count: 3,
display_name: "second partner",
message_follower_ids: [],
message_ids: [],
activity_ids: [mailActivityId2],
activity_exception_decoration: 'warning',
activity_exception_icon: 'fa-warning',
});
const { widget: list } = await start({
hasView: true,
View: ListView,
model: 'res.users',
data: this.data,
arch: '<tree>' +
'<field name="foo"/>' +
'<field name="activity_exception_decoration" widget="activity_exception"/> ' +
'</tree>',
});
@@ -368,36 +262,27 @@ QUnit.test('list activity exception widget with activity', async function (asser
list.destroy();
});
QUnit.module('FieldMany2ManyTagsEmail', {
async beforeEach() {
await beforeEach(this);
QUnit.module('FieldMany2ManyTagsEmail');
this.data['mail.message'].records.push({
id: 11,
display_name: "first record",
partner_ids: [],
});
this.data['res.partner'].records.push(
{ id: 12, name: "gold", email: 'coucou@petite.perruche' },
{ id: 14, name: "silver", email: '' },
);
},
});
QUnit.test('fieldmany2many tags email', function (assert) {
QUnit.test('fieldmany2many tags email', async function (assert) {
assert.expect(13);
var done = assert.async();
const message11 = this.data['mail.message'].records.find(message => message.id === 11);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ name: "gold", email: 'coucou@petite.perruche' },
{ name: "silver", email: '' },
]);
const mailMessageId1 = pyEnv['mail.message'].create({
partner_ids: [resPartnerId1, resPartnerId2],
});
message11.partner_ids = [12, 14];
// the modals need to be closed before the form view rendering
start({
hasView: true,
View: FormView,
model: 'mail.message',
data: this.data,
res_id: 11,
res_id: mailMessageId1,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="body"/>' +
@@ -419,7 +304,7 @@ QUnit.test('fieldmany2many tags email', function (assert) {
},
}).then(async function ({ widget: form }) {
// should read it 3 times (1 with the form view, one with the form dialog and one after save)
assert.verifySteps(['[12,14]', '[14]', '[14]']);
assert.verifySteps([`[${resPartnerId1},${resPartnerId2}]`, `[${resPartnerId2}]`, `[${resPartnerId2}]`]);
await testUtils.nextTick();
assert.containsN(form, '.o_field_many2manytags[name="partner_ids"] .badge.o_tag_color_0', 2,
"two tags should be present");
@@ -435,7 +320,7 @@ QUnit.test('fieldmany2many tags email', function (assert) {
assert.strictEqual($('.modal-body.o_act_window').length, 1,
"there should be one modal opened to edit the empty email");
assert.strictEqual($('.modal-body.o_act_window input[name="name"]').val(), "silver",
"the opened modal should be a form view dialog with the res.partner 14");
"the opened modal should be a form view dialog with the res.partner 2");
assert.strictEqual($('.modal-body.o_act_window input[name="email"]').length, 1,
"there should be an email field in the modal");
@@ -449,15 +334,20 @@ QUnit.test('fieldmany2many tags email', function (assert) {
QUnit.test('fieldmany2many tags email (edition)', async function (assert) {
assert.expect(15);
const message11 = this.data['mail.message'].records.find(message => message.id === 11);
message11.partner_ids = [12];
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ name: "gold", email: 'coucou@petite.perruche' },
{ name: "silver", email: '' },
]);
const mailMessageId1 = pyEnv['mail.message'].create({
partner_ids: [resPartnerId1],
});
var { widget: form } = await start({
hasView: true,
View: FormView,
model: 'mail.message',
data: this.data,
res_id: 11,
res_id: mailMessageId1,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="body"/>' +
@@ -479,7 +369,7 @@ QUnit.test('fieldmany2many tags email (edition)', async function (assert) {
},
});
assert.verifySteps(['[12]']);
assert.verifySteps([`[${resPartnerId1}]`]);
assert.containsOnce(form, '.o_field_many2manytags[name="partner_ids"] .badge.o_tag_color_0',
"should contain one tag");
@@ -500,9 +390,9 @@ QUnit.test('fieldmany2many tags email (edition)', async function (assert) {
assert.containsN(form, '.o_field_many2manytags[name="partner_ids"] .badge.o_tag_color_0', 2,
"should contain the second tag");
// should have read [14] three times: when opening the dropdown, when opening the modal, and
// should have read resPartnerId2 three times: when opening the dropdown, when opening the modal, and
// after the save
assert.verifySteps(['[14]', '[14]', '[14]']);
assert.verifySteps([`[${resPartnerId2}]`, `[${resPartnerId2}]`, `[${resPartnerId2}]`]);
form.destroy();
});
@@ -510,20 +400,21 @@ QUnit.test('fieldmany2many tags email (edition)', async function (assert) {
QUnit.test('many2many_tags_email widget can load more than 40 records', async function (assert) {
assert.expect(3);
const message11 = this.data['mail.message'].records.find(message => message.id === 11);
message11.partner_ids = [];
const pyEnv = await startServer();
const messagePartnerIds = [];
for (let i = 100; i < 200; i++) {
this.data['res.partner'].records.push({ id: i, display_name: `partner${i}` });
message11.partner_ids.push(i);
messagePartnerIds.push(pyEnv['res.partner'].create({ display_name: `partner${i}` }));
}
const mailMessageId1 = pyEnv['mail.message'].create({
partner_ids: messagePartnerIds,
});
const { widget: form } = await start({
hasView: true,
View: FormView,
model: 'mail.message',
data: this.data,
arch: '<form><field name="partner_ids" widget="many2many_tags"/></form>',
res_id: 11,
res_id: mailMessageId1,
});
assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge').length, 100);
@@ -1,7 +1,7 @@
/** @odoo-module **/
import { Many2OneAvatarUser } from '@mail/js/m2x_avatar_user';
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import { click, getFixture, legacyExtraNextTick, patchWithCleanup, triggerHotkey } from "@web/../tests/helpers/utils";
import { doAction } from '@web/../tests/webclient/helpers';
import { registry } from "@web/core/registry";
@@ -18,30 +18,9 @@ let target;
QUnit.module('mail', {}, function () {
QUnit.module('M2XAvatarUser', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
// reset the cache before each test
Many2OneAvatarUser.prototype.partnerIds = {};
this.data['m2x.avatar.user'].records.push(
{ id: 1, user_id: 11, user_ids: [11, 23], },
{ id: 2, user_id: 7 },
{ id: 3, user_id: 11 },
{ id: 4, user_id: 23 },
);
this.data['res.partner'].records.push(
{ id: 11, display_name: "Partner 1" },
{ id: 12, display_name: "Partner 2" },
{ id: 13, display_name: "Partner 3" }
);
this.data['res.users'].records.push(
{ id: 11, name: "Mario", partner_id: 11 },
{ id: 7, name: "Luigi", partner_id: 12 },
{ id: 23, name: "Yoshi", partner_id: 13 }
);
target = getFixture();
},
});
@@ -49,12 +28,15 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2one_avatar_user widget in list view', async function (assert) {
assert.expect(2);
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: 'Partner 1' });
const resUsersId1 = pyEnv['res.users'].create({ name: "Mario", partner_id: resPartnerId1 });
pyEnv['m2x.avatar.user'].create({ user_id: resUsersId1 });
const { widget: list } = await start({
hasChatWindow: true,
hasView: true,
View: ListView,
model: 'm2x.avatar.user',
data: this.data,
arch: '<tree><field name="user_id" widget="many2one_avatar_user"/></tree>',
});
@@ -72,14 +54,17 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2many_avatar_user widget in form view', async function (assert) {
assert.expect(2);
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: 'Partner 1' });
const resUsersId1 = pyEnv['res.users'].create({ name: "Mario", partner_id: resPartnerId1 });
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_ids: [resUsersId1] });
const { widget: form } = await start({
hasChatWindow: true,
hasView: true,
View: FormView,
model: 'm2x.avatar.user',
data: this.data,
arch: '<form><field name="user_ids" widget="many2many_avatar_user"/></form>',
res_id: 1,
res_id: m2xAvatarUserId1,
});
await dom.click(form.$('.o_field_many2manytags.avatar .badge:first .o_m2m_avatar'));
@@ -96,14 +81,16 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2many_avatar_user in kanban view', async function (assert) {
assert.expect(4);
this.data['res.users'].records.push({ id: 15, name: "Tapu", partner_id: 11 },);
this.data['m2x.avatar.user'].records[2].user_ids = [11, 23, 7, 15];
const pyEnv = await startServer();
const resUsersIds = pyEnv['res.users'].create(
[{ name: "Mario" }, { name: "Yoshi" }, { name: "Luigi" }, { name: "Tapu" }],
);
pyEnv['m2x.avatar.user'].create({ user_ids: resUsersIds });
const { widget: kanban } = await start({
hasView: true,
View: KanbanView,
model: 'm2x.avatar.user',
data: this.data,
arch: `
<kanban>
<templates>
@@ -123,12 +110,12 @@ QUnit.module('mail', {}, function () {
</kanban>`,
});
assert.containsOnce(kanban, '.o_kanban_record:eq(2) .o_field_many2manytags .o_m2m_avatar_empty',
assert.containsOnce(kanban, '.o_kanban_record .o_field_many2manytags .o_m2m_avatar_empty',
"should have o_m2m_avatar_empty span");
assert.strictEqual(kanban.$('.o_kanban_record:eq(2) .o_field_many2manytags .o_m2m_avatar_empty').text().trim(), "+2",
assert.strictEqual(kanban.$('.o_kanban_record .o_field_many2manytags .o_m2m_avatar_empty').text().trim(), "+2",
"should have +2 in o_m2m_avatar_empty");
kanban.$('.o_kanban_record:eq(2) .o_field_many2manytags .o_m2m_avatar_empty').trigger($.Event('mouseenter'));
kanban.$('.o_kanban_record .o_field_many2manytags .o_m2m_avatar_empty').trigger($.Event('mouseenter'));
await nextTick();
assert.containsOnce(kanban, '.popover',
"should open a popover hover on o_m2m_avatar_empty");
@@ -141,6 +128,11 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2one_avatar_user widget edited by the smart action "Assign to..."', async function (assert) {
assert.expect(4);
const pyEnv = await startServer();
const [resUsersId1] = pyEnv['res.users'].create(
[{ name: "Mario" }, { name: "Luigi" }, { name: "Yoshi" }],
);
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_id: resUsersId1 });
const legacyEnv = makeTestEnvironment({ bus: core.bus });
const serviceRegistry = registry.category("services");
serviceRegistry.add("legacy_command", makeLegacyCommandService(legacyEnv));
@@ -149,10 +141,9 @@ QUnit.module('mail', {}, function () {
'm2x.avatar.user,false,form': '<form><field name="user_id" widget="many2one_avatar_user"/></form>',
'm2x.avatar.user,false,search': '<search></search>',
};
const serverData = { models: this.data, views };
const { widget: webClient } = await start({ hasWebClient: true, serverData });
const { widget: webClient } = await start({ hasWebClient: true, serverData: { views } });
await doAction(webClient, {
res_id: 1,
res_id: m2xAvatarUserId1,
type: 'ir.actions.act_window',
target: 'current',
res_model: 'm2x.avatar.user',
@@ -183,7 +174,10 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2one_avatar_user widget edited by the smart action "Assign to me"', async function (assert) {
assert.expect(4);
patchWithCleanup(session, { user_id: [7] })
const pyEnv = await startServer();
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{ name: "Mario" }, { name: "Luigi" }]);
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_id: resUsersId1 });
patchWithCleanup(session, { user_id: [resUsersId2] });
const legacyEnv = makeTestEnvironment({ bus: core.bus });
const serviceRegistry = registry.category("services");
serviceRegistry.add("legacy_command", makeLegacyCommandService(legacyEnv));
@@ -192,10 +186,9 @@ QUnit.module('mail', {}, function () {
'm2x.avatar.user,false,form': '<form><field name="user_id" widget="many2one_avatar_user"/></form>',
'm2x.avatar.user,false,search': '<search></search>',
};
const serverData = { models: this.data, views };
const { widget: webClient } = await start({ hasWebClient: true, serverData });
const { widget: webClient } = await start({ hasWebClient: true, serverData: { views } });
await doAction(webClient, {
res_id: 1,
res_id: m2xAvatarUserId1,
type: 'ir.actions.act_window',
target: 'current',
res_model: 'm2x.avatar.user',
@@ -224,6 +217,11 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2many_avatar_user widget edited by the smart action "Assign to..."', async function (assert) {
assert.expect(4);
const pyEnv = await startServer();
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create(
[{ name: "Mario" }, { name: "Yoshi" }, { name: "Luigi" }],
);
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_ids: [resUsersId1, resUsersId2] });
const legacyEnv = makeTestEnvironment({ bus: core.bus });
const serviceRegistry = registry.category("services");
serviceRegistry.add("legacy_command", makeLegacyCommandService(legacyEnv));
@@ -232,10 +230,9 @@ QUnit.module('mail', {}, function () {
'm2x.avatar.user,false,form': '<form><field name="user_ids" widget="many2many_avatar_user"/></form>',
'm2x.avatar.user,false,search': '<search></search>',
};
const serverData = { models: this.data, views };
const { widget: webClient } = await start({ hasWebClient: true, serverData });
const { widget: webClient } = await start({ hasWebClient: true, serverData: { views } });
await doAction(webClient, {
res_id: 1,
res_id: m2xAvatarUserId1,
type: 'ir.actions.act_window',
target: 'current',
res_model: 'm2x.avatar.user',
@@ -267,7 +264,12 @@ QUnit.module('mail', {}, function () {
QUnit.test('many2many_avatar_user widget edited by the smart action "Assign to me"', async function (assert) {
assert.expect(4);
patchWithCleanup(session, { user_id: [7] })
const pyEnv = await startServer();
const [resUsersId1, resUsersId2, resUsersId3] = pyEnv['res.users'].create(
[{ name: "Mario" }, { name: "Luigi" }, { name: "Yoshi" }],
);
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_ids: [resUsersId1, resUsersId3] });
patchWithCleanup(session, { user_id: [resUsersId2] });
const legacyEnv = makeTestEnvironment({ bus: core.bus });
const serviceRegistry = registry.category("services");
serviceRegistry.add("legacy_command", makeLegacyCommandService(legacyEnv));
@@ -276,10 +278,9 @@ QUnit.module('mail', {}, function () {
'm2x.avatar.user,false,form': '<form><field name="user_ids" widget="many2many_avatar_user"/></form>',
'm2x.avatar.user,false,search': '<search></search>',
};
const serverData = { models: this.data, views };
const { widget: webClient } = await start({ hasWebClient: true, serverData });
const { widget: webClient } = await start({ hasWebClient: true, serverData: { views } });
await doAction(webClient, {
res_id: 1,
res_id: m2xAvatarUserId1,
type: 'ir.actions.act_window',
target: 'current',
res_model: 'm2x.avatar.user',
@@ -312,17 +313,19 @@ QUnit.module('mail', {}, function () {
QUnit.test('avatar_user widget displays the appropriate user image in list view', async function (assert) {
assert.expect(1);
const pyEnv = await startServer();
const resUsersId1 = pyEnv['res.users'].create({ name: "Mario" });
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_id: resUsersId1 });
const { widget: list } = await start({
hasView: true,
View: ListView,
model: 'm2x.avatar.user',
data: this.data,
arch: '<tree><field name="user_id" widget="many2one_avatar_user"/></tree>',
res_id: 1,
res_id: m2xAvatarUserId1,
});
assert.strictEqual(
list.$('.o_m2o_avatar > img').data('src'),
'/web/image/res.users/11/avatar_128',
`/web/image/res.users/${resUsersId1}/avatar_128`,
'Should have correct avatar image'
);
list.destroy();
@@ -331,11 +334,13 @@ QUnit.module('mail', {}, function () {
QUnit.test('avatar_user widget displays the appropriate user image in kanban view', async function (assert) {
assert.expect(1);
const pyEnv = await startServer();
const resUsersId1 = pyEnv['res.users'].create({ name: "Mario" });
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_id: resUsersId1 });
const { widget: kanban } = await start({
hasView: true,
View: KanbanView,
model: 'm2x.avatar.user',
data: this.data,
arch: `<kanban>
<templates>
<t t-name="kanban-box">
@@ -345,11 +350,11 @@ QUnit.module('mail', {}, function () {
</t>
</templates>
</kanban>`,
res_id: 1,
res_id: m2xAvatarUserId1,
});
assert.strictEqual(
kanban.$('.o_m2o_avatar > img').data('src'),
'/web/image/res.users/11/avatar_128',
`/web/image/res.users/${resUsersId1}/avatar_128`,
'Should have correct avatar image'
);
kanban.destroy();
@@ -358,17 +363,19 @@ QUnit.module('mail', {}, function () {
QUnit.test('avatar_user widget displays the appropriate user image in form view', async function (assert) {
assert.expect(1);
const pyEnv = await startServer();
const resUsersId1 = pyEnv['res.users'].create({ name: "Mario" });
const m2xAvatarUserId1 = pyEnv['m2x.avatar.user'].create({ user_ids: [resUsersId1] });
const { widget: form } = await start({
hasView: true,
View: FormView,
model: 'm2x.avatar.user',
data: this.data,
arch: '<form><field name="user_ids" widget="many2many_avatar_user"/></form>',
res_id: 1,
res_id: m2xAvatarUserId1,
});
assert.strictEqual(
form.$('.o_field_many2manytags.avatar.o_field_widget .badge:first img').data('src'),
'/web/image/res.users/11/avatar_128',
`/web/image/res.users/${resUsersId1}/avatar_128`,
'Should have correct avatar image'
);
form.destroy();
@@ -1,22 +1,15 @@
/** @odoo-module **/
import { clear, insertAndReplace } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('clear_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('clear_tests.js');
QUnit.test('clear: should set attribute field undefined if there is no default value', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const task = messaging.models['TestTask'].create({
id: 1,
title: 'test title 1',
@@ -32,7 +25,7 @@ QUnit.test('clear: should set attribute field undefined if there is no default v
QUnit.test('clear: should set attribute field the default value', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const task = messaging.models['TestTask'].create({
id: 1,
difficulty: 5,
@@ -47,7 +40,7 @@ QUnit.test('clear: should set attribute field the default value', async function
QUnit.test('clear: should set x2one field undefined if no default value is given', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -69,7 +62,7 @@ QUnit.test('clear: should set x2one field undefined if no default value is given
QUnit.test('clear: should set x2one field the default value', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
favorite: insertAndReplace({ description: 'pingpong' }),
@@ -85,7 +78,7 @@ QUnit.test('clear: should set x2one field the default value', async function (as
QUnit.test('clear: should set x2many field empty array if no default value is given', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -107,7 +100,7 @@ QUnit.test('clear: should set x2many field empty array if no default value is gi
QUnit.test('clear: should set x2many field the default value', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -1,22 +1,15 @@
/** @odoo-module **/
import { insertAndReplace } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('insert_and_replace_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('insert_and_replace_tests.js');
QUnit.test('insertAndReplace: should create and link a new record for an empty x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
contact.update({ address: insertAndReplace({ id: 10 }) });
@@ -35,7 +28,7 @@ QUnit.test('insertAndReplace: should create and link a new record for an empty x
QUnit.test('insertAndReplace: should create and replace a new record for a non-empty x2one field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -63,7 +56,7 @@ QUnit.test('insertAndReplace: should create and replace a new record for a non-e
QUnit.test('insertAndReplace: should update the existing record for an x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -93,7 +86,7 @@ QUnit.test('insertAndReplace: should update the existing record for an x2one fie
QUnit.test('insertAndReplace: should create and replace the records for an x2many field', async function (assert) {
assert.expect(4);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -126,7 +119,7 @@ QUnit.test('insertAndReplace: should create and replace the records for an x2man
QUnit.test('insertAndReplace: should update and replace the records for an x2many field', async function (assert) {
assert.expect(4);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -1,22 +1,15 @@
/** @odoo-module **/
import { insert, insertAndReplace } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('insert_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('insert_tests.js');
QUnit.test('insert: should create and link a new record for an empty x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
contact.update({ address: insert({ id: 10 }) });
@@ -35,7 +28,7 @@ QUnit.test('insert: should create and link a new record for an empty x2one field
QUnit.test('insert: should create and replace a new record for a non-empty x2one field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -63,7 +56,7 @@ QUnit.test('insert: should create and replace a new record for a non-empty x2one
QUnit.test('insert: should update the existing record for an x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -93,7 +86,7 @@ QUnit.test('insert: should update the existing record for an x2one field', async
QUnit.test('insert: should create and link a new record for an x2many field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
contact.update({ tasks: insert({ id: 10 }) });
@@ -117,7 +110,7 @@ QUnit.test('insert: should create and link a new record for an x2many field', as
QUnit.test('insert: should create and add a new record for an x2many field', async function (assert) {
assert.expect(4);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -150,7 +143,7 @@ QUnit.test('insert: should create and add a new record for an x2many field', asy
QUnit.test('insert: should update existing records for an x2many field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -1,22 +1,15 @@
/** @odoo-module **/
import { insertAndReplace, link } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('field_command_link_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('field_command_link_tests.js');
QUnit.test('link: should link a record to an empty x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
const address = messaging.models['TestAddress'].create({ id: 10 });
@@ -35,7 +28,7 @@ QUnit.test('link: should link a record to an empty x2one field', async function
QUnit.test('link: should replace a record to a non-empty x2one field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -63,7 +56,7 @@ QUnit.test('link: should replace a record to a non-empty x2one field', async fun
QUnit.test('link: should link a record to an empty x2many field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
const task = messaging.models['TestTask'].create({ id: 10 });
@@ -87,7 +80,7 @@ QUnit.test('link: should link a record to an empty x2many field', async function
QUnit.test('link: should link and add a record to a non-empty x2many field', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -1,22 +1,15 @@
/** @odoo-module **/
import { insertAndReplace, replace } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('replace_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('replace_tests.js');
QUnit.test('replace: should link a record for an empty x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
const address = messaging.models['TestAddress'].create({ id: 10 });
@@ -35,7 +28,7 @@ QUnit.test('replace: should link a record for an empty x2one field', async funct
QUnit.test('replace: should replace a record for a non-empty x2one field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -63,7 +56,7 @@ QUnit.test('replace: should replace a record for a non-empty x2one field', async
QUnit.test('replace: should link a record for an empty x2many field', async function (assert) {
assert.expect(4);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({ id: 10 });
const task = messaging.models['TestTask'].create({ id: 10 });
@@ -92,7 +85,7 @@ QUnit.test('replace: should link a record for an empty x2many field', async func
QUnit.test('replace: should replace all records for a non-empty field', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -134,7 +127,7 @@ QUnit.test('replace: should replace all records for a non-empty field', async fu
QUnit.test('replace: should order the existing records for x2many field', async function (assert) {
assert.expect(3);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -5,22 +5,15 @@ import {
increment,
set
} from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('set_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('set_tests.js');
QUnit.test('decrement: should decrease attribute field value', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const task = messaging.models['TestTask'].create({
id: 10,
@@ -36,7 +29,7 @@ QUnit.test('decrement: should decrease attribute field value', async function (a
QUnit.test('increment: should increase attribute field value', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const task = messaging.models['TestTask'].create({
id: 10,
@@ -52,7 +45,7 @@ QUnit.test('increment: should increase attribute field value', async function (a
QUnit.test('set: should set a value for attribute field', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const task = messaging.models['TestTask'].create({
id: 10,
@@ -68,7 +61,7 @@ QUnit.test('set: should set a value for attribute field', async function (assert
QUnit.test('multiple attribute commands combination', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const task = messaging.models['TestTask'].create({
id: 10,
@@ -1,22 +1,15 @@
/** @odoo-module **/
import { insertAndReplace, unlinkAll } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('unlink_all_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('unlink_all_tests.js');
QUnit.test('unlinkAll: should set x2one field undefined', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -38,7 +31,7 @@ QUnit.test('unlinkAll: should set x2one field undefined', async function (assert
QUnit.test('unlinkAll: should set x2many field an empty array', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -1,23 +1,16 @@
/** @odoo-module **/
import { insertAndReplace, unlink } from '@mail/model/model_field_command';
import {
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('model_field_commands', {}, function () {
QUnit.module('unlink_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('unlink_tests.js');
QUnit.test('unlink: should unlink the record for x2one field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -39,7 +32,7 @@ QUnit.test('unlink: should unlink the record for x2one field', async function (a
QUnit.test('unlink: should unlink the specified record for x2many field', async function (assert) {
assert.expect(2);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const contact = messaging.models['TestContact'].create({
id: 10,
@@ -1,19 +1,15 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('models', {}, function () {
QUnit.module('attachment_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('attachment_tests.js');
QUnit.test('create (txt)', async function (assert) {
assert.expect(9);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }));
const attachment = messaging.models['Attachment'].create({
@@ -35,7 +31,7 @@ QUnit.test('create (txt)', async function (assert) {
QUnit.test('displayName', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }));
const attachment = messaging.models['Attachment'].create({
@@ -53,7 +49,7 @@ QUnit.test('displayName', async function (assert) {
QUnit.test('extension', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }));
const attachment = messaging.models['Attachment'].create({
@@ -71,7 +67,7 @@ QUnit.test('extension', async function (assert) {
QUnit.test('fileType', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }));
const attachment = messaging.models['Attachment'].create({
@@ -91,7 +87,7 @@ QUnit.test('fileType', async function (assert) {
QUnit.test('isTextFile', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }));
const attachment = messaging.models['Attachment'].create({
@@ -109,7 +105,7 @@ QUnit.test('isTextFile', async function (assert) {
QUnit.test('isViewable', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }));
const attachment = messaging.models['Attachment'].create({
@@ -1,20 +1,16 @@
/** @odoo-module **/
import { insertAndReplace } from '@mail/model/model_field_command';
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('models', {}, function () {
QUnit.module('clock_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('clock_tests.js');
QUnit.test('Deleting all the watchers of a clock should result in the deletion of the clock itself.', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const watcher = messaging.models['ClockWatcher'].insert({
clock: insertAndReplace({ frequency: 180 * 1000 }),
qunitTestOwner: insertAndReplace(),
@@ -1,6 +1,6 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import { file } from 'web.test_utils';
@@ -8,23 +8,20 @@ const { createFile, inputFiles } = file;
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('file_uploader', {}, function () {
QUnit.module('file_uploader_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('file_uploader_tests.js');
QUnit.test('no conflicts between file uploaders', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({ id: 100 }, { id: 101 });
const { afterNextRender, createChatterContainerComponent, messaging } = await start({ data: this.data });
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([{}, {}]);
const { afterNextRender, createChatterContainerComponent, messaging } = await start();
const firstChatterContainerComponent = await createChatterContainerComponent({
threadId: 100,
threadId: resPartnerId1,
threadModel: 'res.partner',
});
const secondChatterContainerComponent = await createChatterContainerComponent({
threadId: 101,
threadId: resPartnerId2,
threadModel: 'res.partner',
});
await afterNextRender(() => {
@@ -1,22 +1,18 @@
/** @odoo-module **/
import { insert, insertAndReplace, link } from '@mail/model/model_field_command';
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
import { str_to_datetime } from 'web.time';
QUnit.module('mail', {}, function () {
QUnit.module('models', {}, function () {
QUnit.module('message_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('message_tests.js');
QUnit.test('create', async function (assert) {
assert.expect(31);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Partner'].findFromIdentifyingData({ id: 5 }));
assert.notOk(messaging.models['Thread'].findFromIdentifyingData({
id: 100,
@@ -100,70 +96,70 @@ QUnit.test('create', async function (assert) {
QUnit.test('message without body should be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test('message with body "" should be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test('message with body "<p></p>" should be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<p></p>", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test('message with body "<p><br></p>" should be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<p><br></p>", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test('message with body "<p><br/></p>" should be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<p><br/></p>", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test(String.raw`message with body "<p>\n</p>" should be considered empty`, async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<p>\n</p>", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test(String.raw`message with body "<p>\r\n\r\n</p>" should be considered empty`, async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<p>\r\n\r\n</p>", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test('message with body "<p> </p> " should be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<p> </p> ", id: 11 });
assert.ok(message.isEmpty);
});
QUnit.test(`message with body "<img src=''>" should not be considered empty`, async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "<img src=''>", id: 11 });
assert.notOk(message.isEmpty);
});
QUnit.test('message with body "test" should not be considered empty', async function (assert) {
assert.expect(1);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const message = messaging.models['Message'].create({ body: "test", id: 11 });
assert.notOk(message.isEmpty);
});
@@ -1,19 +1,15 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('models', {}, function () {
QUnit.module('messaging_menu_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
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);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
messaging.models['Thread'].create({
id: 31,
isServerPinned: false,
@@ -1,21 +1,17 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('models', {}, function () {
QUnit.module('messaging_tests.js', {
async beforeEach() {
await beforeEach(this);
},
}, function () {
QUnit.module('messaging_tests.js', {}, function () {
QUnit.test('openChat: display notification for partner without user', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({ id: 14 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const { messaging } = await start({
data: this.data,
services: {
notification: {
notify(notification) {
@@ -33,14 +29,15 @@ QUnit.test('openChat: display notification for partner without user', async func
},
});
await messaging.openChat({ partnerId: 14 });
await messaging.openChat({ partnerId: resPartnerId1 });
});
QUnit.test('openChat: display notification for wrong user', async function (assert) {
assert.expect(2);
const pyEnv = await startServer();
pyEnv['res.users'].create();
const { messaging } = await start({
data: this.data,
services: {
notification: {
notify(notification) {
@@ -58,31 +55,32 @@ QUnit.test('openChat: display notification for wrong user', async function (asse
},
});
// user id not in this.data
await messaging.openChat({ userId: 14 });
// userId not in the server data
await messaging.openChat({ userId: 4242 });
});
QUnit.test('openChat: open new chat for user', async function (assert) {
assert.expect(3);
this.data['res.partner'].records.push({ id: 14 });
this.data['res.users'].records.push({ id: 11, partner_id: 14 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
pyEnv['res.users'].create({ partner_id: resPartnerId1 });
const { messaging } = await start({ data: this.data });
const existingChat = messaging.models['Thread'].find(thread =>
thread.channel_type === 'chat' &&
thread.correspondent &&
thread.correspondent.id === 14 &&
thread.correspondent.id === resPartnerId1 &&
thread.model === 'mail.channel' &&
thread.public === 'private'
);
assert.notOk(existingChat, 'a chat should not exist with the target partner initially');
await messaging.openChat({ partnerId: 14 });
await messaging.openChat({ partnerId: resPartnerId1 });
const chat = messaging.models['Thread'].find(thread =>
thread.channel_type === 'chat' &&
thread.correspondent &&
thread.correspondent.id === 14 &&
thread.correspondent.id === resPartnerId1 &&
thread.model === 'mail.channel' &&
thread.public === 'private'
);
@@ -93,28 +91,28 @@ QUnit.test('openChat: open new chat for user', async function (assert) {
QUnit.test('openChat: open existing chat for user', async function (assert) {
assert.expect(5);
this.data['res.partner'].records.push({ id: 14 });
this.data['res.users'].records.push({ id: 11, partner_id: 14 });
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
pyEnv['res.users'].create({ partner_id: resPartnerId1 });
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: "chat",
id: 10,
members: [this.data.currentPartnerId, 14],
members: [pyEnv.currentPartnerId, resPartnerId1],
public: 'private',
});
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const existingChat = messaging.models['Thread'].find(thread =>
thread.channel_type === 'chat' &&
thread.correspondent &&
thread.correspondent.id === 14 &&
thread.correspondent.id === resPartnerId1 &&
thread.model === 'mail.channel' &&
thread.public === 'private'
);
assert.ok(existingChat, 'a chat should initially exist with the target partner');
assert.strictEqual(existingChat.threadViews.length, 0, 'the chat should not be displayed in a `ThreadView`');
await messaging.openChat({ partnerId: 14 });
await messaging.openChat({ partnerId: resPartnerId1 });
assert.ok(existingChat, 'a chat should still exist with the target partner');
assert.strictEqual(existingChat.id, 10, 'the chat should be the existing chat');
assert.strictEqual(existingChat.id, mailChannelId1, 'the chat should be the existing chat');
assert.strictEqual(existingChat.threadViews.length, 1, 'the chat should now be displayed in a `ThreadView`');
});
@@ -3,7 +3,6 @@
import ActivityMenu from '@mail/js/systray/systray_activity_menu';
import {
afterNextRender,
beforeEach,
start,
} from '@mail/../tests/helpers/test_utils';
@@ -12,7 +11,6 @@ import testUtils from 'web.test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('ActivityMenu', {
async beforeEach() {
await beforeEach(this);
this.activities = [{
name: "Contact",
model: "res.partner",
@@ -69,7 +67,6 @@ QUnit.test('activity menu widget: menu with no records', async function (assert)
assert.expect(1);
const { widget } = await start({
data: this.data,
mockRPC: function (route, args) {
if (args.method === 'systray_get_activities') {
return Promise.resolve([]);
@@ -89,7 +86,6 @@ QUnit.test('activity menu widget: activity menu with 3 records', async function
var self = this;
const { widget } = await start({
data: this.data,
mockRPC: function (route, args) {
if (args.method === 'systray_get_activities') {
return Promise.resolve(self.activities);
@@ -151,7 +147,6 @@ QUnit.test('activity menu widget: activity view icon', async function (assert) {
var self = this;
const { widget } = await start({
data: this.data,
mockRPC: function (route, args) {
if (args.method === 'systray_get_activities') {
return Promise.resolve(self.activities);
@@ -212,7 +207,6 @@ QUnit.test('activity menu widget: close on messaging menu click', async function
assert.expect(2);
const { createMessagingMenuComponent, widget } = await start({
data: this.data,
async mockRPC(route, args) {
if (args.method === 'systray_get_activities') {
return [];
@@ -1,6 +1,6 @@
/** @odoo-module **/
import { beforeEach, nextTick, start } from '@mail/../tests/helpers/test_utils';
import { nextTick, start } from '@mail/../tests/helpers/test_utils';
import Timer from '@mail/utils/timer';
const { TimerClearedError } = Timer;
@@ -9,8 +9,7 @@ QUnit.module('mail', {}, function () {
QUnit.module('utils', {}, function () {
QUnit.module('timer', {}, function () {
QUnit.module('timer_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.timers = [];
},
afterEach() {
@@ -25,7 +24,7 @@ QUnit.module('timer_tests.js', {
QUnit.test('timer does not timeout on initialization', async function (assert) {
assert.expect(3);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -57,7 +56,7 @@ QUnit.test('timer does not timeout on initialization', async function (assert) {
QUnit.test('timer start (duration: 0ms)', async function (assert) {
assert.expect(2);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -84,7 +83,7 @@ QUnit.test('timer start (duration: 0ms)', async function (assert) {
QUnit.test('timer start observe termination (duration: 0ms)', async function (assert) {
assert.expect(6);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -131,7 +130,7 @@ QUnit.test('timer start observe termination (duration: 0ms)', async function (as
QUnit.test('timer start (duration: 1000s)', async function (assert) {
assert.expect(5);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -176,7 +175,7 @@ QUnit.test('timer start (duration: 1000s)', async function (assert) {
QUnit.test('[no cancelation intercept] timer start then immediate clear (duration: 0ms)', async function (assert) {
assert.expect(4);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -215,7 +214,7 @@ QUnit.test('[no cancelation intercept] timer start then immediate clear (duratio
QUnit.test('[no cancelation intercept] timer start then clear before timeout (duration: 1000ms)', async function (assert) {
assert.expect(4);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -255,7 +254,7 @@ QUnit.test('[no cancelation intercept] timer start then clear before timeout (du
QUnit.test('[no cancelation intercept] timer start then reset before timeout (duration: 1000ms)', async function (assert) {
assert.expect(5);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -301,7 +300,7 @@ QUnit.test('[no cancelation intercept] timer start then reset before timeout (du
QUnit.test('[with cancelation intercept] timer start then immediate clear (duration: 0ms)', async function (assert) {
assert.expect(5);
const { messaging } = await start({ data: this.data, hasTimeControl: true });
const { messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -342,7 +341,7 @@ QUnit.test('[with cancelation intercept] timer start then immediate clear (durat
QUnit.test('[with cancelation intercept] timer start then immediate reset (duration: 0ms)', async function (assert) {
assert.expect(9);
const { env, messaging } = await start({ data: this.data, hasTimeControl: true });
const { env, messaging } = await start({ hasTimeControl: true });
let hasTimedOut = false;
this.timers.push(
@@ -1,6 +1,6 @@
/** @odoo-module **/
import { afterNextRender, beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { afterNextRender, start, startServer } from '@mail/../tests/helpers/test_utils';
import { editSearchBar } from '@web/../tests/core/commands/command_service_tests';
import { click, getFixture, nextTick, patchWithCleanup, triggerHotkey } from "@web/../tests/helpers/utils";
import { browser } from '@web/core/browser/browser';
@@ -11,9 +11,8 @@ const serviceRegistry = registry.category("services");
QUnit.module('mail', {}, function () {
QUnit.module('Command Palette', {
async beforeEach() {
beforeEach() {
serviceRegistry.add("command", commandService);
await beforeEach(this);
patchWithCleanup(browser, {
clearTimeout() {},
setTimeout(later, wait) {
@@ -27,24 +26,24 @@ QUnit.module('mail', {}, function () {
QUnit.test('open the chatWindow of a user from the command palette', async function (assert) {
assert.expect(3);
this.data['res.partner'].records.push(
{ id: 11, name: "Partner 1", email: "p1@odoo.com" },
{ id: 12, name: "Partner 2", email: "p2@odoo.com" },
{ id: 13, name: "Partner 3", email: "p3@odoo.com" },
);
this.data['res.users'].records.push(
{ id: 11, name: "User 1", partner_id: 11 },
{ id: 7, name: "User 2", partner_id: 12 },
{ id: 23, name: "User 3", partner_id: 13 },
);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2, resPartnerId3] = pyEnv['res.partner'].create([
{ name: "Partner 1", email: "p1@odoo.com" },
{ name: "Partner 2", email: "p2@odoo.com" },
{ name: "Partner 3", email: "p3@odoo.com" },
]);
pyEnv['res.users'].create([
{ name: "User 1", partner_id: resPartnerId1 },
{ name: "User 2", partner_id: resPartnerId2 },
{ name: "User 3", partner_id: resPartnerId3 },
]);
const target = getFixture();
await start({
data: this.data,
hasChatWindow: true,
hasWebClient: true,
target,
});
hasChatWindow: true,
hasWebClient: true,
target,
});
triggerHotkey("control+k");
await nextTick();
@@ -67,23 +66,21 @@ QUnit.module('mail', {}, function () {
QUnit.test('open the chatWindow of a channel from the command palette', async function (assert) {
assert.expect(3);
this.data['mail.channel'].records.push({
id: 100,
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
name: "general",
members: [this.data.currentPartnerId],
members: [pyEnv.currentPartnerId],
});
this.data['mail.channel'].records.push({
id: 101,
pyEnv['mail.channel'].create({
name: "project",
members: [this.data.currentPartnerId],
members: [pyEnv.currentPartnerId],
});
const target = getFixture();
await start({
data: this.data,
hasChatWindow: true,
hasWebClient: true,
target,
});
hasChatWindow: true,
hasWebClient: true,
target,
});
triggerHotkey("control+k");
await nextTick();
@@ -3,9 +3,9 @@
import { makeDeferred } from '@mail/utils/deferred';
import {
afterNextRender,
beforeEach,
nextAnimationFrame,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import config from 'web.config';
@@ -20,8 +20,6 @@ QUnit.module('mail', {}, function () {
QUnit.module('widgets', {}, function () {
QUnit.module('form_renderer_tests.js', {
async beforeEach() {
await beforeEach(this);
// FIXME archs could be removed once task-2248306 is done
// The mockServer will try to get the list view
// of every relational fields present in the main view.
@@ -58,12 +56,11 @@ QUnit.test('[technical] spinner when messaging is not created', async function (
*/
assert.expect(3);
this.data['res.partner'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
display_name: "second partner",
id: 12,
});
await this.createView({
data: this.data,
hasView: true,
messagingBeforeCreationDeferred: makeDeferred(), // block messaging creation
waitUntilMessagingCondition: 'none',
@@ -78,7 +75,7 @@ QUnit.test('[technical] spinner when messaging is not created', async function (
<div class="oe_chatter"></div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.containsOnce(
document.body,
@@ -108,13 +105,12 @@ QUnit.test('[technical] keep spinner on transition from messaging non-created to
*/
assert.expect(4);
const pyEnv = await startServer();
const messagingBeforeCreationDeferred = makeDeferred();
this.data['res.partner'].records.push({
const resPartnerId1 = pyEnv['res.partner'].create({
display_name: "second partner",
id: 12,
});
await this.createView({
data: this.data,
hasView: true,
messagingBeforeCreationDeferred,
async mockRPC(route, args) {
@@ -136,7 +132,7 @@ QUnit.test('[technical] keep spinner on transition from messaging non-created to
<div class="oe_chatter"></div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.strictEqual(
document.querySelector('.o_ChatterContainer').textContent,
@@ -167,12 +163,11 @@ QUnit.test('[technical] keep spinner on transition from messaging non-created to
QUnit.test('spinner when messaging is created but not initialized', async function (assert) {
assert.expect(3);
this.data['res.partner'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
display_name: "second partner",
id: 12,
});
await this.createView({
data: this.data,
hasView: true,
async mockRPC(route, args) {
const _super = this._super.bind(this, ...arguments); // limitation of class.js
@@ -193,7 +188,7 @@ QUnit.test('spinner when messaging is created but not initialized', async functi
<div class="oe_chatter"></div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.containsOnce(
document.body,
@@ -215,13 +210,12 @@ QUnit.test('spinner when messaging is created but not initialized', async functi
QUnit.test('transition non-initialized messaging to initialized messaging: display spinner then chatter', async function (assert) {
assert.expect(3);
const pyEnv = await startServer();
const messagingBeforeInitializationDeferred = makeDeferred();
this.data['res.partner'].records.push({
const resPartnerId1 = pyEnv['res.partner'].create({
display_name: "second partner",
id: 12,
});
await this.createView({
data: this.data,
hasView: true,
async mockRPC(route, args) {
const _super = this._super.bind(this, ...arguments); // limitation of class.js
@@ -242,7 +236,7 @@ QUnit.test('transition non-initialized messaging to initialized messaging: displ
<div class="oe_chatter"></div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.strictEqual(
document.querySelector('.o_ChatterContainer').textContent,
@@ -267,9 +261,9 @@ QUnit.test('transition non-initialized messaging to initialized messaging: displ
QUnit.test('basic chatter rendering', async function (assert) {
assert.expect(1);
this.data['res.partner'].records.push({ display_name: "second partner", id: 12, });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "second partner" });
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -282,7 +276,7 @@ QUnit.test('basic chatter rendering', async function (assert) {
<div class="oe_chatter"></div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.strictEqual(
document.querySelectorAll(`.o_Chatter`).length,
@@ -294,9 +288,9 @@ QUnit.test('basic chatter rendering', async function (assert) {
QUnit.test('basic chatter rendering without followers', async function (assert) {
assert.expect(6);
this.data['res.partner'].records.push({ display_name: "second partner", id: 12 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "second partner" });
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -312,7 +306,7 @@ QUnit.test('basic chatter rendering without followers', async function (assert)
</div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.containsOnce(
document.body,
@@ -349,9 +343,9 @@ QUnit.test('basic chatter rendering without followers', async function (assert)
QUnit.test('basic chatter rendering without activities', async function (assert) {
assert.expect(6);
this.data['res.partner'].records.push({ display_name: "second partner", id: 12 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "second partner" });
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -367,7 +361,7 @@ QUnit.test('basic chatter rendering without activities', async function (assert)
</div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.containsOnce(
document.body,
@@ -404,9 +398,9 @@ QUnit.test('basic chatter rendering without activities', async function (assert)
QUnit.test('basic chatter rendering without messages', async function (assert) {
assert.expect(6);
this.data['res.partner'].records.push({ display_name: "second partner", id: 12 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "second partner" });
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -422,7 +416,7 @@ QUnit.test('basic chatter rendering without messages', async function (assert) {
</div>
</form>
`,
res_id: 12,
res_id: resPartnerId1,
});
assert.containsOnce(
document.body,
@@ -459,20 +453,20 @@ QUnit.test('basic chatter rendering without messages', async function (assert) {
QUnit.test('chatter updating', async function (assert) {
assert.expect(1);
this.data['mail.message'].records.push({ body: "not empty", model: 'res.partner', res_id: 12 });
this.data['res.partner'].records.push(
{ display_name: "first partner", id: 11 },
{ display_name: "second partner", id: 12 }
);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ display_name: "first partner" },
{ display_name: "second partner" },
]);
pyEnv['mail.message'].create({ body: "not empty", model: 'res.partner', res_id: resPartnerId2 });
const { afterEvent } = await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
model: 'res.partner',
res_id: 11,
res_id: resPartnerId1,
viewOptions: {
ids: [11, 12],
ids: [resPartnerId1, resPartnerId2],
index: 0,
},
arch: `
@@ -492,7 +486,7 @@ QUnit.test('chatter updating', async function (assert) {
return (
hint.type === 'messages-loaded' &&
threadViewer.thread.model === 'res.partner' &&
threadViewer.thread.id === 11
threadViewer.thread.id === resPartnerId1
);
},
}
@@ -505,7 +499,7 @@ QUnit.test('chatter updating', async function (assert) {
return (
hint.type === 'messages-loaded' &&
threadViewer.thread.model === 'res.partner' &&
threadViewer.thread.id === 12
threadViewer.thread.id === resPartnerId2
);
},
}));
@@ -520,7 +514,6 @@ QUnit.test('chatter should become enabled when creation done', async function (a
assert.expect(10);
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -594,8 +587,10 @@ QUnit.test('chatter should become enabled when creation done', async function (a
QUnit.test('read more/less links are not duplicated when switching from read to edit mode', async function (assert) {
assert.expect(5);
this.data['mail.message'].records.push({
author_id: 100,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
author_id: resPartnerId1,
// "data-o-mail-quote" added by server is intended to be compacted in read more/less blocks
body: `
<div>
@@ -609,21 +604,15 @@ QUnit.test('read more/less links are not duplicated when switching from read to
</span>
</div>
`,
id: 1000,
model: 'res.partner',
res_id: 100,
});
this.data['res.partner'].records.push({
display_name: "Someone",
id: 100,
res_id: resPartnerId1,
});
const { afterEvent } = await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
model: 'res.partner',
res_id: 100,
res_id: resPartnerId1,
arch: `
<form string="Partners">
<sheet>
@@ -637,7 +626,7 @@ QUnit.test('read more/less links are not duplicated when switching from read to
waitUntilEvent: {
eventName: 'o-component-message-read-more-less-inserted',
message: "should wait until read more/less is inserted initially",
predicate: ({ message }) => message.id === 1000,
predicate: ({ message }) => message.id === mailMessageId1,
},
});
assert.containsOnce(
@@ -659,7 +648,7 @@ QUnit.test('read more/less links are not duplicated when switching from read to
eventName: 'o-component-message-read-more-less-inserted',
func: () => document.querySelector('.o_form_button_edit').click(),
message: "should wait until read more/less is inserted after clicking on edit",
predicate: ({ message }) => message.id === 1000,
predicate: ({ message }) => message.id === mailMessageId1,
}));
assert.containsOnce(
document.body,
@@ -671,7 +660,7 @@ QUnit.test('read more/less links are not duplicated when switching from read to
eventName: 'o-component-message-read-more-less-inserted',
func: () => document.querySelector('.o_form_button_cancel').click(),
message: "should wait until read more/less is inserted after canceling edit",
predicate: ({ message }) => message.id === 1000,
predicate: ({ message }) => message.id === mailMessageId1,
}));
assert.containsOnce(
document.body,
@@ -683,8 +672,10 @@ QUnit.test('read more/less links are not duplicated when switching from read to
QUnit.test('read more links becomes read less after being clicked', async function (assert) {
assert.expect(6);
this.data['mail.message'].records = [{
author_id: 100,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create([{
author_id: resPartnerId1,
// "data-o-mail-quote" added by server is intended to be compacted in read more/less blocks
body: `
<div>
@@ -698,21 +689,15 @@ QUnit.test('read more links becomes read less after being clicked', async functi
</span>
</div>
`,
id: 1000,
model: 'res.partner',
res_id: 100,
}];
this.data['res.partner'].records.push({
display_name: "Someone",
id: 100,
});
res_id: resPartnerId1,
}]);
const { afterEvent } = await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
model: 'res.partner',
res_id: 100,
res_id: resPartnerId1,
arch: `
<form string="Partners">
<sheet>
@@ -726,7 +711,7 @@ QUnit.test('read more links becomes read less after being clicked', async functi
waitUntilEvent: {
eventName: 'o-component-message-read-more-less-inserted',
message: "should wait until read more/less is inserted initially",
predicate: ({ message }) => message.id === 1000,
predicate: ({ message }) => message.id === mailMessageId1,
},
});
assert.containsOnce(
@@ -754,7 +739,7 @@ QUnit.test('read more links becomes read less after being clicked', async functi
eventName: 'o-component-message-read-more-less-inserted',
func: () => document.querySelector('.o_form_button_edit').click(),
message: "should wait until read more/less is inserted after clicking on edit",
predicate: ({ message }) => message.id === 1000,
predicate: ({ message }) => message.id === mailMessageId1,
}));
assert.strictEqual(
document.querySelector('.o_Message_readMoreLess').textContent,
@@ -773,28 +758,26 @@ QUnit.test('read more links becomes read less after being clicked', async functi
QUnit.test('Form view not scrolled when switching record', async function (assert) {
assert.expect(6);
this.data['res.partner'].records.push(
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{
id: 11,
display_name: "Partner 1",
description: [...Array(60).keys()].join('\n'),
display_name: "Partner 1",
},
{
id: 12,
display_name: "Partner 2",
}
);
},
]);
const messages = [...Array(60).keys()].map(id => {
return {
model: 'res.partner',
res_id: id % 2 ? 11 : 12,
res_id: id % 2 ? resPartnerId1 : resPartnerId2,
};
});
this.data['mail.message'].records = messages;
pyEnv['mail.message'].create(messages);
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -811,8 +794,8 @@ QUnit.test('Form view not scrolled when switching record', async function (asser
</form>
`,
viewOptions: {
currentId: 11,
ids: [11, 12],
currentId: resPartnerId1,
ids: [resPartnerId1, resPartnerId2],
},
config: {
device: { size_class: config.device.SIZES.LG },
@@ -872,33 +855,31 @@ QUnit.test('Attachments that have been unlinked from server should be visually u
// partner accesses this record again.
assert.expect(2);
this.data['res.partner'].records.push(
{ display_name: "Partner1", id: 11 },
{ display_name: "Partner2", id: 12 }
);
this.data['ir.attachment'].records.push(
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ display_name: "Partner1" },
{ display_name: "Partner2" },
]);
const [irAttachmentId1] = pyEnv['ir.attachment'].create([
{
id: 11,
mimetype: 'text.txt',
res_id: 11,
res_model: 'res.partner',
mimetype: 'text.txt',
res_id: resPartnerId1,
res_model: 'res.partner',
},
{
id: 12,
mimetype: 'text.txt',
res_id: 11,
res_model: 'res.partner',
}
);
mimetype: 'text.txt',
res_id: resPartnerId1,
res_model: 'res.partner',
},
]);
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
model: 'res.partner',
res_id: 11,
res_id: resPartnerId1,
viewOptions: {
ids: [11, 12],
ids: [resPartnerId1, resPartnerId2],
index: 0,
},
arch: `
@@ -923,8 +904,8 @@ QUnit.test('Attachments that have been unlinked from server should be visually u
await afterNextRender(() =>
document.querySelector('.o_pager_next').click()
);
// Simulate unlinking attachment 12 from Partner 1.
this.data['ir.attachment'].records.find(a => a.id === 11).res_id = 0;
// Simulate unlinking attachment 1 from Partner 1.
pyEnv['ir.attachment'].write([irAttachmentId1], { res_id: 0 });
await afterNextRender(() =>
document.querySelector('.o_pager_previous').click()
);
@@ -938,13 +919,13 @@ QUnit.test('Attachments that have been unlinked from server should be visually u
QUnit.test('chatter just contains "creating a new record" message during the creation of a new record after having displayed a chatter for an existing record', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({ id: 12 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
await this.createView({
data: this.data,
hasView: true,
View: FormView,
model: 'res.partner',
res_id: 12,
res_id: resPartnerId1,
arch: `
<form>
<div class="oe_chatter">
@@ -980,8 +961,10 @@ QUnit.test('[TECHNICAL] unfolded read more/less links should not fold on message
// from text selection automatically folding all read more/less links.
assert.expect(3);
this.data['mail.message'].records.push({
author_id: 100,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "Someone" });
pyEnv['mail.message'].create({
author_id: resPartnerId1,
// "data-o-mail-quote" added by server is intended to be compacted in read more/less blocks
body: `
<div>
@@ -995,21 +978,15 @@ QUnit.test('[TECHNICAL] unfolded read more/less links should not fold on message
</span>
</div>
`,
id: 1000,
model: 'res.partner',
res_id: 100,
});
this.data['res.partner'].records.push({
display_name: "Someone",
id: 100,
res_id: resPartnerId1,
});
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
model: 'res.partner',
res_id: 100,
res_id: resPartnerId1,
arch: `
<form string="Partners">
<sheet>
@@ -1045,10 +1022,11 @@ QUnit.test('[TECHNICAL] unfolded read more/less links should not fold on message
});
QUnit.test('chatter does not flicker when the form view is re-rendered', async function (assert) {
this.data['res.partner'].records.push(
{ display_name: "first partner", id: 11 },
{ display_name: "second partner", id: 12 }
);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ display_name: "first partner" },
{ display_name: "second partner" },
]);
// define an asynchronous field and use it in the form to ease testing
let def;
@@ -1064,7 +1042,6 @@ QUnit.test('chatter does not flicker when the form view is re-rendered', async f
});
await this.createView({
data: this.data,
hasView: true,
// View params
View: FormView,
@@ -1078,8 +1055,8 @@ QUnit.test('chatter does not flicker when the form view is re-rendered', async f
</form>
`,
viewOptions: {
currentId: 11,
ids: [11, 12],
currentId: resPartnerId1,
ids: [resPartnerId1, resPartnerId2],
},
});
assert.strictEqual(
@@ -1,16 +1,12 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
import FormView from 'web.FormView';
QUnit.module('mail', {}, function () {
QUnit.module('widgets', {}, function () {
QUnit.module('notification_alert_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('notification_alert_tests.js');
QUnit.skip('notification_alert widget: display blocked notification alert', async function (assert) {
// FIXME: Test should work, but for some reasons OWL always flags the
@@ -24,7 +20,6 @@ QUnit.skip('notification_alert widget: display blocked notification alert', asyn
<widget name="notification_alert"/>
</form>
`,
data: this.data,
env: {
browser: {
Notification: {
@@ -54,7 +49,6 @@ QUnit.test('notification_alert widget: no notification alert when granted', asyn
<widget name="notification_alert"/>
</form>
`,
data: this.data,
env: {
browser: {
Notification: {
@@ -84,7 +78,6 @@ QUnit.test('notification_alert widget: no notification alert when default', asyn
<widget name="notification_alert"/>
</form>
`,
data: this.data,
env: {
browser: {
Notification: {
@@ -1,13 +1,9 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('mail_bot', {}, function () {
QUnit.module('messaging_initializer_tests.js', {
beforeEach() {
beforeEach(this);
},
});
QUnit.module('messaging_initializer_tests.js');
QUnit.test('OdooBot initialized at init', async function (assert) {
@@ -16,7 +12,6 @@ QUnit.test('OdooBot initialized at init', async function (assert) {
assert.expect(2);
await start({
data: this.data,
env: {
session: {
odoobot_initialized: false,