From 6487c8ef24b7e939ad9aafed6108b4207188a43c Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 26 Apr 2023 17:35:35 +0200 Subject: [PATCH] FIX: properly respects chat_minimum_message_length (#21256) Before this fix we were only considering `>` and not `>=`, this also adds two tests. --- .../discourse/components/chat-composer.js | 4 +-- .../chat/spec/system/chat_composer_spec.rb | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js index ead10d17c57..5602ef8981f 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js @@ -103,9 +103,9 @@ export default class ChatComposer extends Component { } get hasContent() { - const minLength = this.siteSettings.chat_minimum_message_length || 0; + const minLength = this.siteSettings.chat_minimum_message_length || 1; return ( - this.currentMessage?.message?.length > minLength || + this.currentMessage?.message?.length >= minLength || (this.canAttachUploads && this.currentMessage?.uploads?.length > 0) ); } diff --git a/plugins/chat/spec/system/chat_composer_spec.rb b/plugins/chat/spec/system/chat_composer_spec.rb index fe66ca967ab..9b2095d4743 100644 --- a/plugins/chat/spec/system/chat_composer_spec.rb +++ b/plugins/chat/spec/system/chat_composer_spec.rb @@ -293,4 +293,35 @@ RSpec.describe "Chat composer", type: :system, js: true do expect(find(".chat-composer__input").value).to eq("[discourse](https://www.discourse.org)") end end + + context "when posting a message with length equal to minimum length" do + before do + SiteSetting.chat_minimum_message_length = 1 + channel_1.add(current_user) + sign_in(current_user) + end + + it "works" do + chat.visit_channel(channel_1) + find("body").send_keys("1") + channel.click_send_message + + expect(channel).to have_message(text: "1") + end + end + + context "when posting a message with length superior to minimum length" do + before do + SiteSetting.chat_minimum_message_length = 2 + channel_1.add(current_user) + sign_in(current_user) + end + + it "doesn’t allow to send" do + chat.visit_channel(channel_1) + find("body").send_keys("1") + + expect(page).to have_css(".chat-composer--send-disabled") + end + end end