diff --git a/addons/mail/static/src/components/activity/tests/activity_tests.js b/addons/mail/static/src/components/activity/tests/activity_tests.js index 60b4f40f444..39fe49d3546 100644 --- a/addons/mail/static/src/components/activity/tests/activity_tests.js +++ b/addons/mail/static/src/components/activity/tests/activity_tests.js @@ -1,24 +1,10 @@ /** @odoo-module **/ -import { insert } from '@mail/model/model_field_command'; -import { - registerMessagingComponent, - unregisterMessagingComponent, -} from '@mail/utils/messaging_component'; -import { - afterEach, - afterNextRender, - beforeEach, - createRootMessagingComponent, - start, -} from '@mail/utils/test_utils'; +import { afterEach, afterNextRender, beforeEach, start } from '@mail/utils/test_utils'; -import { registerCleanup } from "@web/../tests/helpers/cleanup"; import Bus from 'web.Bus'; import { date_to_str } from 'web.time'; -const { Component, tags: { xml } } = owl; - QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { QUnit.module('activity', {}, function () { @@ -26,19 +12,13 @@ QUnit.module('activity_tests.js', { beforeEach() { beforeEach(this); - this.createActivityComponent = async function (activity) { - await createRootMessagingComponent(this, "Activity", { - props: { activityLocalId: activity.localId }, - target: this.widget.el, - }); - }; - this.start = async params => { - const { env, widget } = await start(Object.assign({}, params, { - data: this.data, - })); + const res = await start({ ...params, data: this.data }); + const { components, env, widget } = res; + this.components = components; this.env = env; this.widget = widget; + return res; }; }, afterEach() { @@ -49,12 +29,20 @@ QUnit.module('activity_tests.js', { QUnit.test('activity simplest layout', async function (assert) { assert.expect(12); - await this.start(); - const activity = this.messaging.models['Activity'].create({ - id: 12, - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -120,13 +108,21 @@ QUnit.test('activity simplest layout', async function (assert) { QUnit.test('activity with note layout', async function (assert) { assert.expect(3); - await this.start(); - const activity = this.messaging.models['Activity'].create({ + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ id: 12, note: 'There is no good or bad note', - thread: insert({ id: 42, model: 'res.partner' }), + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -147,17 +143,25 @@ QUnit.test('activity with note layout', async function (assert) { QUnit.test('activity info layout when planned after tomorrow', async function (assert) { assert.expect(4); - await this.start(); const today = new Date(); const fiveDaysFromNow = new Date(); fiveDaysFromNow.setDate(today.getDate() + 5); - const activity = this.messaging.models['Activity'].create({ - dateDeadline: date_to_str(fiveDaysFromNow), - id: 12, - state: 'planned', - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + date_deadline: date_to_str(fiveDaysFromNow), + id: 12, + res_id: 100, + res_model: 'res.partner', + state: 'planned', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -182,17 +186,25 @@ QUnit.test('activity info layout when planned after tomorrow', async function (a QUnit.test('activity info layout when planned tomorrow', async function (assert) { assert.expect(4); - await this.start(); const today = new Date(); const tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); - const activity = this.messaging.models['Activity'].create({ - dateDeadline: date_to_str(tomorrow), - id: 12, - state: 'planned', - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + date_deadline: date_to_str(tomorrow), + id: 12, + res_id: 100, + res_model: 'res.partner', + state: 'planned', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -217,15 +229,22 @@ QUnit.test('activity info layout when planned tomorrow', async function (assert) QUnit.test('activity info layout when planned today', async function (assert) { assert.expect(4); - await this.start(); - const today = new Date(); - const activity = this.messaging.models['Activity'].create({ - dateDeadline: date_to_str(today), - id: 12, - state: 'today', - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + date_deadline: date_to_str(new Date()), + id: 12, + res_id: 100, + res_model: 'res.partner', + state: 'today', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -250,17 +269,25 @@ QUnit.test('activity info layout when planned today', async function (assert) { QUnit.test('activity info layout when planned yesterday', async function (assert) { assert.expect(4); - await this.start(); const today = new Date(); const yesterday = new Date(); yesterday.setDate(today.getDate() - 1); - const activity = this.messaging.models['Activity'].create({ - dateDeadline: date_to_str(yesterday), - id: 12, - state: 'overdue', - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + date_deadline: date_to_str(yesterday), + id: 12, + res_id: 100, + res_model: 'res.partner', + state: 'overdue', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -285,17 +312,25 @@ QUnit.test('activity info layout when planned yesterday', async function (assert QUnit.test('activity info layout when planned before yesterday', async function (assert) { assert.expect(4); - await this.start(); const today = new Date(); const fiveDaysBeforeNow = new Date(); fiveDaysBeforeNow.setDate(today.getDate() - 5); - const activity = this.messaging.models['Activity'].create({ - dateDeadline: date_to_str(fiveDaysBeforeNow), - id: 12, - state: 'overdue', - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + date_deadline: date_to_str(fiveDaysBeforeNow), + id: 12, + res_id: 100, + res_model: 'res.partner', + state: 'overdue', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -320,13 +355,21 @@ QUnit.test('activity info layout when planned before yesterday', async function QUnit.test('activity with a summary layout', async function (assert) { assert.expect(4); - await this.start(); - const activity = this.messaging.models['Activity'].create({ - id: 12, - summary: 'test summary', - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + id: 12, + res_id: 100, + res_model: 'res.partner', + summary: 'test summary', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -352,13 +395,21 @@ QUnit.test('activity with a summary layout', async function (assert) { QUnit.test('activity without summary layout', async function (assert) { assert.expect(5); - await this.start(); - const activity = this.messaging.models['Activity'].create({ - id: 12, - thread: insert({ id: 42, model: 'res.partner' }), - type: insert({ id: 1, displayName: "Fake type" }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -371,7 +422,7 @@ QUnit.test('activity without summary layout', async function (assert) { ); assert.strictEqual( document.querySelector('.o_Activity_type').textContent.trim(), - "Fake type", + "Email", "activity details should have the activity type display name in type section" ); assert.strictEqual( @@ -389,20 +440,26 @@ QUnit.test('activity without summary layout', async function (assert) { QUnit.test('activity details toggle', async function (assert) { assert.expect(5); - await this.start(); const today = new Date(); const tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); - const activity = this.messaging.models['Activity'].create({ - creator: insert({ id: 1, display_name: "Admin" }), - dateCreate: date_to_str(today), - dateDeadline: date_to_str(tomorrow), - id: 12, - state: 'planned', - thread: insert({ id: 42, model: 'res.partner' }), - type: insert({ id: 1, displayName: "Fake type" }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + create_date: date_to_str(today), + create_uid: 1, + date_deadline: date_to_str(tomorrow), + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -441,21 +498,33 @@ QUnit.test('activity details toggle', async function (assert) { QUnit.test('activity details layout', async function (assert) { assert.expect(11); - await this.start(); const today = new Date(); const tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); - const activity = this.messaging.models['Activity'].create({ - assignee: insert({ id: 10, display_name: "Pauvre pomme" }), - creator: insert({ id: 1, display_name: "Admin" }), - dateCreate: date_to_str(today), - dateDeadline: date_to_str(tomorrow), - id: 12, - state: 'planned', - thread: insert({ id: 42, model: 'res.partner' }), - type: insert({ id: 1, displayName: "Fake type" }), + this.data['res.users'].records.push({ + id: 10, + name: 'Pauvre pomme', + }); + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + create_date: date_to_str(today), + create_uid: 2, + date_deadline: date_to_str(tomorrow), + id: 12, + res_id: 100, + res_model: 'res.partner', + state: 'planned', + user_id: 10, + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -487,7 +556,7 @@ QUnit.test('activity details layout', async function (assert) { ); assert.strictEqual( document.querySelector('.o_Activity_details .o_Activity_type').textContent, - "Fake type", + "Email", "activity details type should be 'Fake type'" ); assert.strictEqual( @@ -520,13 +589,26 @@ QUnit.test('activity details layout', async function (assert) { QUnit.test('activity with mail template layout', async function (assert) { assert.expect(8); - await this.start(); - const activity = this.messaging.models['Activity'].create({ - id: 12, - mailTemplates: insert({ id: 1, name: "Dummy mail template" }), - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.template'].records.push({ + id: 1, + name: "Dummy mail template", + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + id: 12, + mail_template_ids: [1], + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -606,16 +688,26 @@ QUnit.test('activity with mail template: preview mail', async function (assert) ); }); - await this.start({ env: { bus } }); - const activity = this.messaging.models['Activity'].create({ - id: 12, - mailTemplates: insert({ - id: 1, - name: "Dummy mail template", - }), - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 42, + }); + this.data['mail.template'].records.push({ + id: 1, + name: "Dummy mail template", + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + id: 12, + mail_template_ids: [1], + res_id: 42, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start({ env: { bus } }); + await createChatterContainerComponent({ + threadId: 42, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -637,7 +729,22 @@ QUnit.test('activity with mail template: preview mail', async function (assert) QUnit.test('activity with mail template: send mail', async function (assert) { assert.expect(7); - await this.start({ + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 42, + }); + this.data['mail.template'].records.push({ + id: 1, + name: "Dummy mail template", + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + id: 12, + mail_template_ids: [1], + res_id: 42, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start({ async mockRPC(route, args) { if (args.method === 'activity_send_mail') { assert.step('activity_send_mail'); @@ -650,15 +757,10 @@ QUnit.test('activity with mail template: send mail', async function (assert) { } }, }); - const activity = this.messaging.models['Activity'].create({ - id: 12, - mailTemplates: insert({ - id: 1, - name: "Dummy mail template", - }), - thread: insert({ id: 42, model: 'res.partner' }), + await createChatterContainerComponent({ + threadId: 42, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -680,17 +782,23 @@ QUnit.test('activity with mail template: send mail', async function (assert) { QUnit.test('activity upload document is available', async function (assert) { assert.expect(3); - await this.start(); - const today = new Date(); - const tomorrow = new Date(); - tomorrow.setDate(today.getDate() + 1); - const activity = this.messaging.models['Activity'].create({ - canWrite: true, - category: 'upload_file', - id: 12, - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + activity_category: 'upload_file', + activity_type_id: 1, + can_write: true, + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -711,18 +819,23 @@ QUnit.test('activity upload document is available', async function (assert) { QUnit.test('activity click on mark as done', async function (assert) { assert.expect(4); - await this.start(); - const today = new Date(); - const tomorrow = new Date(); - tomorrow.setDate(today.getDate() + 1); - const activity = this.messaging.models['Activity'].create({ - canWrite: true, - category: 'not_upload_file', - id: 12, - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + activity_category: 'default', + activity_type_id: 1, + can_write: true, + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); - assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -756,18 +869,23 @@ QUnit.test('activity click on mark as done', async function (assert) { QUnit.test('activity mark as done popover should focus feedback input on open [REQUIRE FOCUS]', async function (assert) { assert.expect(3); - await this.start(); - const today = new Date(); - const tomorrow = new Date(); - tomorrow.setDate(today.getDate() + 1); - const activity = this.messaging.models['Activity'].create({ - canWrite: true, - category: 'not_upload_file', - id: 12, - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + activity_category: 'default', + activity_type_id: 1, + can_write: true, + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start(); + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); - assert.containsOnce( document.body, '.o_Activity', @@ -822,14 +940,27 @@ QUnit.test('activity click on edit', async function (assert) { ); }); - await this.start({ env: { bus } }); - const activity = this.messaging.models['Activity'].create({ - canWrite: true, - id: 12, - mailTemplates: insert({ id: 1, name: "Dummy mail template" }), - thread: insert({ id: 42, model: 'res.partner' }), + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 42, + }); + this.data['mail.template'].records.push({ + id: 1, + name: "Dummy mail template", + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + can_write: true, + id: 12, + mail_template_ids: [1], + res_id: 42, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start({ env: { bus } }); + await createChatterContainerComponent({ + threadId: 42, + threadModel: 'res.partner', }); - await this.createActivityComponent(activity); assert.strictEqual( document.querySelectorAll('.o_Activity').length, 1, @@ -851,6 +982,10 @@ QUnit.test('activity click on edit', async function (assert) { QUnit.test('activity edition', async function (assert) { assert.expect(14); + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 42, + }); this.data['mail.activity'].records.push({ can_write: true, icon: 'fa-times', @@ -889,15 +1024,11 @@ QUnit.test('activity edition', async function (assert) { this.data['mail.activity'].records[0].icon = 'fa-check'; payload.options.on_close(); }); - - await this.start({ env: { bus } }); - const activity = this.messaging.models['Activity'].insert( - this.messaging.models['Activity'].convertData( - this.data['mail.activity'].records[0] - ) - ); - await this.createActivityComponent(activity); - + const { createChatterContainerComponent } = await this.start({ env: { bus } }); + await createChatterContainerComponent({ + threadId: 42, + threadModel: 'res.partner', + }); assert.containsOnce( document.body, '.o_Activity', @@ -946,7 +1077,18 @@ QUnit.test('activity edition', async function (assert) { QUnit.test('activity click on cancel', async function (assert) { assert.expect(7); - await this.start({ + this.data['res.partner'].records.push({ + activity_ids: [12], + id: 100, + }); + this.data['mail.activity'].records.push({ + activity_type_id: 1, + can_write: true, + id: 12, + res_id: 100, + res_model: 'res.partner', + }); + const { createChatterContainerComponent } = await this.start({ async mockRPC(route, args) { if (route === '/web/dataset/call_kw/mail.activity/unlink') { assert.step('unlink'); @@ -958,45 +1100,10 @@ QUnit.test('activity click on cancel', async function (assert) { } }, }); - const activity = this.messaging.models['Activity'].create({ - canWrite: true, - id: 12, - mailTemplates: insert({ - id: 1, - name: "Dummy mail template", - }), - thread: insert({ id: 42, model: 'res.partner' }), + await createChatterContainerComponent({ + threadId: 100, + threadModel: 'res.partner', }); - - // Create a parent component to surround the Activity component in order to be able - // to check that activity component has been destroyed - class ParentComponent extends Component { - /** - * @returns {Activity} - */ - get activity() { - return this.messaging.models['Activity'].get(this.props.activityLocalId); - } - } - ParentComponent.env = this.env; - Object.assign(ParentComponent, { - props: { activityLocalId: String }, - template: xml` -
parent
-