compose_validate: Fix topic required error message not shown.

Earlier, with `realm_mandatory_topics=true` the topic required
error message was shown only when topic="".

The error message was missing for other topic names which are
also considered empty:
* "(no topic)"
* realm_empty_topic_display_name

This commit fixes the bug to show the error message for the
other two topic names too.
This commit is contained in:
Prakhar Pratyush
2025-03-18 20:38:06 +05:30
committed by Tim Abbott
parent 0642c7a264
commit f8bedf3e3a
2 changed files with 10 additions and 5 deletions

View File

@@ -763,7 +763,7 @@ function validate_stream_message(scheduling_message: boolean, show_banner = true
if (realm.realm_mandatory_topics) {
const topic = compose_state.topic();
const missing_topic = topic === "";
const missing_topic = util.is_topic_name_considered_empty(topic);
set_missing_topic(missing_topic);
if (missing_topic) {
report_validation_error(

View File

@@ -33,7 +33,8 @@ mock_esm("../src/group_permission_settings", {
}),
});
const realm = {};
const REALM_EMPTY_TOPIC_DISPLAY_NAME = "general chat";
const realm = {realm_empty_topic_display_name: REALM_EMPTY_TOPIC_DISPLAY_NAME};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
@@ -343,7 +344,6 @@ test_ui("validate", ({mock_template, override}) => {
stream_data.add_sub(denmark);
compose_state.set_stream_id(denmark.stream_id);
override(realm, "realm_mandatory_topics", true);
compose_state.topic("");
let missing_topic_error_rendered = false;
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
assert.equal(data.classname, compose_banner.CLASSNAMES.topic_missing);
@@ -351,8 +351,13 @@ test_ui("validate", ({mock_template, override}) => {
missing_topic_error_rendered = true;
return "<banner-stub>";
});
assert.ok(!compose_validate.validate());
assert.ok(missing_topic_error_rendered);
for (const topic_name of ["", "(no topic)", `translated: ${REALM_EMPTY_TOPIC_DISPLAY_NAME}`]) {
compose_state.topic(topic_name);
missing_topic_error_rendered = false;
assert.ok(!compose_validate.validate());
assert.ok(missing_topic_error_rendered);
}
});
test_ui("get_invalid_recipient_emails", ({override, override_rewire}) => {