discourse/plugins/chat/spec/system/chat_message/channel_spec.rb
Joffrey JAFFEUX 90efdd7f9d
PERF: cook message in background (#24227)
This commit starts from a simple observation: cooking messages on the hot path can be slow. Especially with a lot of mentions.

To move cooking from the hot path, this commit has made the following changes:

- updating cooked, inserting mentions and notifying user of new mentions has been moved inside the `process_message` job. It happens right after the `Chat::MessageProcessor` run, which is where the cooking happens.
- the similar existing code in `rebake!` has also been moved to rely on the `process_message`job only
- refactored `create_mentions` and `update_mentions` into one single `upsert_mentions` which can be called invariably
- allows services to decide if their job is ran inline or later. It avoids to need to know you have to use `Jobs.run_immediately!` in this case, in tests it will be inline per default
- made various frontend changes to make the chat-channel component lifecycle clearer. we had to handle `did-update @channel` which was super awkward and creating bugs with listeners which the changes of the PR made clear in failing specs
- adds a new `-processed` (and `-not-processed`) class on the chat message, this is made to have a good lifecyle hook in system specs
2023-11-06 15:45:30 +01:00

99 lines
3.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Chat message - channel", type: :system do
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel) }
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, use_service: true) }
let(:cdp) { PageObjects::CDP.new }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.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_channel(channel_1)
channel_page.hover_message(message_1)
expect(page).to have_css(
".chat-channel[data-id='#{channel_1.id}'] .chat-message-container[data-id='#{message_1.id}'].-active",
)
end
end
context "when copying text of a message" do
before { cdp.allow_clipboard }
it "[mobile] copies the text of a single message", mobile: true do
chat_page.visit_channel(channel_1)
channel_page.messages.copy_text(message_1)
expect(cdp.read_clipboard.chomp).to eq(message_1.message)
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.text_copied"))
end
end
context "when copying link to a message" do
before { cdp.allow_clipboard }
it "copies the link to the message" do
chat_page.visit_channel(channel_1)
channel_page.messages.copy_link(message_1)
expect(cdp.read_clipboard).to include("/chat/c/-/#{channel_1.id}/#{message_1.id}")
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.link_copied"))
end
it "[mobile] copies the link to the message", mobile: true do
chat_page.visit_channel(channel_1)
channel_page.messages.copy_link(message_1)
expect(cdp.read_clipboard).to include("/chat/c/-/#{channel_1.id}/#{message_1.id}")
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.link_copied"))
end
context "when the message is part of a thread" do
before { channel_1.update!(threading_enabled: true) }
fab!(:thread_1) do
chat_thread_chain_bootstrap(
channel: channel_1,
users: [current_user, Fabricate(:user)],
messages_count: 2,
)
end
it "copies the link to the message" do
chat_page.visit_channel(channel_1)
channel_page.messages.copy_link(thread_1.original_message)
expect(cdp.read_clipboard).to include(
"/chat/c/-/#{channel_1.id}/#{thread_1.original_message.id}",
)
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.link_copied"))
end
xit "[mobile] copies the link to the message", mobile: true do
chat_page.visit_channel(channel_1)
channel_page.messages.copy_link(thread_1.original_message)
expect(cdp.read_clipboard).to include(
"/chat/c/-/#{channel_1.id}/#{thread_1.original_message.id}",
)
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.link_copied"))
end
end
end
end