compose_validate: Use correct stream_id value for different context.

This commit addresses the issue of relying on `compose_state` for
retrieving the `stream_id` to display warning banners. Previously,
warnings were shown for syntax in the message edit box based on
whether that syntax would trigger a warning for the draft content (if
any) currently in the compose box.

We fix this by using a new `get_stream_id_for_textarea` function to
obtain the correct `stream_id` value for the check being done.

Fixes: #25410.
This commit is contained in:
Daniil Fadeev
2023-05-24 14:27:44 +04:00
committed by Tim Abbott
parent 807b9ae081
commit 3e2d5b3c86
2 changed files with 44 additions and 16 deletions

View File

@@ -66,6 +66,15 @@ function test_ui(label, f) {
});
}
function stub_message_row($textarea) {
const $stub = $.create("message_row_stub");
$textarea.closest = (selector) => {
assert.equal(selector, ".message_row");
$stub.length = 0;
return $stub;
};
}
test_ui("validate_stream_message_address_info", ({mock_template}) => {
mock_banners();
const sub = {
@@ -622,6 +631,7 @@ test_ui("needs_subscribe_warning", () => {
test_ui("warn_if_private_stream_is_linked", ({mock_template}) => {
const $textarea = $("<textarea>").attr("id", "compose-textarea");
stub_message_row($textarea);
const test_sub = {
name: compose_state.stream_name(),
stream_id: 99,
@@ -676,6 +686,7 @@ test_ui("warn_if_private_stream_is_linked", ({mock_template}) => {
test_ui("warn_if_mentioning_unsubscribed_user", ({override, override_rewire, mock_template}) => {
override_rewire(compose_recipient, "on_compose_select_recipient_update", () => {});
const $textarea = $("<textarea>").attr("id", "compose-textarea");
stub_message_row($textarea);
compose_state.set_stream_name("");
override(settings_data, "user_can_subscribe_other_users", () => true);