FIX: Default parameter recipients to create new message via params must be a string (#22455)

* FIX: Default parameter recipients to create new message via params must be a string

The default parameter recipients was defined as an empty array in:
- route:application#createNewMessageViaParams
- mixin:open-composer#openComposerWithMessageParams

However, in model:composer, targetRecipient is handled as a string as can be
verified due to the existence of the #targetRecipientsArray computed property.

Using the default parameter defined as an array was causing issues with
the `discourse-bcc` plugin when opening the composer using the route
/new-message.

* DEV: Added tests for the composer messages for private messages

* Fix test naming

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>

---------

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
This commit is contained in:
Sérgio Saquetim 2023-07-10 18:33:58 -03:00 committed by GitHub
parent 3d7cca5911
commit 657c1023fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 118 additions and 2 deletions

View File

@ -59,7 +59,7 @@ export default Mixin.create({
},
openComposerWithMessageParams({
recipients = [],
recipients = "",
topicTitle = "",
topicBody = "",
hasGroups = false,

View File

@ -213,7 +213,7 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
},
createNewMessageViaParams({
recipients = [],
recipients = "",
topicTitle = "",
topicBody = "",
hasGroups = false,

View File

@ -11,6 +11,7 @@ import {
waitUntil,
} from "@ember/test-helpers";
import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import I18n from "I18n";
import pretender, { response } from "../helpers/create-pretender";
@ -160,3 +161,118 @@ acceptance("Composer - Messages - Duplicate links", function (needs) {
.exists("shows composer warning message");
});
});
acceptance("Composer - Messages - Private Messages", function (needs) {
needs.user({
id: 32,
username: "codinghorror",
});
needs.pretender((server, helper) => {
server.get("/composer_messages/user_not_seen_in_a_while", () => {
return helper.response({});
});
server.get("/u/search/users", () =>
response({
users: [
{
username: "codinghorror",
},
{
username: "sam",
},
],
})
);
});
test("Shows warning in the composer if the user is sending a message only to himself", async function (assert) {
await visit("/new-message");
const privateMessageUsers = selectKit("#private-message-users");
assert.strictEqual(
privateMessageUsers.header().value(),
null,
"target recipients are empty"
);
// Since we are activating the composer via the route /new-message, it was initialized with
// default values. Filling the input before assigning the target recipient of the message
// also ensures that the popup test is executed correctly when targetRecipients is empty.
await fillIn("#reply-title", "Private message test title");
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
assert.false(
exists(".composer-popup"),
"composer warning is not shown if the target recipients are empty"
);
// filling the input with the username of the current user
await privateMessageUsers.expand();
await privateMessageUsers.fillInFilter("codinghorror");
await privateMessageUsers.selectRowByValue("codinghorror");
await privateMessageUsers.collapse();
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
assert.true(exists(".composer-popup"), "shows composer warning message");
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.yourself_confirm.title")
),
"warning message has correct title"
);
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.yourself_confirm.body")
),
"warning message has correct body"
);
});
test("Does not show a warning in the composer if the message is sent to other users", async function (assert) {
await visit("/new-message");
const privateMessageUsers = selectKit("#private-message-users");
assert.strictEqual(
privateMessageUsers.header().value(),
null,
"target recipients are empty"
);
// Since we are activating the composer via the route /new-message, it was initialized with
// default values. Filling the input before assigning the target recipient of the message
// also ensures that the popup test is executed correctly when targetRecipients is empty.
await fillIn("#reply-title", "Private message test title");
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
assert.false(
exists(".composer-popup"),
"composer warning is not shown if the target recipients are empty"
);
// filling the input with the username of another user
await privateMessageUsers.expand();
await privateMessageUsers.fillInFilter("sam");
await privateMessageUsers.selectRowByValue("sam");
await privateMessageUsers.collapse();
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
assert.false(exists(".composer-popup"), "do not show it for other user");
// filling the input with the username of the current user
await privateMessageUsers.expand();
await privateMessageUsers.fillInFilter("codinghorror");
await privateMessageUsers.selectRowByValue("codinghorror");
await privateMessageUsers.collapse();
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
assert.false(
exists(".composer-popup"),
"do not show it when the current user is just one of the target recipients"
);
});
});