2023-03-03 20:09:25 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-07 09:26:58 +08:00
|
|
|
RSpec.describe "Message user info", type: :system do
|
2023-03-03 20:09:25 +08:00
|
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
fab!(:channel_1) { Fabricate(:category_channel) }
|
|
|
|
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
chat_system_bootstrap
|
2023-04-08 02:08:31 +08:00
|
|
|
channel_1.add(current_user)
|
2023-03-03 20:09:25 +08:00
|
|
|
sign_in(current_user)
|
|
|
|
end
|
|
|
|
|
2023-04-08 02:08:31 +08:00
|
|
|
context "with one message" do
|
2023-03-03 20:09:25 +08:00
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
|
|
|
|
|
|
it "shows user info on the message" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-04-08 02:08:31 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with two messages from the same user" do
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
|
|
|
|
it "shows user info only on first message" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_no_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-03-03 20:09:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-08 02:08:31 +08:00
|
|
|
context "with a deleted previous message" do
|
2023-03-03 20:09:25 +08:00
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
|
2023-04-08 02:08:31 +08:00
|
|
|
it "shows user info only on second message" do
|
|
|
|
message_1.trash!
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-04-08 02:08:31 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with messages from a webhook" do
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
it "shows user info only on both messages" do
|
2023-04-08 02:08:31 +08:00
|
|
|
Fabricate(:chat_webhook_event, chat_message: message_1)
|
|
|
|
Fabricate(:chat_webhook_event, chat_message: message_2)
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-04-08 02:08:31 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with large time difference between messages" do
|
|
|
|
fab!(:message_1) do
|
|
|
|
Fabricate(:chat_message, chat_channel: channel_1, user: current_user, created_at: 1.days.ago)
|
|
|
|
end
|
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
|
|
|
|
it "shows user info on both messages" do
|
2023-03-03 20:09:25 +08:00
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-04-08 02:08:31 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when replying to own previous message" do
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
fab!(:message_2) do
|
|
|
|
Fabricate(:chat_message, in_reply_to: message_1, user: current_user, chat_channel: channel_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows user info on first message only" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_no_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-03-03 20:09:25 +08:00
|
|
|
end
|
2023-04-08 02:08:31 +08:00
|
|
|
end
|
2023-03-03 20:09:25 +08:00
|
|
|
|
2023-04-08 02:08:31 +08:00
|
|
|
context "when replying to another user previous message and previous message is yours" do
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
|
|
|
|
fab!(:message_3) do
|
|
|
|
Fabricate(:chat_message, in_reply_to: message_1, user: current_user, chat_channel: channel_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows user info on each message" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
2023-12-07 05:25:11 +08:00
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
|
|
|
expect(page.find(".chat-message-container[data-id='#{message_3.id}']")).to have_css(
|
|
|
|
".chat-message-avatar",
|
|
|
|
)
|
2023-03-03 20:09:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|