2023-04-07 01:32:21 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-07 09:26:58 +08:00
|
|
|
RSpec.describe "Message errors", type: :system do
|
2023-04-07 01:32:21 +08:00
|
|
|
context "when message is too long" do
|
2024-07-10 00:34:35 +08:00
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
let(:dialog_page) { PageObjects::Components::Dialog.new }
|
|
|
|
let(:max_length) { SiteSetting.chat_maximum_message_length }
|
|
|
|
let(:message) { "atoolongmessage" + "a" * max_length }
|
2023-04-07 01:32:21 +08:00
|
|
|
|
2024-07-10 00:34:35 +08:00
|
|
|
fab!(:current_user) { Fabricate(:admin) }
|
2023-11-06 22:45:30 +08:00
|
|
|
|
2024-07-10 00:34:35 +08:00
|
|
|
before do
|
|
|
|
chat_system_bootstrap
|
2023-04-07 01:32:21 +08:00
|
|
|
sign_in(current_user)
|
2024-07-10 00:34:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when in channel" do
|
|
|
|
fab!(:channel) { Fabricate(:chat_channel) }
|
|
|
|
|
|
|
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
|
|
|
|
|
|
|
before { channel.add(current_user) }
|
|
|
|
|
|
|
|
it "shows a dialog with the error and keeps the message in the input" do
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
|
|
|
|
channel_page.send_message(message)
|
|
|
|
|
|
|
|
expect(dialog_page).to have_content(
|
|
|
|
I18n.t("chat.errors.message_too_long", count: max_length),
|
|
|
|
)
|
|
|
|
expect(channel_page.composer).to have_value(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when in thread" do
|
|
|
|
fab!(:thread) { Fabricate(:chat_thread) }
|
|
|
|
|
|
|
|
let(:thread_page) { PageObjects::Pages::ChatThread.new }
|
|
|
|
|
|
|
|
before { thread.add(current_user) }
|
|
|
|
|
|
|
|
it "shows a dialog with the error and keeps the message in the input" do
|
|
|
|
chat_page.visit_thread(thread)
|
2023-04-07 01:32:21 +08:00
|
|
|
|
2024-07-10 00:34:35 +08:00
|
|
|
thread_page.send_message(message)
|
2023-04-07 01:32:21 +08:00
|
|
|
|
2024-07-10 00:34:35 +08:00
|
|
|
expect(dialog_page).to have_content(
|
|
|
|
I18n.t("chat.errors.message_too_long", count: max_length),
|
|
|
|
)
|
|
|
|
expect(thread_page.composer).to have_value(message)
|
|
|
|
end
|
2023-04-07 01:32:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|