diff --git a/addons/mail/static/src/core/common/composer.js b/addons/mail/static/src/core/common/composer.js index d4942674983..67b77ced0dd 100644 --- a/addons/mail/static/src/core/common/composer.js +++ b/addons/mail/static/src/core/common/composer.js @@ -434,9 +434,12 @@ export class Composer extends Component { default_attachment_ids: attachmentIds, default_body: escapeAndCompactTextContent(this.props.composer.textInputContent), default_model: this.props.composer.thread.model, - default_partner_ids: this.props.composer.thread.suggestedRecipients.map( - (recipient) => recipient.persona.id - ), + default_partner_ids: + this.props.type === "note" + ? [] + : this.props.composer.thread.suggestedRecipients + .filter((recipient) => recipient.checked) + .map((recipient) => recipient.persona.id), default_res_ids: [this.props.composer.thread.id], default_subtype_xmlid: this.props.type === "note" ? "mail.mt_note" : "mail.mt_comment", mail_post_autofollow: this.props.composer.thread.hasWriteAccess, diff --git a/addons/mail/static/tests/composer/suggested_recipients_test.js b/addons/mail/static/tests/composer/suggested_recipients_test.js index 86dc787bb2c..3faeb4cffea 100644 --- a/addons/mail/static/tests/composer/suggested_recipients_test.js +++ b/addons/mail/static/tests/composer/suggested_recipients_test.js @@ -7,6 +7,7 @@ import { startServer, waitUntil, } from "@mail/../tests/helpers/test_utils"; +import { patchWithCleanup } from "@web/../tests/helpers/utils"; const views = { "res.fake,false,form": ` @@ -37,6 +38,81 @@ QUnit.test("with 3 or less suggested recipients: no 'show more' button", async ( assert.containsNone($, "button:contains(Show more)"); }); +QUnit.test( + "Opening full composer in 'send message' mode should copy selected suggested recipients", + async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ + display_name: "John Jane", + email: "john@jane.be", + }); + const fakeId = pyEnv["res.fake"].create({ + email_cc: "john@test.be", + partner_ids: [partnerId], + }); + const { env, openFormView } = await start(); + await openFormView("res.fake", fakeId); + patchWithCleanup(env.services.action, { + doAction(action) { + assert.step("do-action"); + assert.strictEqual(action.name, "Compose Email"); + assert.strictEqual(action.context.default_subtype_xmlid, "mail.mt_comment"); + assert.deepEqual(action.context.default_partner_ids, [partnerId]); + return Promise.resolve(); + }, + }); + await click("button:contains(Send message)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(john@test.be)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(John Jane)"); + assert.notOk( + $(".o-mail-SuggestedRecipient:contains(john@test.be) input[type=checkbox]")[0].checked + ); + assert.ok( + $(".o-mail-SuggestedRecipient:contains(John Jane) input[type=checkbox]")[0].checked + ); + await click("button[title='Full composer']"); + assert.verifySteps(["do-action"]); + } +); + +QUnit.test( + "Opening full composer in 'log note' mode should not copy selected suggested recipients", + async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ + display_name: "John Jane", + email: "john@jane.be", + }); + const fakeId = pyEnv["res.fake"].create({ + email_cc: "john@test.be", + partner_ids: [partnerId], + }); + const { env, openFormView } = await start(); + await openFormView("res.fake", fakeId); + patchWithCleanup(env.services.action, { + doAction(action) { + assert.step("do-action"); + assert.strictEqual(action.name, "Log note"); + assert.strictEqual(action.context.default_subtype_xmlid, "mail.mt_note"); + assert.deepEqual(action.context.default_partner_ids, []); + return Promise.resolve(); + }, + }); + await click("button:contains(Send message)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(john@test.be)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(John Jane)"); + assert.notOk( + $(".o-mail-SuggestedRecipient:contains(john@test.be) input[type=checkbox]")[0].checked + ); + assert.ok( + $(".o-mail-SuggestedRecipient:contains(John Jane) input[type=checkbox]")[0].checked + ); + await click("button:contains(Log note)"); + await click("button[title='Full composer']"); + assert.verifySteps(["do-action"]); + } +); + QUnit.test( "more than 3 suggested recipients: display only 3 and 'show more' button", async (assert) => {