diff --git a/addons/calendar/static/tests/systray_activity_menu_tests.js b/addons/calendar/static/tests/systray_activity_menu_tests.js index 16d0276012c..f77769d8bea 100644 --- a/addons/calendar/static/tests/systray_activity_menu_tests.js +++ b/addons/calendar/static/tests/systray_activity_menu_tests.js @@ -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')); diff --git a/addons/hr/static/tests/m2x_avatar_employee_tests.js b/addons/hr/static/tests/m2x_avatar_employee_tests.js index 1545df09564..c0771dd4a6a 100644 --- a/addons/hr/static/tests/m2x_avatar_employee_tests.js +++ b/addons/hr/static/tests/m2x_avatar_employee_tests.js @@ -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: '', 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: '', 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: ` @@ -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: '
', 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', diff --git a/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js b/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js index a9bedc113e2..5f1450f8dad 100644 --- a/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js +++ b/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js @@ -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", diff --git a/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js b/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js index 0b7c708ea20..025af44118f 100644 --- a/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js +++ b/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js @@ -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); diff --git a/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_view_tests.js b/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_view_tests.js index e9e9a0ac480..7371cbd2424 100644 --- a/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_view_tests.js +++ b/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_view_tests.js @@ -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({ diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js index 96a3d6d4c8e..0546305e5eb 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js @@ -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, diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js index 06a433f055b..596fc7e64e4 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js @@ -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, diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_item_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_item_tests.js index 160621b5c8f..b63e86c15ad 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_item_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_item_tests.js @@ -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' ); }); diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_tests.js index bc1dfc21fea..16c3d6cbc3a 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_sidebar_category_tests.js @@ -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 }"]`, diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js index c5840dcff45..9869ea917c4 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js @@ -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, diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js index 9a2a53b1cb8..a2b53c0af6c 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/messaging_menu_tests.js @@ -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 }"]`, diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js index f204ab41b36..e1649b274aa 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js @@ -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, diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js index 61e32338c7c..575385d32eb 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js @@ -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, diff --git a/addons/mail/static/tests/qunit_suite_tests/components/thread_needaction_preview_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/thread_needaction_preview_tests.js index 88b60adb747..e1d424c300f 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/thread_needaction_preview_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/thread_needaction_preview_tests.js @@ -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', diff --git a/addons/mail/static/tests/qunit_suite_tests/components/thread_preview_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/thread_preview_tests.js index 61a886c77e8..5aa2c809190 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/thread_preview_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/thread_preview_tests.js @@ -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')) { diff --git a/addons/mail/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js index ece5b72a74f..f45743dbbe8 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js @@ -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", }, }]); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js index 5ead1d93844..b6c69a0276e 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js @@ -3,44 +3,38 @@ import { insert, insertAndReplace, link } from '@mail/model/model_field_command'; import { afterNextRender, - beforeEach, dragenterFiles, start, + startServer, } from '@mail/../tests/helpers/test_utils'; QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { -QUnit.module('thread_view_tests.js', { - async beforeEach() { - await beforeEach(this); - }, -}); +QUnit.module('thread_view_tests.js'); QUnit.test('dragover files on thread with composer', async function (assert) { assert.expect(1); - this.data['res.partner'].records.push( + const pyEnv = await startServer(); + const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([ { email: "john@example.com", - id: 9, name: "John", }, { email: "fred@example.com", - id: 10, name: "Fred", }, - ); - this.data['mail.channel'].records.push({ + ]); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 100, - channel_partner_ids: [this.data.currentPartnerId, 9, 10], + channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1, resPartnerId2], name: "General", public: 'public', }); - const { createThreadViewComponent, messaging } = await start({ data: this.data }); + const { createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -61,35 +55,33 @@ QUnit.test('dragover files on thread with composer', async function (assert) { QUnit.test('message list desc order', async function (assert) { assert.expect(5); - for (let i = 0; i <= 60; i++) { - this.data['mail.message'].records.push({ - body: "not empty", - model: 'mail.channel', - res_id: 100, - }); - } - this.data['res.partner'].records.push( + const pyEnv = await startServer(); + const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([ { email: "john@example.com", - id: 9, name: "John", }, { email: "fred@example.com", - id: 10, name: "Fred", }, - ); - this.data['mail.channel'].records.push({ + ]); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 100, - channel_partner_ids: [this.data.currentPartnerId, 9, 10], + channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1, resPartnerId2], name: "General", public: 'public', }); - const { afterEvent, createThreadViewComponent, messaging } = await start({ data: this.data }); + for (let i = 0; i <= 60; i++) { + pyEnv['mail.message'].create({ + body: "not empty", + model: 'mail.channel', + res_id: mailChannelId1, + }); + } + const { afterEvent, createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -101,12 +93,12 @@ QUnit.test('message list desc order', async function (assert) { await afterEvent({ eventName: 'o-thread-view-hint-processed', func: () => createThreadViewComponent(threadViewer.threadView, undefined, { isFixedSize: true }), - message: "should wait until channel 100 loaded initial messages", + message: "should wait until channel 1 loaded initial messages", predicate: ({ hint, threadViewer }) => { return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 100 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -132,12 +124,12 @@ QUnit.test('message list desc order', async function (assert) { const messageList = document.querySelector('.o_ThreadView_messageList'); messageList.scrollTop = messageList.scrollHeight - messageList.clientHeight; }, - message: "should wait until channel 100 loaded more messages after scrolling to bottom", + message: "should wait until channel 1 loaded more messages after scrolling to bottom", predicate: ({ hint, threadViewer }) => { return ( hint.type === 'more-messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 100 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -160,35 +152,33 @@ QUnit.test('message list desc order', async function (assert) { QUnit.test('message list asc order', async function (assert) { assert.expect(5); - for (let i = 0; i <= 60; i++) { - this.data['mail.message'].records.push({ - body: "not empty", - model: 'mail.channel', - res_id: 100, - }); - } - this.data['res.partner'].records.push( + const pyEnv = await startServer(); + const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([ { email: "john@example.com", - id: 9, name: "John", }, { email: "fred@example.com", - id: 10, name: "Fred", }, - ); - this.data['mail.channel'].records.push({ + ]); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 100, - channel_partner_ids: [this.data.currentPartnerId, 9, 10], + channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1, resPartnerId2], name: "General", public: 'public', }); - const { afterEvent, createThreadViewComponent, messaging } = await start({ data: this.data }); + for (let i = 0; i <= 60; i++) { + pyEnv['mail.message'].create({ + body: "not empty", + model: 'mail.channel', + res_id: mailChannelId1, + }); + } + const { afterEvent, createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -199,12 +189,12 @@ QUnit.test('message list asc order', async function (assert) { await afterEvent({ eventName: 'o-thread-view-hint-processed', func: () => createThreadViewComponent(threadViewer.threadView, undefined, { isFixedSize: true }), - message: "should wait until channel 100 loaded initial messages", + message: "should wait until channel 1 loaded initial messages", predicate: ({ hint, threadViewer }) => { return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 100 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -227,12 +217,12 @@ QUnit.test('message list asc order', async function (assert) { await afterEvent({ eventName: 'o-thread-view-hint-processed', func: () => document.querySelector(`.o_ThreadView_messageList`).scrollTop = 0, - message: "should wait until channel 100 loaded more messages after scrolling to top", + message: "should wait until channel 1 loaded more messages after scrolling to top", predicate: ({ hint, threadViewer }) => { return ( hint.type === 'more-messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 100 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -257,20 +247,18 @@ QUnit.test('message list asc order', async function (assert) { QUnit.test('mark channel as fetched when a new message is loaded and as seen when focusing composer [REQUIRE FOCUS]', async function (assert) { assert.expect(7); - this.data['res.partner'].records.push({ + const pyEnv = await startServer(); + const resPartnerId1 = pyEnv['res.partner'].create({ email: "fred@example.com", - id: 10, name: "Fred", }); - this.data['res.users'].records.push({ - id: 10, - partner_id: 10, + const resUsersId1 = pyEnv['res.users'].create({ + partner_id: resPartnerId1, }); - this.data['mail.channel'].records.push({ + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'chat', - id: 100, is_pinned: true, - channel_partner_ids: [this.data.currentPartnerId, 10], + channel_partner_ids: [pyEnv.currentPartnerId, resPartnerId1], }); const { afterEvent, createThreadViewComponent, env, messaging } = await start({ data: this.data, @@ -278,7 +266,7 @@ QUnit.test('mark channel as fetched when a new message is loaded and as seen whe if (args.method === 'channel_fetched') { assert.strictEqual( args.args[0][0], - 100, + mailChannelId1, 'channel_fetched is called on the right channel id' ); assert.strictEqual( @@ -290,7 +278,7 @@ QUnit.test('mark channel as fetched when a new message is loaded and as seen whe } else if (route === '/mail/channel/set_last_seen_message') { assert.strictEqual( args.channel_id, - 100, + mailChannelId1, 'set_last_seen_message is called on the right channel id' ); assert.step('rpc:set_last_seen_message'); @@ -299,7 +287,7 @@ QUnit.test('mark channel as fetched when a new message is loaded and as seen whe } }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -312,7 +300,7 @@ QUnit.test('mark channel as fetched when a new message is loaded and as seen whe route: '/mail/chat_post', params: { context: { - mockedUserId: 10, + mockedUserId: resUsersId1, }, message_content: "new message", uuid: thread.uuid, @@ -329,7 +317,7 @@ QUnit.test('mark channel as fetched when a new message is loaded and as seen whe message: "should wait until last seen by current partner message id changed after focusing the thread", predicate: ({ thread }) => { return ( - thread.id === 100 && + thread.id === mailChannelId1 && thread.model === 'mail.channel' ); }, @@ -343,25 +331,21 @@ QUnit.test('mark channel as fetched when a new message is loaded and as seen whe QUnit.test('mark channel as fetched and seen when a new message is loaded if composer is focused [REQUIRE FOCUS]', async function (assert) { assert.expect(3); - this.data['res.partner'].records.push({ - id: 10, - }); - this.data['res.users'].records.push({ - id: 10, - partner_id: 10, - }); - this.data['mail.channel'].records.push({ - id: 100, + const pyEnv = await startServer(); + const resPartnerId1 = pyEnv['res.partner'].create({}); + const resUsersId1 = pyEnv['res.users'].create({ + partner_id: resPartnerId1, }); + const mailChannelId1 = pyEnv['mail.channel'].create({}); const { afterEvent, createThreadViewComponent, env, messaging } = await start({ data: this.data, mockRPC(route, args) { - if (args.method === 'channel_fetched' && args.args[0] === 100) { + if (args.method === 'channel_fetched' && args.args[0] === mailChannelId1) { throw new Error("'channel_fetched' RPC must not be called for created channel as message is directly seen"); } else if (route === '/mail/channel/set_last_seen_message') { assert.strictEqual( args.channel_id, - 100, + mailChannelId1, 'set_last_seen_message is called on the right channel id' ); assert.step('rpc:set_last_seen_message'); @@ -370,7 +354,7 @@ QUnit.test('mark channel as fetched and seen when a new message is loaded if com } }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -387,7 +371,7 @@ QUnit.test('mark channel as fetched and seen when a new message is loaded if com route: '/mail/chat_post', params: { context: { - mockedUserId: 10, + mockedUserId: resUsersId1, }, message_content: "

fdsfsd

", uuid: thread.uuid, @@ -396,7 +380,7 @@ QUnit.test('mark channel as fetched and seen when a new message is loaded if com message: "should wait until last seen by current partner message id changed after receiving a message while thread is focused", predicate: ({ thread }) => { return ( - thread.id === 100 && + thread.id === mailChannelId1 && thread.model === 'mail.channel' ); }, @@ -410,21 +394,21 @@ QUnit.test('mark channel as fetched and seen when a new message is loaded if com QUnit.test('show message subject when subject is not the same as the thread name', async function (assert) { assert.expect(3); - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 100, name: "General", public: 'public', }); - this.data['mail.message'].records.push({ + pyEnv['mail.message'].create({ body: "not empty", model: 'mail.channel', - res_id: 100, + res_id: mailChannelId1, subject: "Salutations, voyageur", }); - const { createThreadViewComponent, messaging } = await start({ data: this.data }); + const { createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -454,21 +438,21 @@ QUnit.test('show message subject when subject is not the same as the thread name QUnit.test('do not show message subject when subject is the same as the thread name', async function (assert) { assert.expect(1); - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 100, name: "Salutations, voyageur", public: 'public', }); - this.data['mail.message'].records.push({ + pyEnv['mail.message'].create({ body: "not empty", model: 'mail.channel', - res_id: 100, + res_id: mailChannelId1, subject: "Salutations, voyageur", }); - const { createThreadViewComponent, messaging } = await start({ data: this.data }); + const { createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 100, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -489,23 +473,22 @@ QUnit.test('[technical] new messages separator on posting message', async functi // technical as we need to remove focus from text input to avoid `set_last_seen_message` call assert.expect(4); - this.data['mail.channel'].records = [{ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, message_unread_counter: 0, - seen_message_id: 10, name: "General", - }]; - this.data['mail.message'].records.push({ - body: "first message", - id: 10, - model: "mail.channel", - res_id: 20, }); - const { createThreadViewComponent, messaging } = await start({ data: this.data }); + const mailMessageId1 = pyEnv['mail.message'].create({ + body: "first message", + model: "mail.channel", + res_id: mailChannelId1, + }); + pyEnv['mail.channel'].write([mailChannelId1], { seen_message_id: mailMessageId1 }); + const { createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -550,33 +533,30 @@ QUnit.test('[technical] new messages separator on posting message', async functi QUnit.test('new messages separator on receiving new message [REQUIRE FOCUS]', async function (assert) { assert.expect(6); - this.data['res.partner'].records.push({ - id: 11, + const pyEnv = await startServer(); + const resPartnerId1 = pyEnv['res.partner'].create({ name: "Foreigner partner", }); - this.data['res.users'].records.push({ - id: 42, + const resUsersId1 = pyEnv['res.users'].create({ name: "Foreigner user", - partner_id: 11, + partner_id: resPartnerId1, }); - this.data['mail.channel'].records.push({ + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, message_unread_counter: 0, name: "General", - seen_message_id: 1, uuid: 'randomuuid', }); - this.data['mail.message'].records.push({ + const mailMessageId1 = pyEnv['mail.message'].create({ body: "blah", - id: 1, model: "mail.channel", - res_id: 20, + res_id: mailChannelId1, }); - const { afterEvent, createThreadViewComponent, env, messaging } = await start({ data: this.data }); + pyEnv['mail.channel'].write([mailChannelId1], { seen_message_id: mailMessageId1 }); + const { afterEvent, createThreadViewComponent, env, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -605,7 +585,7 @@ QUnit.test('new messages separator on receiving new message [REQUIRE FOCUS]', as route: '/mail/chat_post', params: { context: { - mockedUserId: 42, + mockedUserId: resUsersId1, }, message_content: "hu", uuid: thread.uuid, @@ -614,7 +594,7 @@ QUnit.test('new messages separator on receiving new message [REQUIRE FOCUS]', as message: "should wait until new message is received", predicate: ({ hint, threadViewer }) => { return ( - threadViewer.thread.id === 20 && + threadViewer.thread.id === mailChannelId1 && threadViewer.thread.model === 'mail.channel' && hint.type === 'message-received' ); @@ -635,7 +615,7 @@ QUnit.test('new messages separator on receiving new message [REQUIRE FOCUS]', as assert.containsOnce( document.body, `.o_MessageList_separatorNewMessages ~ .o_Message[data-message-local-id="${ - messaging.models['Message'].findFromIdentifyingData({ id: 2 }).localId + messaging.models['Message'].findFromIdentifyingData({ id: mailMessageId1 + 1 }).localId }"]`, "'new messages' separator should be shown above new message received" ); @@ -646,7 +626,7 @@ QUnit.test('new messages separator on receiving new message [REQUIRE FOCUS]', as message: "should wait until last seen by current partner message id changed after focusing the thread", predicate: ({ thread }) => { return ( - thread.id === 20 && + thread.id === mailChannelId1 && thread.model === 'mail.channel' ); }, @@ -661,16 +641,16 @@ QUnit.test('new messages separator on receiving new message [REQUIRE FOCUS]', as QUnit.test('new messages separator on posting message', async function (assert) { assert.expect(4); - this.data['mail.channel'].records = [{ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, message_unread_counter: 0, name: "General", - }]; - const { click, createThreadViewComponent, messaging } = await start({ data: this.data }); + }); + const { click, createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -709,30 +689,28 @@ QUnit.test('new messages separator on posting message', async function (assert) QUnit.test('basic rendering of canceled notification', async function (assert) { assert.expect(8); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['res.partner'].records.push({ id: 12, name: "Someone" }); - this.data['mail.message'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + const resPartnerId1 = pyEnv['res.partner'].create({ name: "Someone" }); + const mailMessageId1 = pyEnv['mail.message'].create({ body: "not empty", - id: 10, message_type: 'email', model: 'mail.channel', - notification_ids: [11], - res_id: 11, + res_id: mailChannelId1, }); - this.data['mail.notification'].records.push({ + pyEnv['mail.notification'].create({ failure_type: 'SMTP', - id: 11, - mail_message_id: 10, + mail_message_id: mailMessageId1, notification_status: 'canceled', notification_type: 'email', - res_partner_id: 12, + res_partner_id: resPartnerId1, }); - const { afterEvent, click, createThreadViewComponent, messaging } = await start({ data: this.data }); + const { afterEvent, click, createThreadViewComponent, messaging } = await start(); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), thread: insert({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }), }); @@ -746,7 +724,7 @@ QUnit.test('basic rendering of canceled notification', async function (assert) { return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -798,27 +776,26 @@ QUnit.test('basic rendering of canceled notification', async function (assert) { QUnit.test('should scroll to bottom on receiving new message if the list is initially scrolled to bottom (asc order)', async function (assert) { assert.expect(2); + 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", }); - this.data['res.users'].records.push({ - id: 42, + const resUsersId1 = pyEnv['res.users'].create({ name: "Foreigner user", - partner_id: 11, + partner_id: resPartnerId1, }); - this.data['mail.channel'].records.push({ id: 20 }); + const mailChannelId1 = pyEnv['mail.channel'].create({}); for (let i = 0; i <= 10; i++) { - this.data['mail.message'].records.push({ + pyEnv['mail.message'].create({ body: "not empty", model: "mail.channel", - res_id: 20, + res_id: mailChannelId1, }); } - const { afterEvent, createThreadViewComponent, env, messaging } = await start({ data: this.data }); + const { afterEvent, createThreadViewComponent, env, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -851,7 +828,7 @@ QUnit.test('should scroll to bottom on receiving new message if the list is init route: '/mail/chat_post', params: { context: { - mockedUserId: 42, + mockedUserId: resUsersId1, }, message_content: "hello", uuid: thread.uuid, @@ -871,27 +848,26 @@ QUnit.test('should scroll to bottom on receiving new message if the list is init QUnit.test('should not scroll on receiving new message if the list is initially scrolled anywhere else than bottom (asc order)', async function (assert) { assert.expect(3); + 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", }); - this.data['res.users'].records.push({ - id: 42, + const resUsersId1 = pyEnv['res.users'].create({ name: "Foreigner user", - partner_id: 11, + partner_id: resPartnerId1, }); - this.data['mail.channel'].records.push({ id: 20 }); + const mailChannelId1 = pyEnv['mail.channel'].create({}); for (let i = 0; i <= 10; i++) { - this.data['mail.message'].records.push({ + pyEnv['mail.message'].create({ body: "not empty", model: "mail.channel", - res_id: 20, + res_id: mailChannelId1, }); } - const { afterEvent, createThreadViewComponent, env, messaging } = await start({ data: this.data }); + const { afterEvent, createThreadViewComponent, env, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -906,26 +882,26 @@ QUnit.test('should not scroll on receiving new message if the list is initially undefined, { isFixedSize: true }, ), - message: "should wait until channel 20 scrolled initially", + message: "should wait until channel 1 scrolled initially", predicate: data => threadViewer === data.threadViewer, }); const initialMessageList = document.querySelector('.o_ThreadView_messageList'); assert.strictEqual( initialMessageList.scrollTop, initialMessageList.scrollHeight - initialMessageList.clientHeight, - "should have scrolled to bottom of channel 20 initially" + "should have scrolled to bottom of channel 1 initially" ); await afterEvent({ eventName: 'o-component-message-list-scrolled', func: () => initialMessageList.scrollTop = 0, - message: "should wait until channel 20 processed manual scroll", + message: "should wait until channel 1 processed manual scroll", predicate: data => threadViewer === data.threadViewer, }); assert.strictEqual( initialMessageList.scrollTop, 0, - "should have scrolled to the top of channel 20 manually" + "should have scrolled to the top of channel 1 manually" ); // simulate receiving a message @@ -936,7 +912,7 @@ QUnit.test('should not scroll on receiving new message if the list is initially route: '/mail/chat_post', params: { context: { - mockedUserId: 42, + mockedUserId: resUsersId1, }, message_content: "hello", uuid: thread.uuid, @@ -955,25 +931,24 @@ QUnit.test('should not scroll on receiving new message if the list is initially QUnit.test("delete all attachments of message without content should no longer display the message", async function (assert) { assert.expect(2); - this.data['ir.attachment'].records.push({ - id: 143, + const pyEnv = await startServer(); + const irAttachmentId1 = pyEnv['ir.attachment'].create({ mimetype: 'text/plain', name: "Blah.txt", }); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['mail.message'].records.push( + const mailChannelId1 = pyEnv['mail.channel'].create({}); + pyEnv['mail.message'].create( { - attachment_ids: [143], - id: 101, + attachment_ids: [irAttachmentId1], model: "mail.channel", - res_id: 11, + res_id: mailChannelId1, } ); - const { afterEvent, click, createThreadViewComponent, messaging } = await start({ data: this.data, hasDialog: true }); + const { afterEvent, click, createThreadViewComponent, messaging } = await start({ hasDialog: true }); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), - thread: insert({ id: 11, model: 'mail.channel' }), + thread: insert({ id: mailChannelId1, model: 'mail.channel' }), }); // wait for messages of the thread to be loaded await afterEvent({ @@ -986,7 +961,7 @@ QUnit.test("delete all attachments of message without content should no longer d return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -997,7 +972,7 @@ QUnit.test("delete all attachments of message without content should no longer d ); await click(`.o_AttachmentCard[data-id="${ - messaging.models['Attachment'].findFromIdentifyingData({ id: 143 }).localId + messaging.models['Attachment'].findFromIdentifyingData({ id: irAttachmentId1 }).localId }"] .o_AttachmentCard_asideItemUnlink`); await click('.o_AttachmentDeleteConfirm_confirmButton'); assert.containsNone( @@ -1010,26 +985,23 @@ QUnit.test("delete all attachments of message without content should no longer d QUnit.test('delete all attachments of a message with some text content should still keep it displayed', async function (assert) { assert.expect(2); - this.data['ir.attachment'].records.push({ - id: 143, + const pyEnv = await startServer(); + const irAttachmentId1 = pyEnv['ir.attachment'].create({ mimetype: 'text/plain', name: "Blah.txt", }); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['mail.message'].records.push( - { - attachment_ids: [143], - body: "Some content", - id: 101, - model: "mail.channel", - res_id: 11, - }, - ); - const { afterEvent, click, createThreadViewComponent, messaging } = await start({ data: this.data, hasDialog: true }); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + pyEnv['mail.message'].create({ + attachment_ids: [irAttachmentId1], + body: "Some content", + model: "mail.channel", + res_id: mailChannelId1, + }); + const { afterEvent, click, createThreadViewComponent, messaging } = await start({ hasDialog: true }); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), - thread: insert({ id: 11, model: 'mail.channel' }), + thread: insert({ id: mailChannelId1, model: 'mail.channel' }), }); // wait for messages of the thread to be loaded await afterEvent({ @@ -1042,7 +1014,7 @@ QUnit.test('delete all attachments of a message with some text content should st return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -1053,7 +1025,7 @@ QUnit.test('delete all attachments of a message with some text content should st ); await click(`.o_AttachmentCard[data-id="${ - messaging.models['Attachment'].findFromIdentifyingData({ id: 143 }).localId + messaging.models['Attachment'].findFromIdentifyingData({ id: irAttachmentId1 }).localId }"] .o_AttachmentCard_asideItemUnlink`); await click('.o_AttachmentDeleteConfirm_confirmButton'); assert.containsOnce( @@ -1066,15 +1038,15 @@ QUnit.test('delete all attachments of a message with some text content should st QUnit.test('Post a message containing an email address followed by a mention on another line', async function (assert) { assert.expect(1); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['res.partner'].records.push({ - id: 25, + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + const resPartnerId1 = pyEnv['res.partner'].create({ email: "testpartner@odoo.com", name: "TestPartner", }); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1089,7 +1061,7 @@ QUnit.test('Post a message containing an email address followed by a mention on await click('.o_Composer_buttonSend'); assert.containsOnce( document.querySelector(`.o_Message_content`), - `.o_mail_redirect[data-oe-id="25"][data-oe-model="res.partner"]:contains("@TestPartner")`, + `.o_mail_redirect[data-oe-id="${resPartnerId1}"][data-oe-model="res.partner"]:contains("@TestPartner")`, "Conversation should have a message that has been posted, which contains partner mention" ); }); @@ -1097,15 +1069,15 @@ QUnit.test('Post a message containing an email address followed by a mention on QUnit.test(`Mention a partner with special character (e.g. apostrophe ')`, async function (assert) { assert.expect(1); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['res.partner'].records.push({ - id: 1952, + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + const resPartnerId1 = pyEnv['res.partner'].create({ email: "usatyi@example.com", name: "Pynya's spokesman", }); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1119,7 +1091,7 @@ QUnit.test(`Mention a partner with special character (e.g. apostrophe ')`, async await click('.o_Composer_buttonSend'); assert.containsOnce( document.querySelector(`.o_Message_content`), - `.o_mail_redirect[data-oe-id="1952"][data-oe-model="res.partner"]:contains("@Pynya's spokesman")`, + `.o_mail_redirect[data-oe-id="${resPartnerId1}"][data-oe-model="res.partner"]:contains("@Pynya's spokesman")`, "Conversation should have a message that has been posted, which contains partner mention" ); }); @@ -1127,21 +1099,21 @@ QUnit.test(`Mention a partner with special character (e.g. apostrophe ')`, async QUnit.test('mention 2 different partners that have the same name', async function (assert) { assert.expect(3); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['res.partner'].records.push( + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create(); + const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([ { - id: 25, email: "partner1@example.com", name: "TestPartner", - }, { - id: 26, + }, + { email: "partner2@example.com", name: "TestPartner", }, - ); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + ]); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1158,12 +1130,12 @@ QUnit.test('mention 2 different partners that have the same name', async functio assert.containsOnce(document.body, '.o_Message_content', 'should have one message after posting it'); assert.containsOnce( document.querySelector(`.o_Message_content`), - `.o_mail_redirect[data-oe-id="25"][data-oe-model="res.partner"]:contains("@TestPartner")`, + `.o_mail_redirect[data-oe-id="${resPartnerId1}"][data-oe-model="res.partner"]:contains("@TestPartner")`, "message should contain the first partner mention" ); assert.containsOnce( document.querySelector(`.o_Message_content`), - `.o_mail_redirect[data-oe-id="26"][data-oe-model="res.partner"]:contains("@TestPartner")`, + `.o_mail_redirect[data-oe-id="${resPartnerId2}"][data-oe-model="res.partner"]:contains("@TestPartner")`, "message should also contain the second partner mention" ); }); @@ -1171,13 +1143,13 @@ QUnit.test('mention 2 different partners that have the same name', async functio QUnit.test('mention a channel with space in the name', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ - id: 7, + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ name: "General good boy", }); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 7, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1205,13 +1177,13 @@ QUnit.test('mention a channel with space in the name', async function (assert) { QUnit.test('mention a channel with "&" in the name', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ - id: 7, + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ name: "General & good", }); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 7, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1239,13 +1211,13 @@ QUnit.test('mention a channel with "&" in the name', async function (assert) { QUnit.test('mention a channel on a second line when the first line contains #', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ - id: 7, + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ name: "General good", }); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 7, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1274,13 +1246,13 @@ QUnit.test('mention a channel on a second line when the first line contains #', QUnit.test('mention a channel when replacing the space after the mention by another char', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ - id: 7, + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ name: "General good", }); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 7, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1311,20 +1283,19 @@ QUnit.test('mention a channel when replacing the space after the mention by anot QUnit.test('mention 2 different channels that have the same name', async function (assert) { assert.expect(3); - this.data['mail.channel'].records.push( + const pyEnv = await startServer(); + const [mailChannelId1, mailChannelId2] = pyEnv['mail.channel'].create([ { - id: 11, name: "my channel", public: 'public', // mentioning another channel is possible only from a public channel }, { - id: 12, name: "my channel", }, - ); - const { click, createThreadViewComponent, insertText, messaging } = await start({ data: this.data }); + ]); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1342,12 +1313,12 @@ QUnit.test('mention 2 different channels that have the same name', async functio assert.containsOnce(document.body, '.o_Message_content', 'should have one message after posting it'); assert.containsOnce( document.querySelector(`.o_Message_content`), - `.o_channel_redirect[data-oe-id="11"][data-oe-model="mail.channel"]:contains("#my channel")`, + `.o_channel_redirect[data-oe-id="${mailChannelId1}"][data-oe-model="mail.channel"]:contains("#my channel")`, "message should contain the first channel mention" ); assert.containsOnce( document.querySelector(`.o_Message_content`), - `.o_channel_redirect[data-oe-id="12"][data-oe-model="mail.channel"]:contains("#my channel")`, + `.o_channel_redirect[data-oe-id="${mailChannelId2}"][data-oe-model="mail.channel"]:contains("#my channel")`, "message should also contain the second channel mention" ); }); @@ -1355,13 +1326,14 @@ QUnit.test('mention 2 different channels that have the same name', async functio QUnit.test('show empty placeholder when thread contains no message', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ id: 11 }); - const { afterEvent, createThreadViewComponent, messaging } = await start({ data: this.data }); + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + const { afterEvent, createThreadViewComponent, messaging } = await start(); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), thread: insert({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }), }); @@ -1375,7 +1347,7 @@ QUnit.test('show empty placeholder when thread contains no message', async funct return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -1394,20 +1366,18 @@ QUnit.test('show empty placeholder when thread contains no message', async funct QUnit.test('show empty placeholder when thread contains only empty messages', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['mail.message'].records.push( - { - id: 101, - model: "mail.channel", - res_id: 11, - }, - ); - const { afterEvent, createThreadViewComponent, messaging } = await start({ data: this.data }); + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + pyEnv['mail.message'].create({ + model: "mail.channel", + res_id: mailChannelId1, + }); + const { afterEvent, createThreadViewComponent, messaging } = await start(); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), thread: insert({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }), }); @@ -1421,7 +1391,7 @@ QUnit.test('show empty placeholder when thread contains only empty messages', as return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -1440,25 +1410,22 @@ QUnit.test('show empty placeholder when thread contains only empty messages', as QUnit.test('message with subtype should be displayed (and not considered as empty)', async function (assert) { assert.expect(2); - this.data['mail.channel'].records.push({ id: 11 }); - this.data['mail.message.subtype'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + const mailMessageSubtypeId1 = pyEnv['mail.message.subtype'].create({ description: "Task created", - id: 10, }); - this.data['mail.message'].records.push( - { - id: 101, - model: "mail.channel", - res_id: 11, - subtype_id: 10, - }, - ); - const { afterEvent, createThreadViewComponent, messaging } = await start({ data: this.data }); + pyEnv['mail.message'].create({ + model: "mail.channel", + res_id: mailChannelId1, + subtype_id: mailMessageSubtypeId1, + }); + const { afterEvent, createThreadViewComponent, messaging } = await start(); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), thread: insert({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }), }); @@ -1472,7 +1439,7 @@ QUnit.test('message with subtype should be displayed (and not considered as empt return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -1495,28 +1462,27 @@ QUnit.test('[technical] message list with a full page of empty messages should s // - auto-load more being triggered on scroll, not automatically when the 30 first messages are empty assert.expect(2); - this.data['mail.channel'].records.push({ - id: 11, - }); + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); for (let i = 0; i <= 30; i++) { - this.data['mail.message'].records.push({ + pyEnv['mail.message'].create({ body: "not empty", model: "mail.channel", - res_id: 11, + res_id: mailChannelId1, }); } for (let i = 0; i <= 30; i++) { - this.data['mail.message'].records.push({ + pyEnv['mail.message'].create({ model: "mail.channel", - res_id: 11, + res_id: mailChannelId1, }); } - const { afterEvent, createThreadViewComponent, messaging } = await start({ data: this.data }); + const { afterEvent, createThreadViewComponent, messaging } = await start(); const threadViewer = messaging.models['ThreadViewer'].create({ hasThreadView: true, qunitTest: insertAndReplace(), thread: insert({ - id: 11, + id: mailChannelId1, model: 'mail.channel', }), }); @@ -1530,7 +1496,7 @@ QUnit.test('[technical] message list with a full page of empty messages should s return ( hint.type === 'messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 11 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -1553,26 +1519,24 @@ QUnit.test('first unseen message should be directly preceded by the new message // and the conditions from focus would otherwise shadow them. assert.expect(3); + 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", }); - this.data['res.users'].records.push({ - id: 42, + const resUsersId1 = pyEnv['res.users'].create({ name: "Foreigner user", - partner_id: 11, + partner_id: resPartnerId1, }); - this.data['mail.channel'].records = [{ + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", uuid: 'channel20uuid', - }]; - const { click, createThreadViewComponent, env, messaging } = await start({ data: this.data }); + }); + const { click, createThreadViewComponent, env, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1593,7 +1557,7 @@ QUnit.test('first unseen message should be directly preceded by the new message route: '/mail/chat_post', params: { context: { - mockedUserId: 42, + mockedUserId: resUsersId1, }, message_content: "test", uuid: 'channel20uuid', @@ -1622,10 +1586,11 @@ QUnit.test('first unseen message should be directly preceded by the new message QUnit.test('composer should be focused automatically after clicking on the send button [REQUIRE FOCUS]', async function (assert) { assert.expect(1); - this.data['mail.channel'].records.push({ id: 20 }); - const { click, createThreadViewComponent, messaging } = await start({ data: this.data }); + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({}); + const { click, createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1647,14 +1612,13 @@ QUnit.test('composer should be focused automatically after clicking on the send QUnit.test('failure on loading messages should display error', async function (assert) { assert.expect(1); - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); const { createThreadViewComponent, messaging } = await start({ - data: this.data, async mockRPC(route, args) { if (route === '/mail/channel/messages') { throw new Error(); @@ -1663,7 +1627,7 @@ QUnit.test('failure on loading messages should display error', async function (a }, }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1683,14 +1647,13 @@ QUnit.test('failure on loading messages should display error', async function (a QUnit.test('failure on loading messages should prompt retry button', async function (assert) { assert.expect(1); - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); const { createThreadViewComponent, messaging } = await start({ - data: this.data, async mockRPC(route, args) { if (route === '/mail/channel/messages') { throw new Error(); @@ -1699,7 +1662,7 @@ QUnit.test('failure on loading messages should prompt retry button', async funct }, }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1723,22 +1686,20 @@ QUnit.test('failure on loading more messages should not alter message list displ // second call comes from load more and needs to fail in order to show the error alert // any later call should work so that retry button and load more clicks would now work let messageFetchShouldFail = false; - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); - this.data['mail.message'].records.push(...[...Array(60).keys()].map(id => { + pyEnv['mail.message'].create([...Array(60).keys()].map(() => { return { body: 'coucou', - id, model: "mail.channel", - res_id: 20, + res_id: mailChannelId1, }; })); const { click, createThreadViewComponent, messaging } = await start({ - data: this.data, async mockRPC(route, args) { if (route === '/mail/channel/messages') { if (messageFetchShouldFail) { @@ -1749,7 +1710,7 @@ QUnit.test('failure on loading more messages should not alter message list displ }, }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1776,22 +1737,20 @@ QUnit.test('failure on loading more messages should display error and prompt ret // second call comes from load more and needs to fail in order to show the error alert // any later call should work so that retry button and load more clicks would now work let messageFetchShouldFail = false; - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); - this.data['mail.message'].records.push(...[...Array(60).keys()].map(id => { + pyEnv['mail.message'].create([...Array(60).keys()].map(() => { return { body: 'coucou', - id, model: "mail.channel", - res_id: 20, + res_id: mailChannelId1, }; })); const { click, createThreadViewComponent, messaging } = await start({ - data: this.data, async mockRPC(route, args) { if (route === '/mail/channel/messages') { if (messageFetchShouldFail) { @@ -1802,7 +1761,7 @@ QUnit.test('failure on loading more messages should display error and prompt ret }, }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1838,22 +1797,20 @@ QUnit.test('Retry loading more messages on failed load more messages should load // second call comes from load more and needs to fail in order to show the error alert // any later call should work so that retry button and load more clicks would now work let messageFetchShouldFail = false; - this.data['mail.channel'].records.push({ + const pyEnv = await startServer(); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); - this.data['mail.message'].records = [...Array(90).keys()].map(id => { + pyEnv['mail.message'].create([...Array(90).keys()].map(() => { return { body: 'coucou', - id, model: "mail.channel", - res_id: 20, + res_id: mailChannelId1, }; - }); + })); const { afterEvent, click, createThreadViewComponent, messaging } = await start({ - data: this.data, async mockRPC(route, args) { if (route === '/mail/channel/messages') { if (messageFetchShouldFail) { @@ -1864,7 +1821,7 @@ QUnit.test('Retry loading more messages on failed load more messages should load }, }); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1885,7 +1842,7 @@ QUnit.test('Retry loading more messages on failed load more messages should load return ( hint.type === 'more-messages-loaded' && threadViewer.thread.model === 'mail.channel' && - threadViewer.thread.id === 20 + threadViewer.thread.id === mailChannelId1 ); }, }); @@ -1894,28 +1851,26 @@ QUnit.test('Retry loading more messages on failed load more messages should load QUnit.test("highlight the message mentioning the current user inside the channel", async function (assert) { assert.expect(1); - this.data['res.partner'].records.push({ + const pyEnv = await startServer(); + const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "Test Partner", - id: 7, }); - this.data['res.users'].records.push({ partner_id: 7 }); - this.data['mail.channel'].records.push({ + pyEnv['res.users'].create({ partner_id: resPartnerId1 }); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); - this.data['mail.message'].records.push({ - author_id: 7, + pyEnv['mail.message'].create({ + author_id: resPartnerId1, body: "hello @Admin", - id: 100, model: 'mail.channel', - partner_ids: [this.data.currentPartnerId], - res_id: 20, + partner_ids: [pyEnv.currentPartnerId], + res_id: mailChannelId1, }); - const { createThreadViewComponent, messaging } = await start({ data: this.data }); + const { createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ @@ -1934,29 +1889,27 @@ QUnit.test("highlight the message mentioning the current user inside the channel QUnit.test("not highlighting the message if not mentioning the current user inside the channel", async function (assert) { assert.expect(1); - this.data['res.partner'].records.push({ + const pyEnv = await startServer(); + const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "testPartner", email: "testPartner@odoo.com", - id: 7, }); - this.data['res.users'].records.push({ partner_id: 7 }); - this.data['mail.channel'].records.push({ + pyEnv['res.users'].create({ partner_id: resPartnerId1 }); + const mailChannelId1 = pyEnv['mail.channel'].create({ channel_type: 'channel', - id: 20, is_pinned: true, name: "General", }); - this.data['mail.message'].records.push({ - author_id: this.data.currentPartnerId, + pyEnv['mail.message'].create({ + author_id: pyEnv.currentPartnerId, body: "hello @testPartner", - id: 100, model: 'mail.channel', - partner_ids: [7], - res_id: 20, + partner_ids: [resPartnerId1], + res_id: mailChannelId1, }); - const { createThreadViewComponent, messaging } = await start({ data: this.data }); + const { createThreadViewComponent, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: 20, + id: mailChannelId1, model: 'mail.channel' }); const threadViewer = messaging.models['ThreadViewer'].create({ diff --git a/addons/mail/static/tests/qunit_suite_tests/models/thread_tests.js b/addons/mail/static/tests/qunit_suite_tests/models/thread_tests.js index b0464105b76..e9447aa92a2 100644 --- a/addons/mail/static/tests/qunit_suite_tests/models/thread_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/models/thread_tests.js @@ -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, diff --git a/addons/mail/static/tests/qunit_suite_tests/utils/throttle_tests.js b/addons/mail/static/tests/qunit_suite_tests/utils/throttle_tests.js index eeb935a44ec..51dc2cb3277 100644 --- a/addons/mail/static/tests/qunit_suite_tests/utils/throttle_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/utils/throttle_tests.js @@ -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, }); diff --git a/addons/note/static/tests/systray_activity_menu_tests.js b/addons/note/static/tests/systray_activity_menu_tests.js index 7514978528d..13b544583d5 100644 --- a/addons/note/static/tests/systray_activity_menu_tests.js +++ b/addons/note/static/tests/systray_activity_menu_tests.js @@ -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')); diff --git a/addons/sms/static/tests/qunit_suite_tests/components/message_tests.js b/addons/sms/static/tests/qunit_suite_tests/components/message_tests.js index 8a51f61b025..868c53a5e29 100644 --- a/addons/sms/static/tests/qunit_suite_tests/components/message_tests.js +++ b/addons/sms/static/tests/qunit_suite_tests/components/message_tests.js @@ -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', }), }); diff --git a/addons/sms/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js b/addons/sms/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js index ba11e68cc76..66d5fb16e08 100644 --- a/addons/sms/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js +++ b/addons/sms/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js @@ -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( diff --git a/addons/snailmail/static/tests/qunit_suite_tests/components/message_tests.js b/addons/snailmail/static/tests/qunit_suite_tests/components/message_tests.js index f3d97f109dc..c9eb10709ef 100644 --- a/addons/snailmail/static/tests/qunit_suite_tests/components/message_tests.js +++ b/addons/snailmail/static/tests/qunit_suite_tests/components/message_tests.js @@ -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); diff --git a/addons/snailmail/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js b/addons/snailmail/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js index 8187d1d4f17..eefae4f1cd8 100644 --- a/addons/snailmail/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js +++ b/addons/snailmail/static/tests/qunit_suite_tests/components/notification_list_notification_group_tests.js @@ -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( diff --git a/addons/test_mail/static/tests/tracking_value_tests.js b/addons/test_mail/static/tests/tracking_value_tests.js index d27fdb4169e..acae04e2dd6 100644 --- a/addons/test_mail/static/tests/tracking_value_tests.js +++ b/addons/test_mail/static/tests/tracking_value_tests.js @@ -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: `
@@ -33,7 +31,6 @@ QUnit.module('tracking_value_tests.js', {
`, archs: { 'mail.message,false,list': '' }, - 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'); diff --git a/addons/website_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js b/addons/website_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js index 391bf9ecb5a..ff5de662d9c 100644 --- a/addons/website_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js +++ b/addons/website_livechat/static/tests/qunit_suite_tests/components/discuss_tests.js @@ -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, diff --git a/addons/website_livechat/static/tests/qunit_suite_tests/messaging_notification_handler_tests.js b/addons/website_livechat/static/tests/qunit_suite_tests/messaging_notification_handler_tests.js index 5b9f12c28f3..46560cda09e 100644 --- a/addons/website_livechat/static/tests/qunit_suite_tests/messaging_notification_handler_tests.js +++ b/addons/website_livechat/static/tests/qunit_suite_tests/messaging_notification_handler_tests.js @@ -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 `, - res_id: 11, + res_id: websiteVisitorId1, }); mock.intercept(widget, 'execute_action', payload => { env.services.rpc({ diff --git a/addons/website_slides/static/tests/qunit_suite_tests/components/activity_tests.js b/addons/website_slides/static/tests/qunit_suite_tests/components/activity_tests.js index 794a6370c26..9f168f9114b 100644 --- a/addons/website_slides/static/tests/qunit_suite_tests/components/activity_tests.js +++ b/addons/website_slides/static/tests/qunit_suite_tests/components/activity_tests.js @@ -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', });