discourse/plugins/chat/spec/system/chat_message/thread_spec.rb
Loïc Guitaut e1ae32103d DEV: Refactor chat specs related to message creation
This is extracted from #22390.

This patch aims to ease the transition to the new message creation
service. (in progress in #22390) Indeed, the new service patch is
breaking some specs from `discourse-ai` and `discourse-templates`
because these plugins are using either `Chat::MessageCreator` or the
`chat_message` fabricator.

This patch addresses theses issues by normalizing how we create a chat
message in specs. To do so, the preferred way is to use
`Fabricate(:chat_message)` with a new `:use_service` option allowing to
call the service under the hood. While this patch will obviously call
`Chat::MessageCreator`, the new service patch will now be able to simply
change the call to `Chat::CreateMessage` without breaking any specs from
other plugins.

Another thing this patch does is to not create chat messages using the
service for specs that aren’t system ones, thus speeding the execution
time a bit in the process.
2023-08-31 11:21:23 +02:00

48 lines
1.4 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Chat message - thread", type: :system do
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
fab!(:thread_message_1) do
message_1 = Fabricate(:chat_message, chat_channel: channel_1, use_service: true)
Fabricate(:chat_message, in_reply_to: message_1, use_service: true)
end
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:thread_page) { PageObjects::Pages::ChatThread.new }
before do
chat_system_bootstrap
channel_1.add(current_user)
sign_in(current_user)
end
context "when hovering a message" do
it "adds an active class" do
chat_page.visit_thread(thread_message_1.thread)
thread_page.hover_message(thread_message_1)
expect(page).to have_css(
".chat-thread[data-id='#{thread_message_1.thread.id}'] [data-id='#{thread_message_1.id}'].chat-message-container.-active",
)
end
end
context "when copying link to a message" do
let(:cdp) { PageObjects::CDP.new }
before { cdp.allow_clipboard }
it "copies the link to the thread" do
chat_page.visit_thread(thread_message_1.thread)
thread_page.copy_link(thread_message_1)
expect(cdp.read_clipboard).to include(
"/chat/c/-/#{channel_1.id}/t/#{thread_message_1.thread.id}/#{thread_message_1.id}",
)
end
end
end