Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose_banner: Assign banner priority.

Apoorva Pendse8496a40564b3
diff --git a/web/src/compose_validate.ts b/web/src/compose_validate.ts
index 937cd07b4ab..6d4e316ee89 100644
--- a/web/src/compose_validate.ts
+++ b/web/src/compose_validate.ts
@@ -857,6 +857,20 @@ export function validate_message_length($container: JQuery): boolean {
export function validate(scheduling_message: boolean): boolean {
const message_content = compose_state.message_content();
+ // The validation checks in this function are in a specific priority order. Don't
+ // change their order unless you want to change which priority they're shown in.
+
+ if (
+ compose_state.get_message_type() !== "private" &&
+ !validate_stream_message(scheduling_message)
+ ) {
+ return false;
+ }
+
+ if (compose_state.get_message_type() === "private" && !validate_private_message()) {
+ return false;
+ }
+
const no_message_content = /^\s*$/.test(message_content);
if (no_message_content) {
$("textarea#compose-textarea").toggleClass("invalid", true);
@@ -879,10 +893,7 @@ export function validate(scheduling_message: boolean): boolean {
return false;
}
- if (compose_state.get_message_type() === "private") {
- return validate_private_message();
- }
- return validate_stream_message(scheduling_message);
+ return true;
}
export function convert_mentions_to_silent_in_direct_messages(
diff --git a/web/tests/compose.test.cjs b/web/tests/compose.test.cjs
index 363e555eb63..e2036c05c27 100644
--- a/web/tests/compose.test.cjs
+++ b/web/tests/compose.test.cjs
@@ -486,6 +486,14 @@ test_ui("finish", ({override, override_rewire}) => {
});
(function test_when_compose_validation_fails() {
+ // To trigger the empty banner error instead of other errors
+ // set as per the priority.
+ override(current_user, "user_id", new_user.user_id);
+ compose_state.set_stream_id(social.stream_id);
+ fake_compose_box.set_topic_val("lunch");
+ fake_compose_box.set_textarea_val("burrito");
+ compose_state.set_message_type("stream");
+
fake_compose_box.set_textarea_toggle_class_function((classname, value) => {
assert.equal(classname, "invalid");
assert.equal(value, true);