diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index d3a038acf42..f4dd0ec4a45 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -400,19 +400,6 @@ function getCreateComposerSuggestionComponent({ env, target }) { }; } -function getCreateMessageComponent({ env, target }) { - return async function createMessageComponent(message) { - const messageView = env.services.messaging.modelManager.messaging.models['MessageView'].create({ - message: replace(message), - qunitTest: insertAndReplace(), - }); - await createRootMessagingComponent(env, "Message", { - props: { record: messageView }, - target, - }); - }; -} - function getCreateNotificationListComponent({ env, target }) { return async function createNotificationListComponent({ filter = 'all' } = {}) { const notificationListView = env.services.messaging.modelManager.messaging.models['NotificationListView'].create({ @@ -590,7 +577,6 @@ async function start(param0 = {}) { click: getClick({ afterNextRender }), createComposerComponent: getCreateComposerComponent({ env: webClient.env, target }), createComposerSuggestionComponent: getCreateComposerSuggestionComponent({ env: webClient.env, target }), - createMessageComponent: getCreateMessageComponent({ env: webClient.env, target }), createNotificationListComponent: getCreateNotificationListComponent({ env: webClient.env, target }), createRootMessagingComponent: (componentName, props) => createRootMessagingComponent(webClient.env, componentName, { props, target }), createThreadViewComponent: getCreateThreadViewComponent({ afterEvent, env: webClient.env, target }), diff --git a/addons/mail/static/tests/qunit_suite_tests/components/attachment_image_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/attachment_image_tests.js index 1b300ca95ac..9e5f4353401 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/attachment_image_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/attachment_image_tests.js @@ -1,7 +1,6 @@ /** @odoo-module **/ -import { link, replace } from '@mail/model/model_field_command'; -import { start } from '@mail/../tests/helpers/test_utils'; +import { start, startServer } from '@mail/../tests/helpers/test_utils'; QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { @@ -10,20 +9,27 @@ QUnit.module('attachment_image_tests.js'); QUnit.test('auto layout with image', async function (assert) { assert.expect(3); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.png", - id: 750, - mimetype: 'image/png', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.png", + mimetype: 'image/png', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "
Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.strictEqual( document.querySelectorAll(`.o_AttachmentImage img`).length, 1, diff --git a/addons/mail/static/tests/qunit_suite_tests/components/attachment_list_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/attachment_list_tests.js index 6cf7bbeaea8..d85fac904a6 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/attachment_list_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/attachment_list_tests.js @@ -1,8 +1,6 @@ /** @odoo-module **/ -import { link, replace } from '@mail/model/model_field_command'; - -import { afterNextRender, start } from '@mail/../tests/helpers/test_utils'; +import { afterNextRender, start, startServer } from '@mail/../tests/helpers/test_utils'; QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { @@ -11,20 +9,27 @@ QUnit.module('attachment_list_tests.js'); QUnit.test('simplest layout', async function (assert) { assert.expect(8); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.txt", - id: 750, - mimetype: 'text/plain', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.txt", + mimetype: 'text/plain', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { messaging, openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.strictEqual( document.querySelectorAll('.o_AttachmentList').length, @@ -34,7 +39,7 @@ QUnit.test('simplest layout', async function (assert) { const attachmentEl = document.querySelector('.o_AttachmentList .o_AttachmentCard'); assert.strictEqual( attachmentEl.dataset.id, - messaging.models['Attachment'].findFromIdentifyingData({ id: 750 }).localId, + messaging.models['Attachment'].findFromIdentifyingData({ id: messageAttachmentId }).localId, "attachment component should be linked to attachment store model" ); assert.strictEqual( @@ -73,7 +78,25 @@ QUnit.test('simplest layout', async function (assert) { QUnit.test('simplest layout + editable', async function (assert) { assert.expect(7); - const { createMessageComponent, messaging } = await start({ + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ + name: "test.txt", + mimetype: 'text/plain', + }); + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], + body: "Test
", + model: 'mail.channel', + res_id: channelId + }); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, async mockRPC(route, args) { if (route.includes('web/image/750')) { assert.ok( @@ -83,19 +106,7 @@ QUnit.test('simplest layout + editable', async function (assert) { } }, }); - const attachment = messaging.models['Attachment'].create({ - filename: "test.txt", - id: 750, - mimetype: 'text/plain', - name: "test.txt", - }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), - body: "Test
", - id: 100, - }); - await createMessageComponent(message); + await openDiscuss(); assert.strictEqual( document.querySelectorAll('.o_AttachmentList').length, @@ -138,20 +149,27 @@ QUnit.test('simplest layout + editable', async function (assert) { QUnit.test('layout with card details and filename and extension', async function (assert) { assert.expect(2); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.txt", - id: 750, - mimetype: 'text/plain', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.txt", + mimetype: 'text/plain', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.strictEqual( document.querySelectorAll(`.o_AttachmentCard_details`).length, @@ -168,20 +186,27 @@ QUnit.test('layout with card details and filename and extension', async function QUnit.test('view attachment', async function (assert) { assert.expect(3); - const { click, createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.png", - id: 750, - mimetype: 'image/png', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.png", + mimetype: 'image/png', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { click, openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.containsOnce( document.body, @@ -204,20 +229,27 @@ QUnit.test('view attachment', async function (assert) { QUnit.test('close attachment viewer', async function (assert) { assert.expect(3); - const { click, createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.png", - id: 750, - mimetype: 'image/png', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.png", + mimetype: 'image/png', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { click, openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.containsOnce( document.body, @@ -243,26 +275,32 @@ QUnit.test('close attachment viewer', async function (assert) { QUnit.test('clicking on the delete attachment button multiple times should do the rpc only once', async function (assert) { assert.expect(2); - const { click, createMessageComponent, messaging } = await start({ + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ + name: "test.txt", + mimetype: 'text/plain', + }); + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], + body: "Test
", + model: 'mail.channel', + res_id: channelId + }); + const { click, openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, async mockRPC(route, args) { if (route === '/mail/attachment/delete') { assert.step('attachment_unlink'); } }, }); - const attachment = messaging.models['Attachment'].create({ - filename: "test.txt", - id: 750, - mimetype: 'text/plain', - name: "test.txt", - }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), - body: "Test
", - id: 100, - }); - await createMessageComponent(message); + await openDiscuss(); await click('.o_AttachmentCard_asideItemUnlink'); @@ -289,20 +327,27 @@ QUnit.test('[technical] does not crash when the viewer is closed before image lo */ assert.expect(1); - const { click, createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.png", - id: 750, - mimetype: 'image/png', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.png", + mimetype: 'image/png', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { click, openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); await click('.o_AttachmentImage'); const imageEl = document.querySelector('.o_AttachmentViewer_viewImage'); await click('.o_AttachmentViewer_headerItemButtonClose'); @@ -321,20 +366,27 @@ QUnit.test('[technical] does not crash when the viewer is closed before image lo QUnit.test('plain text file is viewable', async function (assert) { assert.expect(1); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.txt", - id: 750, - mimetype: 'text/plain', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.txt", + mimetype: 'text/plain', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.hasClass( document.querySelector('.o_AttachmentCard'), @@ -346,20 +398,27 @@ QUnit.test('plain text file is viewable', async function (assert) { QUnit.test('HTML file is viewable', async function (assert) { assert.expect(1); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.html", - id: 750, - mimetype: 'text/html', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.html", + mimetype: 'text/html', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.hasClass( document.querySelector('.o_AttachmentCard'), 'o-viewable', @@ -370,20 +429,27 @@ QUnit.test('HTML file is viewable', async function (assert) { QUnit.test('ODT file is not viewable', async function (assert) { assert.expect(1); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.odt", - id: 750, - mimetype: 'application/vnd.oasis.opendocument.text', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.odt", + mimetype: 'application/vnd.oasis.opendocument.text', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.doesNotHaveClass( document.querySelector('.o_AttachmentCard'), 'o-viewable', @@ -394,20 +460,27 @@ QUnit.test('ODT file is not viewable', async function (assert) { QUnit.test('DOCX file is not viewable', async function (assert) { assert.expect(1); - const { createMessageComponent, messaging } = await start(); - const attachment = messaging.models['Attachment'].create({ - filename: "test.docx", - id: 750, - mimetype: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + const pyEnv = await startServer(); + const channelId = pyEnv['mail.channel'].create({ + channel_type: 'channel', + name: 'channel1', + }); + const messageAttachmentId = pyEnv['ir.attachment'].create({ name: "test.docx", + mimetype: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', }); - const message = messaging.models['Message'].create({ - attachments: link(attachment), - author: replace(messaging.currentPartner), + pyEnv['mail.message'].create({ + attachment_ids: [messageAttachmentId], body: "Test
", - id: 100, + model: 'mail.channel', + res_id: channelId }); - await createMessageComponent(message); + const { openDiscuss } = await start({ + discuss: { + context: { active_id: channelId }, + }, + }); + await openDiscuss(); assert.doesNotHaveClass( document.querySelector('.o_AttachmentCard'), 'o-viewable',