[FIX] mail: no suggested recipients in full composer of log note

Before this commit, opening full composer from chatter were always
copying the selected suggested recipients, regardless of the mode
of the composer.

Suggested recipients only makes sense in "Send message" mode,
therefore it should not copy them in "Log note" mode, which this
commit fixes.

Also fix a bug where copying of suggested recipients in full composer
was taking all suggested recipients into account, regardless of
checkbox state. This commit fixes issue by copying only checked
suggested recipients

closes odoo/odoo#128466

X-original-commit: 89afc58a69a53824a9100ceaf4f3574bb82dfc1d
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2023-07-13 19:28:37 +02:00
parent 872065e0ee
commit b711020e8d
2 changed files with 82 additions and 3 deletions
@@ -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,
@@ -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) => {