diff --git a/addons/mail/static/tests/qunit_suite_tests/chatter_tests.js b/addons/mail/static/tests/qunit_suite_tests/chatter_tests.js
index 5cbe30b62e1..5c5587b280e 100644
--- a/addons/mail/static/tests/qunit_suite_tests/chatter_tests.js
+++ b/addons/mail/static/tests/qunit_suite_tests/chatter_tests.js
@@ -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: '
',
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: '
',
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: '
',
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: `
-
`,
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: '' +
- '' +
' ' +
'',
});
@@ -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: '
`,
- 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
`,
- 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
`,
- 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) {
`,
- 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)
`,
- 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)
`,
- 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) {
`,
- 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: `
@@ -609,21 +604,15 @@ QUnit.test('read more/less links are not duplicated when switching from read to
`,
- 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: `