FIX: properly respects chat_minimum_message_length (#21256)

Before this fix we were only considering `>` and not `>=`, this also adds two tests.
This commit is contained in:
Joffrey JAFFEUX 2023-04-26 17:35:35 +02:00 committed by GitHub
parent 731282c2ec
commit 6487c8ef24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -103,9 +103,9 @@ export default class ChatComposer extends Component {
} }
get hasContent() { get hasContent() {
const minLength = this.siteSettings.chat_minimum_message_length || 0; const minLength = this.siteSettings.chat_minimum_message_length || 1;
return ( return (
this.currentMessage?.message?.length > minLength || this.currentMessage?.message?.length >= minLength ||
(this.canAttachUploads && this.currentMessage?.uploads?.length > 0) (this.canAttachUploads && this.currentMessage?.uploads?.length > 0)
); );
} }

View File

@ -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)") expect(find(".chat-composer__input").value).to eq("[discourse](https://www.discourse.org)")
end end
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 "doesnt 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 end