[IMP] mail, *: adapt remaining tests data seeding

*: calendar, hr, hr_holidays, im_livechat, mail, note, sms, snailmail,
test_mail, website_livechat, website_slides.

task-2792108

closes odoo/odoo#87700

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
tsm-odoo
2022-04-04 17:48:39 +02:00
parent 78d964b29d
commit 848e8d7ee4
28 changed files with 1115 additions and 1249 deletions
@@ -1,37 +1,33 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import ActivityMenu from '@mail/js/systray/systray_activity_menu';
import testUtils from 'web.test_utils';
QUnit.module('calendar', {}, function () {
QUnit.module('ActivityMenu', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('ActivityMenu');
QUnit.test('activity menu widget:today meetings', async function (assert) {
assert.expect(6);
this.data['calendar.attendee'].records.push({ id: 1, partner_id: this.data.currentPartnerId });
this.data['calendar.event'].records.push(
const pyEnv = await startServer();
const calendarAttendeeId1 = pyEnv['calendar.attendee'].create({ partner_id: pyEnv.currentPartnerId });
pyEnv['calendar.event'].create([
{
res_model: "calendar.event",
name: "meeting1",
start: "2018-04-20 06:30:00",
attendee_ids: [1],
attendee_ids: [calendarAttendeeId1],
},
{
res_model: "calendar.event",
name: "meeting2",
start: "2018-04-20 09:30:00",
attendee_ids: [1],
attendee_ids: [calendarAttendeeId1],
},
);
const { widget } = await start({ data: this.data });
]);
const { widget } = await start();
const activityMenu = new ActivityMenu(widget);
await activityMenu.appendTo($('#qunit-fixture'));
@@ -2,8 +2,8 @@
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import FormView from 'web.FormView';
@@ -14,45 +14,37 @@ import { dom, mock } from 'web.test_utils';
QUnit.module('hr', {}, function () {
QUnit.module('M2XAvatarEmployee', {
async beforeEach() {
await beforeEach(this);
// reset the cache before each test
beforeEach() {
Many2OneAvatarEmployee.prototype.partnerIds = {};
this.data['m2x.avatar.employee'].records.push(
{ id: 1, employee_id: 11, employee_ids: [11, 23] },
{ id: 2, employee_id: 7 },
{ id: 3, employee_id: 11 },
{ id: 4, employee_id: 23 },
);
this.data['hr.employee.public'].records.push(
{ id: 11, name: "Mario", user_id: 11, user_partner_id: 11 },
{ id: 7, name: "Luigi", user_id: 12, user_partner_id: 12 },
{ id: 23, name: "Yoshi", user_id: 13, user_partner_id: 13 }
);
this.data['res.users'].records.push(
{ id: 11, partner_id: 11 },
{ id: 12, partner_id: 12 },
{ id: 13, partner_id: 13 }
);
this.data['res.partner'].records.push(
{ id: 11, display_name: "Mario" },
{ id: 12, display_name: "Luigi" },
{ id: 13, display_name: "Yoshi" }
);
},
});
QUnit.test('many2one_avatar_employee widget in list view', async function (assert) {
assert.expect(11);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ display_name: "Mario" },
{ display_name: "Luigi" },
]);
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([
{ partner_id: resPartnerId1 },
{ partner_id: resPartnerId2 },
]);
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
{ name: "Mario", user_id: resUsersId1, user_partner_id: resPartnerId1 },
{ name: "Luigi", user_id: resUsersId2, user_partner_id: resPartnerId2 },
]);
pyEnv['m2x.avatar.employee'].create([
{ employee_id: hrEmployeePublicId1, employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
{ employee_id: hrEmployeePublicId2 },
{ employee_id: hrEmployeePublicId1 },
]);
const { widget: list } = await start({
hasChatWindow: true,
hasView: true,
View: ListView,
model: 'm2x.avatar.employee',
data: this.data,
arch: '<tree><field name="employee_id" widget="many2one_avatar_employee"/></tree>',
mockRPC(route, args) {
if (args.method === 'read') {
@@ -62,14 +54,14 @@ QUnit.module('hr', {}, function () {
},
});
assert.strictEqual(list.$('.o_data_cell span').text(), 'MarioLuigiMarioYoshi');
assert.strictEqual(list.$('.o_data_cell span').text(), 'MarioLuigiMario');
// click on first employee
await afterNextRender(() =>
dom.click(list.$('.o_data_cell:nth(0) .o_m2o_avatar > img'))
);
assert.verifySteps(
['read hr.employee.public 11'],
[`read hr.employee.public ${hrEmployeePublicId1}`],
"first employee should have been read to find its partner"
);
assert.containsOnce(
@@ -88,7 +80,7 @@ QUnit.module('hr', {}, function () {
dom.click(list.$('.o_data_cell:nth(1) .o_m2o_avatar > img')
));
assert.verifySteps(
['read hr.employee.public 7'],
[`read hr.employee.public ${hrEmployeePublicId2}`],
"second employee should have been read to find its partner"
);
assert.containsN(
@@ -122,8 +114,13 @@ QUnit.module('hr', {}, function () {
});
QUnit.test('many2one_avatar_employee widget in kanban view', async function (assert) {
assert.expect(6);
assert.expect(3);
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const resUsersId1 = pyEnv['res.users'].create({ partner_id: resPartnerId1 });
const hrEmployeePublicId1 = pyEnv['hr.employee.public'].create({ user_id: resUsersId1, user_partner_id: resPartnerId1 });
pyEnv['m2x.avatar.employee'].create({ employee_id: hrEmployeePublicId1, employee_ids: [hrEmployeePublicId1] });
const { widget: kanban } = await start({
hasView: true,
View: KanbanView,
@@ -142,11 +139,8 @@ QUnit.module('hr', {}, function () {
});
assert.strictEqual(kanban.$('.o_kanban_record').text().trim(), '');
assert.containsN(kanban, '.o_m2o_avatar', 4);
assert.strictEqual(kanban.$('.o_m2o_avatar:nth(0) > img').data('src'), '/web/image/hr.employee.public/11/avatar_128');
assert.strictEqual(kanban.$('.o_m2o_avatar:nth(1) > img').data('src'), '/web/image/hr.employee.public/7/avatar_128');
assert.strictEqual(kanban.$('.o_m2o_avatar:nth(2) > img').data('src'), '/web/image/hr.employee.public/11/avatar_128');
assert.strictEqual(kanban.$('.o_m2o_avatar:nth(3) > img').data('src'), '/web/image/hr.employee.public/23/avatar_128');
assert.containsOnce(kanban, '.o_m2o_avatar');
assert.strictEqual(kanban.$('.o_m2o_avatar:nth(0) > img').data('src'), `/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`);
kanban.destroy();
});
@@ -154,8 +148,9 @@ QUnit.module('hr', {}, function () {
QUnit.test('many2one_avatar_employee: click on an employee not associated with a user', async function (assert) {
assert.expect(6);
this.data['hr.employee.public'].records[0].user_id = false;
this.data['hr.employee.public'].records[0].user_partner_id = false;
const pyEnv = await startServer();
const hrEmployeePublicId1 = pyEnv['hr.employee.public'].create({ name: 'Mario' });
const m2xHrAvatarUserId1 = pyEnv['m2x.avatar.employee'].create({ employee_id: hrEmployeePublicId1 });
const { widget: form } = await start({
hasView: true,
View: FormView,
@@ -168,7 +163,7 @@ QUnit.module('hr', {}, function () {
}
return this._super(...arguments);
},
res_id: 1,
res_id: m2xHrAvatarUserId1,
services: {
notification: {
notify(notification) {
@@ -197,8 +192,8 @@ QUnit.module('hr', {}, function () {
await dom.click(form.$('.o_m2o_avatar > img'));
assert.verifySteps([
'read m2x.avatar.employee 1',
'read hr.employee.public 11',
`read m2x.avatar.employee ${m2xHrAvatarUserId1}`,
`read hr.employee.public ${hrEmployeePublicId1}`,
]);
form.destroy();
@@ -207,6 +202,16 @@ QUnit.module('hr', {}, function () {
QUnit.test('many2many_avatar_employee widget in form view', async function (assert) {
assert.expect(8);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([{}, {}]);
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
]);
const m2xAvatarEmployeeId1 = pyEnv['m2x.avatar.employee'].create(
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
);
const { widget: form } = await start({
hasChatWindow: true,
hasView: true,
@@ -220,23 +225,23 @@ QUnit.module('hr', {}, function () {
}
return this._super(...arguments);
},
res_id: 1,
res_id: m2xAvatarEmployeeId1,
});
assert.containsN(form, '.o_field_many2manytags.avatar.o_field_widget .badge', 2,
"should have 2 records");
assert.strictEqual(form.$('.o_field_many2manytags.avatar.o_field_widget .badge:first img').data('src'),
'/web/image/hr.employee.public/11/avatar_128',
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
"should have correct avatar image");
await dom.click(form.$('.o_field_many2manytags.avatar .badge:first .o_m2m_avatar'));
await dom.click(form.$('.o_field_many2manytags.avatar .badge:nth(1) .o_m2m_avatar'));
assert.verifySteps([
"read m2x.avatar.employee 1",
'read hr.employee.public 11,23',
"read hr.employee.public 11",
"read hr.employee.public 23",
`read m2x.avatar.employee ${m2xAvatarEmployeeId1}`,
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
`read hr.employee.public ${hrEmployeePublicId1}`,
`read hr.employee.public ${hrEmployeePublicId2}`,
]);
assert.containsN(
@@ -252,12 +257,24 @@ QUnit.module('hr', {}, function () {
QUnit.test('many2many_avatar_employee widget in list view', async function (assert) {
assert.expect(10);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
{ name: "Mario" },
{ name: "Yoshi" },
]);
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
]);
pyEnv['m2x.avatar.employee'].create(
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
);
const { widget: list } = await start({
hasChatWindow: true,
hasView: true,
View: ListView,
model: 'm2x.avatar.employee',
data: this.data,
arch: '<tree><field name="employee_ids" widget="many2many_avatar_employee"/></tree>',
mockRPC(route, args) {
if (args.method === 'read') {
@@ -275,7 +292,7 @@ QUnit.module('hr', {}, function () {
dom.click(list.$('.o_data_cell:nth(0) .o_m2m_avatar:first'))
);
assert.verifySteps(
['read hr.employee.public 11,23', "read hr.employee.public 11"],
[`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`, `read hr.employee.public ${hrEmployeePublicId1}`],
"first employee should have been read to find its partner"
);
assert.containsOnce(
@@ -294,7 +311,7 @@ QUnit.module('hr', {}, function () {
dom.click(list.$('.o_data_cell:nth(0) .o_m2m_avatar:nth(1)')
));
assert.verifySteps(
['read hr.employee.public 23'],
[`read hr.employee.public ${hrEmployeePublicId2}`],
"second employee should have been read to find its partner"
);
assert.containsN(
@@ -315,11 +332,20 @@ QUnit.module('hr', {}, function () {
QUnit.test('many2many_avatar_employee widget in kanban view', async function (assert) {
assert.expect(7);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([{}, {}]);
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
]);
pyEnv['m2x.avatar.employee'].create(
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
);
const { widget: kanban } = await start({
hasView: true,
View: KanbanView,
model: 'm2x.avatar.employee',
data: this.data,
arch: `
<kanban>
<templates>
@@ -347,19 +373,19 @@ QUnit.module('hr', {}, function () {
assert.containsN(kanban, '.o_kanban_record:first .o_field_many2manytags img.o_m2m_avatar', 2,
"should have 2 avatar images");
assert.strictEqual(kanban.$('.o_kanban_record:first .o_field_many2manytags img.o_m2m_avatar:first').data('src'),
"/web/image/hr.employee.public/11/avatar_128",
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
"should have correct avatar image");
assert.strictEqual(kanban.$('.o_kanban_record:first .o_field_many2manytags img.o_m2m_avatar:eq(1)').data('src'),
"/web/image/hr.employee.public/23/avatar_128",
`/web/image/hr.employee.public/${hrEmployeePublicId2}/avatar_128`,
"should have correct avatar image");
await dom.click(kanban.$('.o_kanban_record:first .o_m2m_avatar:nth(0)'));
await dom.click(kanban.$('.o_kanban_record:first .o_m2m_avatar:nth(1)'));
assert.verifySteps([
"read hr.employee.public 11,23",
"read hr.employee.public 11",
"read hr.employee.public 23"
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
`read hr.employee.public ${hrEmployeePublicId1}`,
`read hr.employee.public ${hrEmployeePublicId2}`
]);
kanban.destroy();
@@ -368,14 +394,21 @@ QUnit.module('hr', {}, function () {
QUnit.test('many2many_avatar_employee: click on an employee not associated with a user', async function (assert) {
assert.expect(10);
this.data['hr.employee.public'].records[0].user_id = false;
this.data['hr.employee.public'].records[0].user_partner_id = false;
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const resUsersId1 = pyEnv['res.users'].create();
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
{},
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
]);
const m2xAvatarEmployeeId1 = pyEnv['m2x.avatar.employee'].create(
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
);
const { widget: form } = await start({
hasChatWindow: true,
hasView: true,
View: FormView,
model: 'm2x.avatar.employee',
data: this.data,
arch: '<form><field name="employee_ids" widget="many2many_avatar_employee"/></form>',
mockRPC(route, args) {
if (args.method === 'read') {
@@ -383,7 +416,7 @@ QUnit.module('hr', {}, function () {
}
return this._super(...arguments);
},
res_id: 1,
res_id: m2xAvatarEmployeeId1,
services: {
notification: {
notify(notification) {
@@ -410,17 +443,17 @@ QUnit.module('hr', {}, function () {
assert.containsN(form, '.o_field_many2manytags.avatar.o_field_widget .badge', 2,
"should have 2 records");
assert.strictEqual(form.$('.o_field_many2manytags.avatar.o_field_widget .badge:first img').data('src'),
'/web/image/hr.employee.public/11/avatar_128',
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
"should have correct avatar image");
await dom.click(form.$('.o_field_many2manytags.avatar .badge:first .o_m2m_avatar'));
await dom.click(form.$('.o_field_many2manytags.avatar .badge:nth(1) .o_m2m_avatar'));
assert.verifySteps([
'read m2x.avatar.employee 1',
'read hr.employee.public 11,23',
"read hr.employee.public 11",
"read hr.employee.public 23"
`read m2x.avatar.employee ${hrEmployeePublicId1}`,
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
`read hr.employee.public ${hrEmployeePublicId1}`,
`read hr.employee.public ${hrEmployeePublicId2}`
]);
assert.containsOnce(document.body, '.o_ChatWindowHeader_name',
@@ -1,7 +1,6 @@
/** @odoo-module **/
import {
beforeEach,
createRootMessagingComponent,
start,
} from '@mail/../tests/helpers/test_utils';
@@ -9,9 +8,7 @@ import {
QUnit.module('hr_holidays', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('partner_im_status_icon_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.createPartnerImStatusIcon = async (partner, target) => {
await createRootMessagingComponent(partner.env, "PartnerImStatusIcon", {
props: { partnerLocalId: partner.localId },
@@ -24,7 +21,7 @@ QUnit.module('partner_im_status_icon_tests.js', {
QUnit.test('on leave & online', async function (assert) {
assert.expect(2);
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const partner = messaging.models['Partner'].create({
id: 7,
name: "Demo User",
@@ -46,7 +43,7 @@ QUnit.test('on leave & online', async function (assert) {
QUnit.test('on leave & away', async function (assert) {
assert.expect(2);
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const partner = messaging.models['Partner'].create({
id: 7,
name: "Demo User",
@@ -68,7 +65,7 @@ QUnit.test('on leave & away', async function (assert) {
QUnit.test('on leave & offline', async function (assert) {
assert.expect(2);
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const partner = messaging.models['Partner'].create({
id: 7,
name: "Demo User",
@@ -1,17 +1,15 @@
/** @odoo-module **/
import {
beforeEach,
createRootMessagingComponent,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_icon_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.createThreadIcon = async (thread, target) => {
await createRootMessagingComponent(thread.env, "ThreadIcon", {
props: { threadLocalId: thread.localId },
@@ -24,19 +22,18 @@ QUnit.module('thread_icon_tests.js', {
QUnit.test('thread icon of a chat when correspondent is on leave & online', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({
id: 7,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
im_status: 'leave_online',
name: 'Demo',
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'chat',
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 7],
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadIcon(thread, widget.el);
@@ -56,19 +53,18 @@ QUnit.test('thread icon of a chat when correspondent is on leave & online', asyn
QUnit.test('thread icon of a chat when correspondent is on leave & away', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({
id: 7,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
im_status: 'leave_away',
name: 'Demo',
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'chat',
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 7],
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadIcon(thread, widget.el);
@@ -88,19 +84,18 @@ QUnit.test('thread icon of a chat when correspondent is on leave & away', async
QUnit.test('thread icon of a chat when correspondent is on leave & offline', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({
id: 7,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
im_status: 'leave_offline',
name: 'Demo',
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'chat',
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 7],
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadIcon(thread, widget.el);
@@ -2,37 +2,32 @@
import { insertAndReplace, link } from '@mail/model/model_field_command';
import {
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('hr_holidays', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_view_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('thread_view_tests.js');
QUnit.test('out of office message on direct chat with out of office partner', async function (assert) {
assert.expect(2);
// Returning date of the out of office partner, simulates he'll be back in a month
const returningDate = moment.utc().add(1, 'month');
const pyEnv = await startServer();
// Needed partner & user to allow simulation of message reception
this.data['res.partner'].records.push({
id: 11,
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Foreigner partner",
out_of_office_date_end: returningDate.format("YYYY-MM-DD"),
});
this.data['mail.channel'].records = [{
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'chat',
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 11],
}];
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { createThreadViewComponent, messaging } = await start({ data: this.data });
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel'
});
const threadViewer = messaging.models['ThreadViewer'].create({
@@ -2,37 +2,30 @@
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('chat_window_manager', {}, function () {
QUnit.module('chat_window_manager_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('chat_window_manager_tests.js');
QUnit.test('closing a chat window with no message from admin side unpins it', async function (assert) {
assert.expect(1);
this.data['res.partner'].records.push({ id: 10, name: "Demo" });
this.data['res.users'].records.push({
id: 42,
partner_id: 10,
});
this.data['mail.channel'].records.push(
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: "Demo" });
pyEnv['res.users'].create({ partner_id: resPartnerId1 });
const mailChannelId1 = pyEnv['mail.channel'].create(
{
channel_type: "livechat",
id: 10,
is_pinned: true,
channel_partner_ids: [this.data.currentPartnerId, 10],
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
uuid: 'channel-10-uuid',
},
);
const { createMessagingMenuComponent, env } = await start({ data: this.data, hasChatWindow: true });
const { createMessagingMenuComponent, env } = await start({ hasChatWindow: true });
await createMessagingMenuComponent();
await afterNextRender(() => document.querySelector(`.o_MessagingMenu_toggler`).click());
@@ -41,7 +34,7 @@ QUnit.test('closing a chat window with no message from admin side unpins it', as
const channels = await env.services.rpc({
model: 'mail.channel',
method: 'read',
args: [10],
args: [mailChannelId1],
}, { shadow: true });
assert.strictEqual(
channels[0].is_pinned,
@@ -1,21 +1,17 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('composer_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('composer_tests.js');
QUnit.test('livechat: no add attachment button', async function (assert) {
// Attachments are not yet supported in livechat, especially from livechat
// visitor PoV. This may likely change in the future with task-2029065.
assert.expect(2);
const { createComposerComponent, messaging } = await start({ data: this.data });
const { createComposerComponent, messaging } = await start();
const thread = messaging.models['Thread'].create({
channel_type: 'livechat',
id: 10,
@@ -1,20 +1,17 @@
/** @odoo-module **/
import {
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('discuss_sidebar_category_item_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.start = async params => {
return start(Object.assign({}, params, {
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
}));
};
@@ -24,19 +21,19 @@ QUnit.module('discuss_sidebar_category_item_tests.js', {
QUnit.test('livechat - avatar: should have a smiley face avatar for an anonymous livechat item', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.currentPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.currentPartnerId],
});
const { messaging } = await this.start();
const livechatItem = document.querySelector(`
.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]
@@ -56,22 +53,21 @@ QUnit.test('livechat - avatar: should have a smiley face avatar for an anonymous
QUnit.test('livechat - avatar: should have a partner profile picture for a livechat item linked with a partner', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({
id: 10,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Jean",
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, 10],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { messaging } = await this.start();
const livechatItem = document.querySelector(`
.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]
@@ -83,7 +79,7 @@ QUnit.test('livechat - avatar: should have a partner profile picture for a livec
);
assert.strictEqual(
livechatItem.querySelector(`:scope .o_DiscussSidebarCategoryItem_image`).dataset.src,
'/web/image/res.partner/10/avatar_128',
`/web/image/res.partner/${resPartnerId1}/avatar_128`,
'should have the partner profile picture as the avatar for partners'
);
});
@@ -2,20 +2,17 @@
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('discuss_sidebar_category_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.start = async params => {
return start(Object.assign({}, params, {
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
}));
};
@@ -25,12 +22,12 @@ QUnit.module('discuss_sidebar_category_tests.js', {
QUnit.test('livechat - counter: should not have a counter if the category is unfolded and without unread messages', async function (assert) {
assert.expect(1);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
await this.start();
assert.containsNone(
@@ -43,12 +40,12 @@ QUnit.test('livechat - counter: should not have a counter if the category is unf
QUnit.test('livechat - counter: should not have a counter if the category is unfolded and with unread messages', async function (assert) {
assert.expect(1);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
message_unread_counter: 10,
});
await this.start();
@@ -62,15 +59,15 @@ QUnit.test('livechat - counter: should not have a counter if the category is unf
QUnit.test('livechat - counter: should not have a counter if category is folded and without unread messages', async function (assert) {
assert.expect(1);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: false,
});
await this.start();
@@ -85,16 +82,16 @@ QUnit.test('livechat - counter: should not have a counter if category is folded
QUnit.test('livechat - counter: should have correct value of unread threads if category is folded and with unread messages', async function (assert) {
assert.expect(1);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
message_unread_counter: 10,
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: false,
});
await this.start();
@@ -109,15 +106,15 @@ QUnit.test('livechat - counter: should have correct value of unread threads if c
QUnit.test('livechat - states: close manually by clicking the title', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: true,
});
const { messaging } = await this.start();
@@ -126,7 +123,7 @@ QUnit.test('livechat - states: close manually by clicking the title', async func
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`
@@ -143,7 +140,7 @@ QUnit.test('livechat - states: close manually by clicking the title', async func
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -154,15 +151,15 @@ QUnit.test('livechat - states: close manually by clicking the title', async func
QUnit.test('livechat - states: open manually by clicking the title', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: false,
});
const { messaging } = await this.start();
@@ -171,7 +168,7 @@ QUnit.test('livechat - states: open manually by clicking the title', async funct
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`
@@ -188,7 +185,7 @@ QUnit.test('livechat - states: open manually by clicking the title', async funct
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -199,18 +196,18 @@ QUnit.test('livechat - states: open manually by clicking the title', async funct
QUnit.test('livechat - states: close should update the value on the server', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: true,
});
const currentUserId = this.data.currentUserId;
const currentUserId = pyEnv.currentUserId;
const { env, messaging } = await this.start();
const initalSettings = await env.services.rpc({
@@ -245,18 +242,18 @@ QUnit.test('livechat - states: close should update the value on the server', asy
QUnit.test('livechat - states: open should update the value on the server', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: false,
});
const currentUserId = this.data.currentUserId;
const currentUserId = pyEnv.currentUserId;
const { env, messaging } = await this.start();
const initalSettings = await env.services.rpc({
@@ -291,12 +288,12 @@ QUnit.test('livechat - states: open should update the value on the server', asyn
QUnit.test('livechat - states: close from the bus', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { env, messaging } = await this.start();
@@ -304,7 +301,7 @@ QUnit.test('livechat - states: close from the bus', async function (assert) {
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`
@@ -322,7 +319,7 @@ QUnit.test('livechat - states: close from the bus', async function (assert) {
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -333,15 +330,15 @@ QUnit.test('livechat - states: close from the bus', async function (assert) {
QUnit.test('livechat - states: open from the bus', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
this.data['res.users.settings'].records.push({
user_id: this.data.currentUserId,
pyEnv['res.users.settings'].create({
user_id: pyEnv.currentUserId,
is_discuss_sidebar_category_livechat_open: false,
});
const { env, messaging } = await this.start();
@@ -350,7 +347,7 @@ QUnit.test('livechat - states: open from the bus', async function (assert) {
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`
@@ -368,7 +365,7 @@ QUnit.test('livechat - states: open from the bus', async function (assert) {
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -380,12 +377,12 @@ QUnit.test('livechat - states: open from the bus', async function (assert) {
QUnit.test('livechat - states: category item should be invisible if the catgory is closed', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { messaging } = await this.start();
@@ -393,7 +390,7 @@ QUnit.test('livechat - states: category item should be invisible if the catgory
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`
@@ -410,7 +407,7 @@ QUnit.test('livechat - states: category item should be invisible if the catgory
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -421,12 +418,12 @@ QUnit.test('livechat - states: category item should be invisible if the catgory
QUnit.test('livechat - states: the active category item should be visble even if the category is closed', async function (assert) {
assert.expect(3);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { messaging } = await this.start();
@@ -434,7 +431,7 @@ QUnit.test('livechat - states: the active category item should be visble even if
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`
@@ -442,7 +439,7 @@ QUnit.test('livechat - states: the active category item should be visble even if
const livechat = document.querySelector(`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`);
@@ -462,7 +459,7 @@ QUnit.test('livechat - states: the active category item should be visble even if
document.body,
`.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -2,34 +2,29 @@
import {
afterNextRender,
beforeEach,
nextAnimationFrame,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import { datetime_to_str } from 'web.time';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('discuss_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('discuss_tests.js');
QUnit.test('livechat in the sidebar: basic rendering', async function (assert) {
assert.expect(5);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { messaging } = await start({
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
});
assert.containsOnce(document.body, '.o_Discuss_sidebar',
@@ -48,7 +43,7 @@ QUnit.test('livechat in the sidebar: basic rendering', async function (assert) {
const livechat = groupLivechat.querySelector(`
.o_DiscussSidebarCategoryItem[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]
@@ -67,25 +62,22 @@ QUnit.test('livechat in the sidebar: basic rendering', async function (assert) {
QUnit.test('livechat in the sidebar: existing user with country', async function (assert) {
assert.expect(3);
this.data['res.country'].records.push({
const pyEnv = await startServer();
const resCountryId1 = pyEnv['res.country'].create({
code: 'be',
id: 10,
name: "Belgium",
});
this.data['res.partner'].records.push({
country_id: 10,
id: 10,
const resPartnerId1 = pyEnv['res.partner'].create({
country_id: resCountryId1,
name: "Jean",
});
this.data['mail.channel'].records.push({
pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, 10],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
await start({
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
});
assert.containsOnce(
@@ -108,17 +100,13 @@ QUnit.test('livechat in the sidebar: existing user with country', async function
QUnit.test('do not add livechat in the sidebar on visitor opening his chat', async function (assert) {
assert.expect(2);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
);
currentUser.im_status = 'online';
this.data['im_livechat.channel'].records.push({
id: 10,
user_ids: [this.data.currentUserId],
const pyEnv = await startServer();
pyEnv['res.users'].write([pyEnv.currentUserId], { im_status: 'online' });
const imLivechatChannelId1 = pyEnv['im_livechat.channel'].create({
user_ids: [pyEnv.currentUserId],
});
const { env } = await start({
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
});
assert.containsNone(
@@ -134,7 +122,7 @@ QUnit.test('do not add livechat in the sidebar on visitor opening his chat', asy
context: {
mockedUserId: false,
},
channel_id: 10,
channel_id: imLivechatChannelId1,
},
});
await nextAnimationFrame();
@@ -148,25 +136,20 @@ QUnit.test('do not add livechat in the sidebar on visitor opening his chat', asy
QUnit.test('do not add livechat in the sidebar on visitor typing', async function (assert) {
assert.expect(2);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
);
currentUser.im_status = 'online';
this.data['im_livechat.channel'].records.push({
id: 10,
user_ids: [this.data.currentUserId],
const pyEnv = await startServer();
pyEnv['res.users'].write([pyEnv.currentUserId], { im_status: 'online' });
const imLivechatChannelId1 = pyEnv['im_livechat.channel'].create({
user_ids: [pyEnv.currentUserId],
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 10,
is_pinned: false,
livechat_channel_id: 10,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.publicPartnerId, this.data.currentPartnerId],
livechat_channel_id: imLivechatChannelId1,
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.publicPartnerId, pyEnv.currentPartnerId],
});
const { env } = await start({
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
});
assert.containsNone(
@@ -176,12 +159,12 @@ QUnit.test('do not add livechat in the sidebar on visitor typing', async functio
);
// simulate livechat visitor typing
const channel = this.data['mail.channel'].records.find(channel => channel.id === 10);
const channel = pyEnv['mail.channel'].searchRead([['id', '=', mailChannelId1]])[0];
await env.services.rpc({
route: '/im_livechat/notify_typing',
params: {
context: {
mockedPartnerId: this.publicPartnerId,
mockedPartnerId: pyEnv.publicPartnerId,
},
is_typing: true,
uuid: channel.uuid,
@@ -198,32 +181,26 @@ QUnit.test('do not add livechat in the sidebar on visitor typing', async functio
QUnit.test('add livechat in the sidebar on visitor sending first message', async function (assert) {
assert.expect(4);
const currentUser = this.data['res.users'].records.find(user =>
user.id === this.data.currentUserId
);
currentUser.im_status = 'online';
this.data['res.country'].records.push({
const pyEnv = await startServer();
pyEnv['res.users'].write([pyEnv.currentUserId], { im_status: 'online' });
const resCountryId1 = pyEnv['res.country'].create({
code: 'be',
id: 10,
name: "Belgium",
});
this.data['im_livechat.channel'].records.push({
id: 10,
user_ids: [this.data.currentUserId],
const imLivechatChannelId1 = pyEnv['im_livechat.channel'].create({
user_ids: [pyEnv.currentUserId],
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor (Belgium)",
channel_type: 'livechat',
country_id: 10,
id: 10,
country_id: resCountryId1,
is_pinned: false,
livechat_channel_id: 10,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.publicPartnerId, this.data.currentPartnerId],
livechat_channel_id: imLivechatChannelId1,
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.publicPartnerId, pyEnv.currentPartnerId],
});
const { env } = await start({
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
});
assert.containsNone(
@@ -233,7 +210,7 @@ QUnit.test('add livechat in the sidebar on visitor sending first message', async
);
// simulate livechat visitor sending a message
const channel = this.data['mail.channel'].records.find(channel => channel.id === 10);
const channel = pyEnv['mail.channel'].searchRead([['id', '=', mailChannelId1]])[0];
await afterNextRender(async () => env.services.rpc({
route: '/mail/chat_post',
params: {
@@ -264,35 +241,33 @@ QUnit.test('add livechat in the sidebar on visitor sending first message', async
QUnit.test('livechats are sorted by last activity time in the sidebar: most recent at the top', async function (assert) {
assert.expect(6);
this.data['mail.channel'].records.push(
const pyEnv = await startServer();
const [mailChannelId1, mailChannelId2] = pyEnv['mail.channel'].create([
{
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
last_interest_dt: datetime_to_str(new Date(2021, 0, 1)), // less recent one
},
{
anonymous_name: "Visitor 12",
channel_type: 'livechat',
id: 12,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
last_interest_dt: datetime_to_str(new Date(2021, 0, 2)), // more recent one
},
);
]);
const { messaging } = await start({
autoOpenDiscuss: true,
data: this.data,
hasDiscuss: true,
});
const livechat11 = messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
});
const livechat12 = messaging.models['Thread'].findFromIdentifyingData({
id: 12,
id: mailChannelId2,
model: 'mail.channel',
});
const initialLivechats = document.querySelectorAll('.o_DiscussSidebar_categoryLivechat .o_DiscussSidebarCategoryItem');
@@ -338,21 +313,20 @@ QUnit.test('livechats are sorted by last activity time in the sidebar: most rece
QUnit.test('invite button should be present on livechat', async function (assert) {
assert.expect(1);
this.data['mail.channel'].records.push(
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create(
{
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
},
);
await start({
autoOpenDiscuss: true,
data: this.data,
discuss: {
params: {
default_active_id: 'mail.channel_11',
default_active_id: `mail.channel_${mailChannelId1}`,
},
},
hasDiscuss: true,
@@ -2,29 +2,25 @@
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('messaging_menu_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('messaging_menu_tests.js');
QUnit.test('livechats should be in "chat" filter', async function (assert) {
assert.expect(7);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 11",
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { createMessagingMenuComponent, messaging } = await start({ data: this.data });
const { createMessagingMenuComponent, messaging } = await start();
await createMessagingMenuComponent();
assert.containsOnce(
document.body,
@@ -52,7 +48,7 @@ QUnit.test('livechats should be in "chat" filter', async function (assert) {
document.body,
`.o_ThreadPreview[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -71,7 +67,7 @@ QUnit.test('livechats should be in "chat" filter', async function (assert) {
document.body,
`.o_ThreadPreview[data-thread-local-id="${
messaging.models['Thread'].findFromIdentifyingData({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}).localId
}"]`,
@@ -2,17 +2,15 @@
import {
afterNextRender,
beforeEach,
createRootMessagingComponent,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_icon_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.createThreadIcon = async (thread, target) => {
await createRootMessagingComponent(thread.env, "ThreadIcon", {
props: { threadLocalId: thread.localId },
@@ -25,16 +23,16 @@ QUnit.module('thread_icon_tests.js', {
QUnit.test('livechat: public website visitor is typing', async function (assert) {
assert.expect(4);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 20",
channel_type: 'livechat',
id: 20,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadIcon(thread, widget.el);
@@ -54,7 +52,7 @@ QUnit.test('livechat: public website visitor is typing', async function (assert)
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: messaging.publicPartners[0].id,
partner_name: messaging.publicPartners[0].name,
@@ -2,17 +2,15 @@
import {
afterNextRender,
beforeEach,
createRootMessagingComponent,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('im_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_textual_typing_status_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.createThreadTextualTypingStatusComponent = async (thread, target) => {
await createRootMessagingComponent(thread.env, "ThreadTextualTypingStatus", {
props: { threadLocalId: thread.localId },
@@ -25,16 +23,16 @@ QUnit.module('thread_textual_typing_status_tests.js', {
QUnit.test('receive visitor typing status "is typing"', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({
anonymous_name: "Visitor 20",
channel_type: 'livechat',
id: 20,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadTextualTypingStatusComponent(thread, widget.el);
@@ -50,7 +48,7 @@ QUnit.test('receive visitor typing status "is typing"', async function (assert)
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: messaging.publicPartners[0].id,
partner_name: messaging.publicPartners[0].name,
@@ -1,35 +1,31 @@
/** @odoo-module **/
import { afterNextRender, beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { afterNextRender, start, startServer } from '@mail/../tests/helpers/test_utils';
import Bus from 'web.Bus';
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_needaction_preview_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('thread_needaction_preview_tests.js');
QUnit.test('mark as read', async function (assert) {
assert.expect(5);
this.data['mail.message'].records.push({
id: 21,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
model: 'res.partner',
needaction: true,
needaction_partner_ids: [this.data.currentPartnerId],
res_id: 11,
needaction_partner_ids: [pyEnv.currentPartnerId],
res_id: resPartnerId1,
});
this.data['mail.notification'].records.push({
mail_message_id: 21,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: this.data.currentPartnerId,
res_partner_id: pyEnv.currentPartnerId,
});
const { afterEvent, click, createMessagingMenuComponent } = await start({
data: this.data,
hasChatWindow: true,
async mockRPC(route, args) {
if (route.includes('mark_all_as_read')) {
@@ -38,7 +34,7 @@ QUnit.test('mark as read', async function (assert) {
args.kwargs.domain,
[
['model', '=', 'res.partner'],
['res_id', '=', 11],
['res_id', '=', resPartnerId1],
],
"should mark all as read the correct thread"
);
@@ -76,21 +72,21 @@ QUnit.test('mark as read', async function (assert) {
QUnit.test('click on preview should mark as read and open the thread', async function (assert) {
assert.expect(6);
this.data['mail.message'].records.push({
id: 21,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
model: 'res.partner',
needaction: true,
needaction_partner_ids: [this.data.currentPartnerId],
res_id: 11,
needaction_partner_ids: [pyEnv.currentPartnerId],
res_id: resPartnerId1,
});
this.data['mail.notification'].records.push({
mail_message_id: 21,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: this.data.currentPartnerId,
res_partner_id: pyEnv.currentPartnerId,
});
const { afterEvent, click, createMessagingMenuComponent } = await start({
data: this.data,
hasChatWindow: true,
async mockRPC(route, args) {
if (route.includes('mark_all_as_read')) {
@@ -99,7 +95,7 @@ QUnit.test('click on preview should mark as read and open the thread', async fun
args.kwargs.domain,
[
['model', '=', 'res.partner'],
['res_id', '=', 11],
['res_id', '=', resPartnerId1],
],
"should mark all as read the correct thread"
);
@@ -142,12 +138,26 @@ QUnit.test('click on preview should mark as read and open the thread', async fun
QUnit.test('click on expand from chat window should close the chat window and open the form view', async function (assert) {
assert.expect(8);
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
model: 'res.partner',
needaction: true,
needaction_partner_ids: [pyEnv.currentPartnerId],
res_id: resPartnerId1,
});
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: pyEnv.currentPartnerId,
});
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
assert.strictEqual(
payload.action.res_id,
11,
resPartnerId1,
"should redirect to the id of the thread"
);
assert.strictEqual(
@@ -156,21 +166,7 @@ QUnit.test('click on expand from chat window should close the chat window and op
"should redirect to the model of the thread"
);
});
this.data['mail.message'].records.push({
id: 21,
model: 'res.partner',
needaction: true,
needaction_partner_ids: [this.data.currentPartnerId],
res_id: 11,
});
this.data['mail.notification'].records.push({
mail_message_id: 21,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: this.data.currentPartnerId,
});
const { afterEvent, click, createMessagingMenuComponent } = await start({
data: this.data,
env: { bus },
hasChatWindow: true,
});
@@ -218,21 +214,21 @@ QUnit.test('[technical] opening a non-channel chat window should not call channe
// window, because there is no server sync of fold state for them.
assert.expect(3);
this.data['mail.message'].records.push({
id: 21,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
model: 'res.partner',
needaction: true,
needaction_partner_ids: [this.data.currentPartnerId],
res_id: 11,
needaction_partner_ids: [pyEnv.currentPartnerId],
res_id: resPartnerId1,
});
this.data['mail.notification'].records.push({
mail_message_id: 21,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: this.data.currentPartnerId,
res_partner_id: pyEnv.currentPartnerId,
});
const { afterEvent, click, createMessagingMenuComponent } = await start({
data: this.data,
hasChatWindow: true,
async mockRPC(route, args) {
if (route.includes('channel_fold')) {
@@ -275,33 +271,31 @@ QUnit.test('[technical] opening a non-channel chat window should not call channe
QUnit.test('preview should display last needaction message preview even if there is a more recent message that is not needaction in the thread', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({
id: 11,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Stranger",
});
this.data['mail.message'].records.push({
author_id: 11,
const mailMessageId1 = pyEnv['mail.message'].create({
author_id: resPartnerId1,
body: "I am the oldest but needaction",
id: 21,
model: 'res.partner',
needaction: true,
needaction_partner_ids: [this.data.currentPartnerId],
res_id: 11,
needaction_partner_ids: [pyEnv.currentPartnerId],
res_id: resPartnerId1,
});
this.data['mail.message'].records.push({
author_id: this.data.currentPartnerId,
pyEnv['mail.message'].create({
author_id: pyEnv.currentPartnerId,
body: "I am more recent",
id: 22,
model: 'res.partner',
res_id: 11,
res_id: resPartnerId1,
});
this.data['mail.notification'].records.push({
mail_message_id: 21,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: this.data.currentPartnerId,
res_partner_id: pyEnv.currentPartnerId,
});
const { afterEvent, createMessagingMenuComponent } = await start({ data: this.data, hasChatWindow: true });
const { afterEvent, createMessagingMenuComponent } = await start({ hasChatWindow: true });
await createMessagingMenuComponent();
await afterNextRender(() => afterEvent({
eventName: 'o-thread-cache-loaded-messages',
@@ -326,23 +320,23 @@ QUnit.test('preview should display last needaction message preview even if there
QUnit.test('chat window header should not have unread counter for non-channel thread', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({ id: 11 });
this.data['mail.message'].records.push({
author_id: 11,
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
author_id: resPartnerId1,
body: 'not empty',
id: 21,
model: 'res.partner',
needaction: true,
needaction_partner_ids: [this.data.currentPartnerId],
res_id: 11,
needaction_partner_ids: [pyEnv.currentPartnerId],
res_id: resPartnerId1,
});
this.data['mail.notification'].records.push({
mail_message_id: 21,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'inbox',
res_partner_id: this.data.currentPartnerId,
res_partner_id: pyEnv.currentPartnerId,
});
const { afterEvent, click, createMessagingMenuComponent } = await start({ data: this.data, hasChatWindow: true });
const { afterEvent, click, createMessagingMenuComponent } = await start({ hasChatWindow: true });
await createMessagingMenuComponent();
await afterNextRender(() => afterEvent({
eventName: 'o-thread-cache-loaded-messages',
@@ -1,31 +1,23 @@
/** @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('components', {}, function () {
QUnit.module('thread_preview_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('thread_preview_tests.js');
QUnit.test('mark as read', async function (assert) {
assert.expect(6);
this.data['mail.channel'].records.push({
id: 11,
message_unread_counter: 1,
seen_message_id: 99,
});
this.data['mail.message'].records.push({
id: 100,
model: 'mail.channel',
res_id: 11,
});
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({ message_unread_counter: 1 });
const [mailMessageId1] = pyEnv['mail.message'].create([
{ model: 'mail.channel', res_id: mailChannelId1 },
{ model: 'mail.channel', res_id: mailChannelId1 },
]);
pyEnv['mail.channel'].write([mailChannelId1], { seen_message_id: mailMessageId1 });
const { click, createMessagingMenuComponent } = await start({
data: this.data,
hasChatWindow: true,
async mockRPC(route, args) {
if (route.includes('set_last_seen_message')) {
@@ -2,18 +2,16 @@
import {
afterNextRender,
beforeEach,
createRootMessagingComponent,
nextAnimationFrame,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_textual_typing_status_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.createThreadTextualTypingStatusComponent = async (thread, target) => {
await createRootMessagingComponent(thread.env, "ThreadTextualTypingStatus", {
props: { threadLocalId: thread.localId },
@@ -26,14 +24,14 @@ QUnit.module('thread_textual_typing_status_tests.js', {
QUnit.test('receive other member typing status "is typing"', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({ id: 17, name: 'Demo' });
this.data['mail.channel'].records.push({
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 17],
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: 'Demo' });
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadTextualTypingStatusComponent(thread, widget.el);
@@ -49,9 +47,9 @@ QUnit.test('receive other member typing status "is typing"', async function (ass
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 17,
partner_id: resPartnerId1,
partner_name: "Demo",
},
}]);
@@ -66,14 +64,14 @@ QUnit.test('receive other member typing status "is typing"', async function (ass
QUnit.test('receive other member typing status "is typing" then "no longer is typing"', async function (assert) {
assert.expect(3);
this.data['res.partner'].records.push({ id: 17, name: 'Demo' });
this.data['mail.channel'].records.push({
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 17],
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: 'Demo' });
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadTextualTypingStatusComponent(thread, widget.el);
@@ -89,9 +87,9 @@ QUnit.test('receive other member typing status "is typing" then "no longer is ty
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 17,
partner_id: resPartnerId1,
partner_name: "Demo",
},
}]);
@@ -107,9 +105,9 @@ QUnit.test('receive other member typing status "is typing" then "no longer is ty
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: false,
partner_id: 17,
partner_id: resPartnerId1,
partner_name: "Demo",
},
}]);
@@ -124,14 +122,16 @@ QUnit.test('receive other member typing status "is typing" then "no longer is ty
QUnit.test('assume other member typing status becomes "no longer is typing" after 60 seconds without any updated typing status', async function (assert) {
assert.expect(3);
this.data['res.partner'].records.push({ id: 17, name: 'Demo' });
this.data['mail.channel'].records.push({
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 17],
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: 'Demo' });
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { env, messaging, widget } = await start({
hasTimeControl: true,
});
const { env, messaging, widget } = await start({ data: this.data, hasTimeControl: true });
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadTextualTypingStatusComponent(thread, widget.el);
@@ -147,9 +147,9 @@ QUnit.test('assume other member typing status becomes "no longer is typing" afte
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 17,
partner_id: resPartnerId1,
partner_name: "Demo",
},
}]);
@@ -171,17 +171,16 @@ QUnit.test('assume other member typing status becomes "no longer is typing" afte
QUnit.test ('other member typing status "is typing" refreshes 60 seconds timer of assuming no longer typing', async function (assert) {
assert.expect(4);
this.data['res.partner'].records.push({ id: 17, name: 'Demo' });
this.data['mail.channel'].records.push({
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 17],
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: 'Demo' });
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
const { env, messaging, widget } = await start({
data: this.data,
hasTimeControl: true,
});
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadTextualTypingStatusComponent(thread, widget.el);
@@ -197,9 +196,9 @@ QUnit.test ('other member typing status "is typing" refreshes 60 seconds timer o
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 17,
partner_id: resPartnerId1,
partner_name: "Demo",
},
}]);
@@ -215,9 +214,9 @@ QUnit.test ('other member typing status "is typing" refreshes 60 seconds timer o
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 17,
partner_id: resPartnerId1,
partner_name: "Demo",
},
}]);
@@ -240,18 +239,18 @@ QUnit.test ('other member typing status "is typing" refreshes 60 seconds timer o
QUnit.test('receive several other members typing status "is typing"', async function (assert) {
assert.expect(6);
this.data['res.partner'].records.push(
{ id: 10, name: 'Other10' },
{ id: 11, name: 'Other11' },
{ id: 12, name: 'Other12' }
);
this.data['mail.channel'].records.push({
id: 20,
channel_partner_ids: [this.data.currentPartnerId, 10, 11, 12],
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2, resPartnerId3] = pyEnv['res.partner'].create([
{ name: 'Other 10' },
{ name: 'Other 11' },
{ name: 'Other 12' },
]);
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1, resPartnerId2, resPartnerId3],
});
const { messaging, widget } = await start({ data: this.data });
const { messaging, widget } = await start();
const thread = messaging.models['Thread'].findFromIdentifyingData({
id: 20,
id: mailChannelId1,
model: 'mail.channel',
});
await this.createThreadTextualTypingStatusComponent(thread, widget.el);
@@ -267,9 +266,9 @@ QUnit.test('receive several other members typing status "is typing"', async func
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 10,
partner_id: resPartnerId1,
partner_name: "Other10",
},
}]);
@@ -285,9 +284,9 @@ QUnit.test('receive several other members typing status "is typing"', async func
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 11,
partner_id: resPartnerId2,
partner_name: "Other11",
},
}]);
@@ -303,9 +302,9 @@ QUnit.test('receive several other members typing status "is typing"', async func
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 12,
partner_id: resPartnerId3,
partner_name: "Other12",
},
}]);
@@ -321,9 +320,9 @@ QUnit.test('receive several other members typing status "is typing"', async func
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: false,
partner_id: 10,
partner_id: resPartnerId1,
partner_name: "Other10",
},
}]);
@@ -339,9 +338,9 @@ QUnit.test('receive several other members typing status "is typing"', async func
widget.call('bus_service', 'trigger', 'notification', [{
type: 'mail.channel.partner/typing_status',
payload: {
channel_id: 20,
channel_id: mailChannelId1,
is_typing: true,
partner_id: 10,
partner_id: resPartnerId1,
partner_name: "Other10",
},
}]);
File diff suppressed because it is too large Load Diff
@@ -1,20 +1,16 @@
/** @odoo-module **/
import { insert } 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('thread_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('thread_tests.js');
QUnit.test('inbox & starred mailboxes', async function (assert) {
assert.expect(10);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
const mailboxInbox = messaging.inbox;
const mailboxStarred = messaging.starred;
assert.ok(mailboxInbox, "should have mailbox inbox");
@@ -32,7 +28,7 @@ QUnit.test('inbox & starred mailboxes', async function (assert) {
QUnit.test('create (channel)', async function (assert) {
assert.expect(23);
const { messaging } = await start({ data: this.data });
const { messaging } = await start();
assert.notOk(messaging.models['Partner'].findFromIdentifyingData({ id: 9 }));
assert.notOk(messaging.models['Partner'].findFromIdentifyingData({ id: 10 }));
assert.notOk(messaging.models['Thread'].findFromIdentifyingData({
@@ -91,7 +87,7 @@ QUnit.test('create (channel)', async function (assert) {
QUnit.test('create (chat)', async function (assert) {
assert.expect(15);
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: 200,
@@ -1,6 +1,6 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
import throttle from '@mail/utils/throttle';
import { nextTick } from '@mail/utils/utils';
@@ -11,7 +11,6 @@ QUnit.module('utils', {}, function () {
QUnit.module('throttle', {}, function () {
QUnit.module('throttle_tests.js', {
async beforeEach() {
await beforeEach(this);
this.throttles = [];
},
afterEach() {
@@ -27,7 +26,6 @@ QUnit.test('single call', async function (assert) {
assert.expect(6);
const { env, messaging } = await start({
data: this.data,
hasTimeControl: true,
});
@@ -76,7 +74,6 @@ QUnit.test('2nd (throttled) call', async function (assert) {
assert.expect(8);
const { env, messaging } = await start({
data: this.data,
hasTimeControl: true,
});
@@ -136,7 +133,6 @@ QUnit.test('throttled call reinvocation', async function (assert) {
assert.expect(11);
const { env, messaging } = await start({
data: this.data,
hasTimeControl: true,
});
@@ -215,7 +211,6 @@ QUnit.test('flush throttled call', async function (assert) {
assert.expect(9);
const { env, messaging } = await start({
data: this.data,
hasTimeControl: true,
});
@@ -272,7 +267,6 @@ QUnit.test('cancel throttled call', async function (assert) {
assert.expect(10);
const { env, messaging } = await start({
data: this.data,
hasTimeControl: true,
});
@@ -339,7 +333,6 @@ QUnit.test('clear throttled call', async function (assert) {
assert.expect(9);
const { env, messaging } = await start({
data: this.data,
hasTimeControl: true,
});
@@ -1,23 +1,17 @@
/** @odoo-module **/
import ActivityMenu from '@mail/js/systray/systray_activity_menu';
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start } from '@mail/../tests/helpers/test_utils';
import testUtils from 'web.test_utils';
QUnit.module('note', {}, function () {
QUnit.module("ActivityMenu", {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module("ActivityMenu");
QUnit.test('note activity menu widget: create note from activity menu', async function (assert) {
assert.expect(15);
const { widget } = await start({
data: this.data,
});
const { widget } = await start();
const activityMenu = new ActivityMenu(widget);
await activityMenu.appendTo($('#qunit-fixture'));
@@ -4,45 +4,40 @@ import { insert, insertAndReplace } from '@mail/model/model_field_command';
import { makeDeferred } from '@mail/utils/deferred';
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import Bus from 'web.Bus';
QUnit.module('sms', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('message_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('message_tests.js');
QUnit.test('Notification Sent', async function (assert) {
assert.expect(9);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: "Someone", partner_share: true });
const mailChannelId1 = pyEnv['mail.channel'].create({});
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'sms',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
id: 11,
mail_message_id: 10,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'sms',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({ data: this.data });
const { createThreadViewComponent, messaging } = await start();
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -103,6 +98,21 @@ QUnit.test('Notification Error', async function (assert) {
assert.expect(8);
const openResendActionDef = makeDeferred();
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ name: "Someone", partner_share: true });
const mailChannelId1 = pyEnv['mail.channel'].create({});
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
message_type: 'sms',
model: 'mail.channel',
res_id: mailChannelId1,
});
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'sms',
res_partner_id: resPartnerId1,
});
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
@@ -113,33 +123,17 @@ QUnit.test('Notification Error', async function (assert) {
);
assert.strictEqual(
payload.options.additional_context.default_mail_message_id,
10,
mailMessageId1,
"action should have correct message id"
);
openResendActionDef.resolve();
});
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
body: 'not empty',
id: 10,
message_type: 'sms',
model: 'mail.channel',
res_id: 11,
});
this.data['mail.notification'].records.push({
id: 11,
mail_message_id: 10,
notification_status: 'exception',
notification_type: 'sms',
res_partner_id: 12,
});
const { createThreadViewComponent, messaging } = await start({ data: this.data, env: { bus } });
const { createThreadViewComponent, messaging } = await start({ env: { bus } });
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -1,40 +1,37 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import Bus from 'web.Bus';
QUnit.module('sms', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('notification_list', {}, function () {
QUnit.module('notification_list_notification_group_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('notification_list_notification_group_tests.js');
QUnit.test('mark as read', async function (assert) {
assert.expect(2);
this.data['mail.message'].records.push(
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({});
const mailMessageId1 = pyEnv['mail.message'].create(
// message that is expected to have a failure
{
author_id: this.data.currentPartnerId,
id: 11,
author_id: pyEnv.currentPartnerId,
message_type: 'sms',
model: 'mail.channel',
res_id: 31,
res_id: mailChannelId1,
}
);
this.data['mail.notification'].records.push(
pyEnv['mail.notification'].create(
// failure that is expected to be used in the test
{
mail_message_id: 11, // id of the related message
mail_message_id: mailMessageId1, // id of the related message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'sms',
}
);
const { afterNextRender, createNotificationListComponent } = await start({ data: this.data });
const { afterNextRender, createNotificationListComponent } = await start();
await createNotificationListComponent();
assert.containsOnce(
document.body,
@@ -55,47 +52,45 @@ QUnit.test('mark as read', async function (assert) {
QUnit.test('notifications grouped by notification_type', async function (assert) {
assert.expect(11);
this.data['mail.message'].records.push(
// first message that is expected to have a failure
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
{
id: 11, // random unique id, will be used to link failure to message
message_type: 'sms', // different type from second message
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: 31, // same res_id as second message
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
// second message that is expected to have a failure
{
id: 12, // random unique id, will be used to link failure to message
message_type: 'email', // different type from first message
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: 31, // same res_id as first message
res_id: resPartnerId1, // same res_id as first message
res_model_name: "Partner", // same related model name for consistency
}
);
this.data['mail.notification'].records.push(
},
]);
pyEnv['mail.notification'].create([
{
mail_message_id: 11, // id of the related first message
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'sms', // different type from second failure
},
{
mail_message_id: 11,
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'sms',
},
{
mail_message_id: 12, // id of the related second message
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'email', // different type from first failure
},
{
mail_message_id: 12,
mail_message_id: mailMessageId2,
notification_status: 'exception',
notification_type: 'email',
},
);
const { createNotificationListComponent } = await start({ data: this.data });
]);
const { createNotificationListComponent } = await start();
await createNotificationListComponent();
assert.containsN(
@@ -163,10 +158,10 @@ QUnit.test('grouped notifications by document model', async function (assert) {
// document model.
assert.expect(12);
this.data['mail.message'].records.push(
const pyEnv = await startServer();
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
// first message that is expected to have a failure
{
id: 11, // random unique id, will be used to link failure to message
message_type: 'sms', // message must be sms (goal of the test)
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: 31, // different res_id from second message
@@ -174,27 +169,26 @@ QUnit.test('grouped notifications by document model', async function (assert) {
},
// second message that is expected to have a failure
{
id: 12, // random unique id, will be used to link failure to message
message_type: 'sms', // message must be sms (goal of the test)
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: 32, // different res_id from first message
res_model_name: "Partner", // same related model name for consistency
}
);
this.data['mail.notification'].records.push(
},
]);
pyEnv['mail.notification'].create([
// first failure that is expected to be used in the test
{
mail_message_id: 11, // id of the related first message
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'sms', // expected failure type for sms message
},
// second failure that is expected to be used in the test
{
mail_message_id: 12, // id of the related second message
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'sms', // expected failure type for sms message
}
);
},
]);
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
@@ -235,7 +229,7 @@ QUnit.test('grouped notifications by document model', async function (assert) {
);
});
const { createNotificationListComponent } = await start({ data: this.data, env: { bus } });
const { createNotificationListComponent } = await start({ env: { bus } });
await createNotificationListComponent();
assert.containsOnce(
@@ -3,45 +3,43 @@
import { insert, insertAndReplace } from '@mail/model/model_field_command';
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import Bus from 'web.Bus';
QUnit.module('snailmail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('message_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('components', {}, async function() {
QUnit.module('message_tests.js');
QUnit.test('Sent', async function (assert) {
assert.expect(8);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
id: 11,
mail_message_id: 10,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'sent',
notification_type: 'snail',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({ data: this.data });
const { createThreadViewComponent, messaging } = await start();
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -96,28 +94,30 @@ QUnit.test('Sent', async function (assert) {
QUnit.test('Canceled', async function (assert) {
assert.expect(8);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
id: 11,
mail_message_id: 10,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'canceled',
notification_type: 'snail',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({ data: this.data });
const { createThreadViewComponent, messaging } = await start();
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -172,28 +172,30 @@ QUnit.test('Canceled', async function (assert) {
QUnit.test('Pending', async function (assert) {
assert.expect(8);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
id: 11,
mail_message_id: 10,
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1,
notification_status: 'ready',
notification_type: 'snail',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({ data: this.data });
const { createThreadViewComponent, messaging } = await start();
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -248,28 +250,29 @@ QUnit.test('Pending', async function (assert) {
QUnit.test('No Price Available', async function (assert) {
assert.expect(10);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
pyEnv['mail.notification'].create({
failure_type: 'sn_price',
id: 11,
mail_message_id: 10,
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({
data: this.data,
hasDialog: true,
async mockRPC(route, args) {
if (args.method === 'cancel_letter' && args.model === 'mail.message' && args.args[0][0] === 10) {
if (args.method === 'cancel_letter' && args.model === 'mail.message' && args.args[0][0] === mailMessageId1) {
assert.step(args.method);
}
return this._super(...arguments);
@@ -279,7 +282,7 @@ QUnit.test('No Price Available', async function (assert) {
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -342,28 +345,29 @@ QUnit.test('No Price Available', async function (assert) {
QUnit.test('Credit Error', async function (assert) {
assert.expect(11);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
pyEnv['mail.notification'].create({
failure_type: 'sn_credit',
id: 11,
mail_message_id: 10,
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({
data: this.data,
hasDialog: true,
async mockRPC(route, args) {
if (args.method === 'send_letter' && args.model === 'mail.message' && args.args[0][0] === 10) {
if (args.method === 'send_letter' && args.model === 'mail.message' && args.args[0][0] === mailMessageId1) {
assert.step(args.method);
}
return this._super(...arguments);
@@ -373,7 +377,7 @@ QUnit.test('Credit Error', async function (assert) {
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -441,28 +445,29 @@ QUnit.test('Credit Error', async function (assert) {
QUnit.test('Trial Error', async function (assert) {
assert.expect(11);
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
res_id: mailChannelId1,
});
this.data['mail.notification'].records.push({
pyEnv['mail.notification'].create({
failure_type: 'sn_trial',
id: 11,
mail_message_id: 10,
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
res_partner_id: 12,
res_partner_id: resPartnerId1,
});
const { createThreadViewComponent, messaging } = await start({
data: this.data,
hasDialog: true,
async mockRPC(route, args) {
if (args.method === 'send_letter' && args.model === 'mail.message' && args.args[0][0] === 10) {
if (args.method === 'send_letter' && args.model === 'mail.message' && args.args[0][0] === mailMessageId1) {
assert.step(args.method);
}
return this._super(...arguments);
@@ -472,7 +477,7 @@ QUnit.test('Trial Error', async function (assert) {
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -540,6 +545,25 @@ QUnit.test('Trial Error', async function (assert) {
QUnit.test('Format Error', async function (assert) {
assert.expect(8);
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({
name: "Someone",
partner_share: true,
});
const mailChannelId1 = pyEnv['mail.channel'].create();
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
message_type: 'snailmail',
model: 'mail.channel',
res_id: mailChannelId1,
});
pyEnv['mail.notification'].create({
failure_type: 'sn_format',
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
res_partner_id: resPartnerId1,
});
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
@@ -550,33 +574,16 @@ QUnit.test('Format Error', async function (assert) {
);
assert.strictEqual(
payload.options.additional_context.message_id,
10,
mailMessageId1,
"action should have correct message id"
);
});
this.data['res.partner'].records.push({ id: 12, name: "Someone", partner_share: true });
this.data['mail.channel'].records.push({ id: 11 });
this.data['mail.message'].records.push({
body: 'not empty',
id: 10,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 11,
});
this.data['mail.notification'].records.push({
failure_type: 'sn_format',
id: 11,
mail_message_id: 10,
notification_status: 'exception',
notification_type: 'snail',
res_partner_id: 12,
});
const { createThreadViewComponent, messaging } = await start({ data: this.data, env: { bus } });
const { createThreadViewComponent, messaging } = await start({ env: { bus } });
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({
id: 11,
id: mailChannelId1,
model: 'mail.channel',
}),
});
@@ -615,22 +622,22 @@ QUnit.test('Format Error', async function (assert) {
QUnit.test('Missing Required Fields', async function (assert) {
assert.expect(8);
this.data['mail.message'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({});
const mailMessageId1 = pyEnv['mail.message'].create({
body: 'not empty',
id: 10, // random unique id, useful to link letter and notification
message_type: 'snailmail',
res_id: 20, // non 0 id, necessary to fetch failure at init
res_id: resPartnerId1, // non 0 id, necessary to fetch failure at init
model: 'res.partner', // not mail.compose.message, necessary to fetch failure at init
});
this.data['mail.notification'].records.push({
pyEnv['mail.notification'].create({
failure_type: 'sn_fields',
mail_message_id: 10,
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
});
this.data['snailmail.letter'].records.push({
id: 22, // random unique id, will be asserted in the test
message_id: 10, // id of related message
const snailMailLetterId1 = pyEnv['snailmail.letter'].create({
message_id: mailMessageId1,
});
const bus = new Bus();
bus.on('do-action', null, payload => {
@@ -642,19 +649,18 @@ QUnit.test('Missing Required Fields', async function (assert) {
);
assert.strictEqual(
payload.options.additional_context.default_letter_id,
22,
snailMailLetterId1,
"action should have correct letter id"
);
});
const { createThreadViewComponent, messaging } = await start({
data: this.data,
env: { bus },
});
const threadViewer = messaging.models['ThreadViewer'].create({
hasThreadView: true,
qunitTest: insertAndReplace(),
thread: insert({ id: 20, model: 'res.partner' }),
thread: insert({ id: resPartnerId1, model: 'res.partner' }),
});
await createThreadViewComponent(threadViewer.threadView);
@@ -1,16 +1,12 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import Bus from 'web.Bus';
QUnit.module('snailmail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('notification_list_notification_group_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('notification_list_notification_group_tests.js');
QUnit.test('mark as read', async function (assert) {
assert.expect(2);
@@ -19,21 +15,22 @@ QUnit.test('mark as read', async function (assert) {
// Actually, the server rely on the model "snailmail.letter" to identify the notification to cancel
// The following code simulates the cancel of the notification without using "snailmail.letter" model
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create();
// message that is expected to have a failure
this.data['mail.message'].records.push({
author_id: this.data.currentPartnerId,
id: 11,
const mailMessageId1 = pyEnv['mail.message'].create({
author_id: pyEnv.currentPartnerId,
message_type: 'snailmail',
model: 'mail.channel',
res_id: 31,
res_id: mailChannelId1,
});
// failure that is expected to be used in the test
this.data['mail.notification'].records.push({
mail_message_id: 11, // id of the related message
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1, // id of the related message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail',
});
const { afterNextRender, createNotificationListComponent } = await start({ data: this.data });
const { afterNextRender, createNotificationListComponent } = await start();
await createNotificationListComponent();
assert.containsOnce(
document.body,
@@ -54,47 +51,47 @@ QUnit.test('mark as read', async function (assert) {
QUnit.test('notifications grouped by notification_type', async function (assert) {
assert.expect(11);
this.data['mail.message'].records.push(
const pyEnv = await startServer();
const resPartnerId1 = await pyEnv['res.partner'].create({});
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
// first message that is expected to have a failure
{
id: 11, // random unique id, will be used to link failure to message
message_type: 'snailmail', // different type from second message
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: 31, // same res_id as second message
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
// second message that is expected to have a failure
{
id: 12, // random unique id, will be used to link failure to message
message_type: 'email', // different type from first message
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: 31, // same res_id as first message
res_id: resPartnerId1, // same res_id as first message
res_model_name: "Partner", // same related model name for consistency
}
);
this.data['mail.notification'].records.push(
},
]);
pyEnv['mail.notification'].create([
{
mail_message_id: 11, // id of the related first message
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // different type from second failure
},
{
mail_message_id: 11,
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
},
{
mail_message_id: 12, // id of the related second message
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'email', // different type from first failure
},
{
mail_message_id: 12,
mail_message_id: mailMessageId2,
notification_status: 'exception',
notification_type: 'email',
},
);
const { createNotificationListComponent } = await start({ data: this.data });
]);
const { createNotificationListComponent } = await start();
await createNotificationListComponent();
assert.containsN(
@@ -162,38 +159,36 @@ QUnit.test('grouped notifications by document model', async function (assert) {
// document model.
assert.expect(12);
this.data['mail.message'].records.push(
// first message that is expected to have a failure
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = await pyEnv['res.partner'].create([{}, {}]);
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
{
id: 11, // random unique id, will be used to link failure to message
message_type: 'snailmail', // message must be snailmail (goal of the test)
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: 31, // different res_id from second message
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
// second message that is expected to have a failure
{
id: 12, // random unique id, will be used to link failure to message
message_type: 'snailmail', // message must be snailmail (goal of the test)
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: 32, // different res_id from first message
res_id: resPartnerId2, // different res_id from first message
res_model_name: "Partner", // same related model name for consistency
}
);
this.data['mail.notification'].records.push(
},
]);
pyEnv['mail.notification'].create([
// first failure that is expected to be used in the test
{
mail_message_id: 11, // id of the related first message
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // expected failure type for snailmail message
},
// second failure that is expected to be used in the test
{
mail_message_id: 12, // id of the related second message
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // expected failure type for snailmail message
}
);
},
]);
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
@@ -234,7 +229,7 @@ QUnit.test('grouped notifications by document model', async function (assert) {
);
});
const { createNotificationListComponent } = await start({ data: this.data, env: { bus } });
const { createNotificationListComponent } = await start({ env: { bus } });
await createNotificationListComponent();
assert.containsOnce(
@@ -1,8 +1,8 @@
/** @odoo-module **/
import {
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import FormView from 'web.FormView';
@@ -10,9 +10,7 @@ import testUtils from 'web.test_utils';
QUnit.module('test_mail', {}, function () {
QUnit.module('tracking_value_tests.js', {
async beforeEach() {
await beforeEach(this);
beforeEach() {
this.start = async params => {
return start({
arch: `<form>
@@ -33,7 +31,6 @@ QUnit.module('tracking_value_tests.js', {
</div>
</form>`,
archs: { 'mail.message,false,list': '<tree/>' },
data: this.data,
hasView: true,
model: 'mail.test.track.all',
View: FormView,
@@ -47,8 +44,9 @@ QUnit.module('tracking_value_tests.js', {
QUnit.test('basic rendering of tracking value (float type)', async function (assert) {
assert.expect(8);
this.data['mail.test.track.all'].records.push({ float_field: 12.30, id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ float_field: 12.30 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=float_field]'), 45.67);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -99,8 +97,9 @@ QUnit.test('basic rendering of tracking value (float type)', async function (ass
QUnit.test('rendering of tracked field of type float: from non-0 to 0', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ float_field: 1, id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ float_field: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=float_field]'), 0);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -116,8 +115,9 @@ QUnit.test('rendering of tracked field of type float: from non-0 to 0', async fu
QUnit.test('rendering of tracked field of type float: from 0 to non-0', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ float_field: 0, id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ float_field: 0 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=float_field]'), 1);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -133,8 +133,9 @@ QUnit.test('rendering of tracked field of type float: from 0 to non-0', async fu
QUnit.test('rendering of tracked field of type integer: from non-0 to 0', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, integer_field: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ integer_field: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=integer_field]'), 0);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -150,8 +151,9 @@ QUnit.test('rendering of tracked field of type integer: from non-0 to 0', async
QUnit.test('rendering of tracked field of type integer: from 0 to non-0', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, integer_field: 0 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ integer_field: 0 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=integer_field]'), 1);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -167,8 +169,9 @@ QUnit.test('rendering of tracked field of type integer: from 0 to non-0', async
QUnit.test('rendering of tracked field of type monetary: from non-0 to 0', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, monetary_field: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ monetary_field: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editSelect(form.$('div[name=monetary_field] > input'), 0);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -184,8 +187,9 @@ QUnit.test('rendering of tracked field of type monetary: from non-0 to 0', async
QUnit.test('rendering of tracked field of type monetary: from 0 to non-0', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, monetary_field: 0 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ monetary_field: 0 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editSelect(form.$('div[name=monetary_field] > input'), 1);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -201,8 +205,9 @@ QUnit.test('rendering of tracked field of type monetary: from 0 to non-0', async
QUnit.test('rendering of tracked field of type boolean: from true to false', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ boolean_field: true, id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ boolean_field: true });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
form.$('.custom-checkbox input').click();
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -218,8 +223,9 @@ QUnit.test('rendering of tracked field of type boolean: from true to false', asy
QUnit.test('rendering of tracked field of type boolean: from false to true', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({});
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
form.$('.custom-checkbox input').click();
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -235,8 +241,9 @@ QUnit.test('rendering of tracked field of type boolean: from false to true', asy
QUnit.test('rendering of tracked field of type char: from a string to empty string', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ char_field: 'Marc', id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ char_field: 'Marc' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=char_field]'), '');
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -252,8 +259,9 @@ QUnit.test('rendering of tracked field of type char: from a string to empty stri
QUnit.test('rendering of tracked field of type char: from empty string to a string', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ char_field: '', id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ char_field: '' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('input[name=char_field]'), 'Marc');
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -269,8 +277,9 @@ QUnit.test('rendering of tracked field of type char: from empty string to a stri
QUnit.test('rendering of tracked field of type date: from no date to a set date', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ date_field: false, id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ date_field: false });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editAndTrigger(form.$('.o_datepicker[name=date_field] .o_datepicker_input'), '12/14/2018', ['change']);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -286,8 +295,9 @@ QUnit.test('rendering of tracked field of type date: from no date to a set date'
QUnit.test('rendering of tracked field of type date: from a set date to no date', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ date_field: '2018-12-14', id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ date_field: '2018-12-14' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editAndTrigger(form.$('.o_datepicker[name=date_field] .o_datepicker_input'), '', ['change']);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -303,8 +313,9 @@ QUnit.test('rendering of tracked field of type date: from a set date to no date'
QUnit.test('rendering of tracked field of type datetime: from no date and time to a set date and time', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ datetime_field: false, id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ datetime_field: false });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editAndTrigger(form.$('.o_datepicker[name=datetime_field] .o_datepicker_input'), '12/14/2018 13:42:28', ['change']);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -320,8 +331,9 @@ QUnit.test('rendering of tracked field of type datetime: from no date and time t
QUnit.test('rendering of tracked field of type datetime: from a set date and time to no date and time', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ datetime_field: '2018-12-14 13:42:28 ', id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ datetime_field: '2018-12-14 13:42:28 ' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editAndTrigger(form.$('.o_datepicker[name=datetime_field] .o_datepicker_input'), '', ['change']);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -337,8 +349,9 @@ QUnit.test('rendering of tracked field of type datetime: from a set date and tim
QUnit.test('rendering of tracked field of type text: from some text to empty', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, text_field: 'Marc' });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ text_field: 'Marc' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('textarea[name=text_field]'), '');
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -354,8 +367,9 @@ QUnit.test('rendering of tracked field of type text: from some text to empty', a
QUnit.test('rendering of tracked field of type text: from empty to some text', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, text_field: '' });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ text_field: '' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editInput(form.$('textarea[name=text_field]'), 'Marc');
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -371,8 +385,9 @@ QUnit.test('rendering of tracked field of type text: from empty to some text', a
QUnit.test('rendering of tracked field of type selection: from a selection to no selection', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1, selection_field: 'first' });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ selection_field: 'first' });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editSelect(form.$('select[name=selection_field]'), '');
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -388,8 +403,9 @@ QUnit.test('rendering of tracked field of type selection: from a selection to no
QUnit.test('rendering of tracked field of type selection: from no selection to a selection', async function (assert) {
assert.expect(1);
this.data['mail.test.track.all'].records.push({ id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({});
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editSelect(form.$('select[name=selection_field]'), '"first"');
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -405,9 +421,10 @@ QUnit.test('rendering of tracked field of type selection: from no selection to a
QUnit.test('rendering of tracked field of type many2one: from having a related record to no related record', async function (assert) {
assert.expect(1);
this.data['res.partner'].records.push({ display_name: 'Marc', id: 11 });
this.data['mail.test.track.all'].records.push({ id: 1, many2one_field_id: 11 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create({ display_name: 'Marc' });
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({ many2one_field_id: resPartnerId1 });
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one_selection input'), '', ['keyup']);
await afterNextRender(() => testUtils.form.clickSave(form));
@@ -423,9 +440,10 @@ QUnit.test('rendering of tracked field of type many2one: from having a related r
QUnit.test('rendering of tracked field of type many2one: from no related record to having a related record', async function (assert) {
assert.expect(1);
this.data['res.partner'].records.push({ display_name: 'Marc', id: 11 });
this.data['mail.test.track.all'].records.push({ id: 1 });
const { afterNextRender, widget: form } = await this.start({ res_id: 1 });
const pyEnv = await startServer();
pyEnv['res.partner'].create({ display_name: 'Marc' });
const mailTestTrackAllId1 = pyEnv['mail.test.track.all'].create({});
const { afterNextRender, widget: form } = await this.start({ res_id: mailTestTrackAllId1 });
await testUtils.fields.many2one.clickOpenDropdown('many2one_field_id');
await testUtils.fields.many2one.clickItem('many2one_field_id', 'Marc');
@@ -1,47 +1,40 @@
/** @odoo-module **/
import {
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
QUnit.module('website_livechat', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('discuss_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('discuss_tests.js');
QUnit.test('rendering of visitor banner', async function (assert) {
assert.expect(13);
this.data['res.country'].records.push({
id: 11,
const pyEnv = await startServer();
const resCountryId1 = pyEnv['res.country'].create({
code: 'FAKE',
});
this.data['website.visitor'].records.push({
id: 11,
country_id: 11,
const websiteVisitorId1 = pyEnv['website.visitor'].create({
country_id: resCountryId1,
display_name: 'Visitor #11',
history: 'Home → Contact',
is_connected: true,
lang_name: "English",
website_name: "General website",
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
livechat_visitor_id: 11,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
livechat_visitor_id: websiteVisitorId1,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
await start({
autoOpenDiscuss: true,
data: this.data,
discuss: {
context: {
active_id: 'mail.channel_11',
active_id: `mail.channel_${mailChannelId1}`,
},
},
hasDiscuss: true,
@@ -116,32 +109,29 @@ QUnit.test('rendering of visitor banner', async function (assert) {
QUnit.test('livechat with non-logged visitor should show visitor banner', async function (assert) {
assert.expect(1);
this.data['res.country'].records.push({
id: 11,
const pyEnv = await startServer();
const resCountryId1 = pyEnv['res.country'].create({
code: 'FAKE',
});
this.data['website.visitor'].records.push({
id: 11,
country_id: 11,
const websiteVisitorId1 = pyEnv['website.visitor'].create({
country_id: resCountryId1,
display_name: 'Visitor #11',
history: 'Home → Contact',
is_connected: true,
lang_name: "English",
website_name: "General website",
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
livechat_visitor_id: 11,
channel_partner_ids: [this.data.currentPartnerId, this.data.publicPartnerId],
livechat_operator_id: pyEnv.currentPartnerId,
livechat_visitor_id: websiteVisitorId1,
channel_partner_ids: [pyEnv.currentPartnerId, pyEnv.publicPartnerId],
});
await start({
autoOpenDiscuss: true,
data: this.data,
discuss: {
context: {
active_id: 'mail.channel_11',
active_id: `mail.channel_${mailChannelId1}`,
},
},
hasDiscuss: true,
@@ -156,37 +146,33 @@ QUnit.test('livechat with non-logged visitor should show visitor banner', async
QUnit.test('livechat with logged visitor should show visitor banner', async function (assert) {
assert.expect(2);
this.data['res.country'].records.push({
id: 11,
const pyEnv = await startServer();
const resCountryId1 = pyEnv['res.country'].create({
code: 'FAKE',
});
this.data['res.partner'].records.push({
id: 12,
const resPartnerId1 = pyEnv['res.partner'].create({
name: 'Partner Visitor',
});
this.data['website.visitor'].records.push({
id: 11,
country_id: 11,
const websiteVisitorId1 = pyEnv['website.visitor'].create({
country_id: resCountryId1,
display_name: 'Visitor #11',
history: 'Home → Contact',
is_connected: true,
lang_name: "English",
partner_id: 12,
partner_id: resPartnerId1,
website_name: "General website",
});
this.data['mail.channel'].records.push({
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
livechat_visitor_id: 11,
channel_partner_ids: [this.data.currentPartnerId, 12],
livechat_operator_id: pyEnv.currentPartnerId,
livechat_visitor_id: websiteVisitorId1,
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
await start({
autoOpenDiscuss: true,
data: this.data,
discuss: {
context: {
active_id: 'mail.channel_11',
active_id: `mail.channel_${mailChannelId1}`,
},
},
hasDiscuss: true,
@@ -206,19 +192,18 @@ QUnit.test('livechat with logged visitor should show visitor banner', async func
QUnit.test('livechat without visitor should not show visitor banner', async function (assert) {
assert.expect(2);
this.data['res.partner'].records.push({ id: 11 });
this.data['mail.channel'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const mailChannelId1 = pyEnv['mail.channel'].create({
channel_type: 'livechat',
id: 11,
livechat_operator_id: this.data.currentPartnerId,
channel_partner_ids: [this.data.currentPartnerId, 11],
livechat_operator_id: pyEnv.currentPartnerId,
channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1],
});
await start({
autoOpenDiscuss: true,
data: this.data,
discuss: {
context: {
active_id: 'mail.channel_11',
active_id: `mail.channel_${mailChannelId1}`,
},
},
hasDiscuss: true,
@@ -238,13 +223,13 @@ QUnit.test('livechat without visitor should not show visitor banner', async func
QUnit.test('non-livechat channel should not show visitor banner', async function (assert) {
assert.expect(2);
this.data['mail.channel'].records.push({ id: 11, name: "General" });
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({ name: "General" });
await start({
autoOpenDiscuss: true,
data: this.data,
discuss: {
context: {
active_id: 'mail.channel_11',
active_id: `mail.channel_${mailChannelId1}`,
},
},
hasDiscuss: true,
@@ -2,29 +2,24 @@
import {
afterNextRender,
beforeEach,
start,
startServer,
} from '@mail/../tests/helpers/test_utils';
import FormView from 'web.FormView';
import { mock } from 'web.test_utils';
QUnit.module('website_livechat', {}, function () {
QUnit.module('messaging_notification_handler_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('messaging_notification_handler_tests.js');
QUnit.test('should open chat window on send chat request to website visitor', async function (assert) {
assert.expect(3);
this.data['website.visitor'].records.push({
const pyEnv = await startServer();
const websiteVisitorId1 = pyEnv['website.visitor'].create({
display_name: "Visitor #11",
id: 11,
});
const { env, widget } = await start({
data: this.data,
hasChatWindow: true,
hasView: true,
// View params
@@ -38,7 +33,7 @@ QUnit.test('should open chat window on send chat request to website visitor', as
<field name="name"/>
</form>
`,
res_id: 11,
res_id: websiteVisitorId1,
});
mock.intercept(widget, 'execute_action', payload => {
env.services.rpc({
@@ -1,42 +1,37 @@
/** @odoo-module **/
import { beforeEach, start } from '@mail/../tests/helpers/test_utils';
import { start, startServer } from '@mail/../tests/helpers/test_utils';
QUnit.module('website_slides', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('activity_tests.js', {
async beforeEach() {
await beforeEach(this);
},
});
QUnit.module('activity_tests.js');
QUnit.test('grant course access', async function (assert) {
assert.expect(8);
this.data['res.partner'].records.push({ id: 5 });
this.data['slide.channel'].records.push({ id: 100 });
this.data['mail.activity'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const slideChannelId1 = pyEnv['slide.channel'].create();
pyEnv['mail.activity'].create({
can_write: true,
id: 12,
res_id: 100,
request_partner_id: 5,
res_id: slideChannelId1,
request_partner_id: resPartnerId1,
res_model: 'slide.channel',
});
const { createChatterContainerComponent } = await start({
data: this.data,
async mockRPC(route, args) {
if (args.method === 'action_grant_access') {
assert.strictEqual(args.args.length, 1);
assert.strictEqual(args.args[0].length, 1);
assert.strictEqual(args.args[0][0], 100);
assert.strictEqual(args.kwargs.partner_id, 5);
assert.strictEqual(args.args[0][0], slideChannelId1);
assert.strictEqual(args.kwargs.partner_id, resPartnerId1);
assert.step('access_grant');
}
return this._super(...arguments);
},
});
await createChatterContainerComponent({
threadId: 100,
threadId: slideChannelId1,
threadModel: 'slide.channel',
});
@@ -50,30 +45,29 @@ QUnit.test('grant course access', async function (assert) {
QUnit.test('refuse course access', async function (assert) {
assert.expect(8);
this.data['res.partner'].records.push({ id: 5 });
this.data['slide.channel'].records.push({ id: 100 });
this.data['mail.activity'].records.push({
const pyEnv = await startServer();
const resPartnerId1 = pyEnv['res.partner'].create();
const slideChannelId1 = pyEnv['slide.channel'].create();
pyEnv['mail.activity'].create({
can_write: true,
id: 12,
res_id: 100,
request_partner_id: 5,
res_id: slideChannelId1,
request_partner_id: resPartnerId1,
res_model: 'slide.channel',
});
const { createChatterContainerComponent } = await start({
data: this.data,
async mockRPC(route, args) {
if (args.method === 'action_refuse_access') {
assert.strictEqual(args.args.length, 1);
assert.strictEqual(args.args[0].length, 1);
assert.strictEqual(args.args[0][0], 100);
assert.strictEqual(args.kwargs.partner_id, 5);
assert.strictEqual(args.args[0][0], slideChannelId1);
assert.strictEqual(args.kwargs.partner_id, resPartnerId1);
assert.step('access_refuse');
}
return this._super(...arguments);
},
});
await createChatterContainerComponent({
threadId: 100,
threadId: slideChannelId1,
threadModel: 'slide.channel',
});