2022-12-22 19:04:41 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Quoting chat message transcripts", type: :system, js: true do
|
|
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
fab!(:chat_channel_1) { Fabricate(:chat_channel) }
|
|
|
|
|
2023-04-13 08:45:50 -04:00
|
|
|
let(:cdp) { PageObjects::CDP.new }
|
2022-12-22 19:04:41 -05:00
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
let(:chat_channel_page) { PageObjects::Pages::ChatChannel.new }
|
|
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
chat_system_bootstrap(Fabricate(:admin), [chat_channel_1])
|
|
|
|
chat_channel_1.add(current_user)
|
|
|
|
sign_in(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def select_message_desktop(message)
|
|
|
|
if page.has_css?(".chat-message-container.selecting-messages")
|
|
|
|
chat_channel_page.message_by_id(message.id).find(".chat-message-selector").click
|
|
|
|
else
|
|
|
|
chat_channel_page.message_by_id(message.id).hover
|
|
|
|
expect(page).to have_css(".chat-message-actions .more-buttons")
|
|
|
|
find(".chat-message-actions .more-buttons").click
|
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.
There are now several new classes and concepts:
* ChatMessageInteractor - This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.
The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.
This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 09:19:52 -04:00
|
|
|
find(".select-kit-row[data-value=\"select\"]").click
|
2022-12-22 19:04:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def click_selection_button(button)
|
|
|
|
selector =
|
|
|
|
case button
|
|
|
|
when "quote"
|
2023-02-01 10:39:23 -05:00
|
|
|
"chat-quote-btn"
|
2022-12-22 19:04:41 -05:00
|
|
|
when "copy"
|
2023-02-01 10:39:23 -05:00
|
|
|
"chat-copy-btn"
|
2022-12-22 19:04:41 -05:00
|
|
|
when "cancel"
|
2023-02-01 10:39:23 -05:00
|
|
|
"chat-cancel-selection-btn"
|
2022-12-22 19:04:41 -05:00
|
|
|
when "move"
|
2023-02-01 10:39:23 -05:00
|
|
|
"chat-move-to-channel-btn"
|
2022-12-22 19:04:41 -05:00
|
|
|
end
|
2023-02-01 10:39:23 -05:00
|
|
|
find_button(selector, disabled: false, wait: 5).click
|
2022-12-22 19:04:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def copy_messages_to_clipboard(messages)
|
|
|
|
messages = Array.wrap(messages)
|
|
|
|
messages.each { |message| select_message_desktop(message) }
|
|
|
|
expect(chat_channel_page).to have_selection_management
|
|
|
|
click_selection_button("copy")
|
2023-02-01 10:39:23 -05:00
|
|
|
expect(page).to have_selector(".chat-copy-success")
|
2023-04-13 08:45:50 -04:00
|
|
|
clip_text = cdp.read_clipboard
|
2022-12-22 19:04:41 -05:00
|
|
|
expect(clip_text.chomp).to eq(generate_transcript(messages, current_user))
|
|
|
|
clip_text
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_transcript(messages, acting_user)
|
|
|
|
messages = Array.wrap(messages)
|
2023-03-17 09:24:38 -04:00
|
|
|
Chat::TranscriptService
|
2022-12-22 19:04:41 -05:00
|
|
|
.new(messages.first.chat_channel, acting_user, messages_or_ids: messages.map(&:id))
|
|
|
|
.generate_markdown
|
|
|
|
.chomp
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "copying quote transcripts with the clipboard" do
|
2023-04-13 08:45:50 -04:00
|
|
|
before { cdp.allow_clipboard }
|
2022-12-22 19:04:41 -05:00
|
|
|
|
|
|
|
context "when quoting a single message into a topic" do
|
|
|
|
fab!(:post_1) { Fabricate(:post) }
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
|
|
|
|
|
|
|
|
it "quotes the message" do
|
|
|
|
chat_page.visit_channel(chat_channel_1)
|
|
|
|
|
|
|
|
clip_text = copy_messages_to_clipboard(message_1)
|
|
|
|
topic_page.visit_topic_and_open_composer(post_1.topic)
|
|
|
|
topic_page.fill_in_composer("This is a new post!\n\n" + clip_text)
|
|
|
|
|
|
|
|
within(".d-editor-preview") { expect(page).to have_css(".chat-transcript") }
|
|
|
|
|
|
|
|
topic_page.send_reply
|
|
|
|
selector = topic_page.post_by_number_selector(2)
|
|
|
|
|
|
|
|
expect(page).to have_css(selector)
|
|
|
|
within(selector) { expect(page).to have_css(".chat-transcript") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when quoting multiple messages into a topic" do
|
|
|
|
fab!(:post_1) { Fabricate(:post) }
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
|
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
|
|
|
|
|
|
|
|
it "quotes the messages" do
|
|
|
|
chat_page.visit_channel(chat_channel_1)
|
|
|
|
|
|
|
|
clip_text = copy_messages_to_clipboard([message_1, message_2])
|
|
|
|
topic_page.visit_topic_and_open_composer(post_1.topic)
|
|
|
|
topic_page.fill_in_composer("This is a new post!\n\n" + clip_text)
|
|
|
|
|
|
|
|
within(".d-editor-preview") { expect(page).to have_css(".chat-transcript", count: 2) }
|
|
|
|
expect(page).to have_content("Originally sent in #{chat_channel_1.name}")
|
|
|
|
|
|
|
|
topic_page.send_reply
|
|
|
|
|
|
|
|
selector = topic_page.post_by_number_selector(2)
|
|
|
|
expect(page).to have_css(selector)
|
|
|
|
within(selector) { expect(page).to have_css(".chat-transcript", count: 2) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when quoting a message containing a onebox" do
|
|
|
|
fab!(:post_1) { Fabricate(:post) }
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Oneboxer.stubs(:preview).returns(
|
|
|
|
"<aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\" tabindex=\"-1\">An interesting article</a></h3></article></aside>",
|
|
|
|
)
|
|
|
|
message_1.update!(message: "http://www.example.com/has-title.html")
|
|
|
|
message_1.rebake!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
chat_page.visit_channel(chat_channel_1)
|
|
|
|
|
|
|
|
clip_text = copy_messages_to_clipboard(message_1)
|
|
|
|
topic_page.visit_topic_and_open_composer(post_1.topic)
|
|
|
|
topic_page.fill_in_composer(clip_text)
|
|
|
|
|
|
|
|
within(".chat-transcript-messages") do
|
|
|
|
expect(page).to have_content("An interesting article")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when quoting a message in another message" do
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
|
|
|
|
|
2023-01-05 18:04:38 -05:00
|
|
|
it "quotes the message" do
|
2022-12-22 19:04:41 -05:00
|
|
|
chat_page.visit_channel(chat_channel_1)
|
|
|
|
|
|
|
|
clip_text = copy_messages_to_clipboard(message_1)
|
|
|
|
click_selection_button("cancel")
|
2023-01-02 09:17:21 -05:00
|
|
|
chat_channel_page.send_message(clip_text)
|
2022-12-22 19:04:41 -05:00
|
|
|
|
|
|
|
expect(page).to have_selector(".chat-message", count: 2)
|
2023-04-27 03:43:26 -04:00
|
|
|
expect(page).to have_css(".chat-transcript")
|
2022-12-22 19:04:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when quoting into a topic directly" do
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
|
|
|
|
let(:topic_title) { "Some topic title for testing" }
|
|
|
|
|
|
|
|
it "opens the topic composer with correct state" do
|
|
|
|
chat_page.visit_channel(chat_channel_1)
|
|
|
|
|
|
|
|
select_message_desktop(message_1)
|
|
|
|
click_selection_button("quote")
|
|
|
|
|
|
|
|
expect(topic_page).to have_expanded_composer
|
|
|
|
expect(topic_page).to have_composer_content(generate_transcript(message_1, current_user))
|
|
|
|
expect(page).to have_css(
|
|
|
|
".category-input .select-kit-header[data-value='#{chat_channel_1.chatable.id}']",
|
|
|
|
)
|
|
|
|
expect(page).not_to have_current_path(chat_channel_1.chatable.url)
|
|
|
|
|
|
|
|
topic_page.fill_in_composer_title(topic_title)
|
|
|
|
topic_page.send_reply
|
|
|
|
|
|
|
|
selector = topic_page.post_by_number_selector(1)
|
|
|
|
expect(page).to have_css(selector)
|
|
|
|
within(selector) { expect(page).to have_css(".chat-transcript") }
|
|
|
|
|
|
|
|
topic = Topic.find_by(user: current_user, title: topic_title)
|
|
|
|
expect(page).to have_current_path(topic.url)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when on mobile" do
|
2023-03-08 10:49:20 -05:00
|
|
|
it "first navigates to the channel's category before opening the topic composer with the quote prefilled",
|
|
|
|
mobile: true do
|
2022-12-22 19:04:41 -05:00
|
|
|
chat_page.visit_channel(chat_channel_1)
|
2023-02-01 10:39:23 -05:00
|
|
|
|
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.
There are now several new classes and concepts:
* ChatMessageInteractor - This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.
The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.
This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 09:19:52 -04:00
|
|
|
chat_channel_page.click_message_action_mobile(message_1, "select")
|
2022-12-22 19:04:41 -05:00
|
|
|
click_selection_button("quote")
|
|
|
|
|
|
|
|
expect(topic_page).to have_expanded_composer
|
|
|
|
expect(topic_page).to have_composer_content(generate_transcript(message_1, current_user))
|
|
|
|
expect(page).to have_current_path(chat_channel_1.chatable.url)
|
|
|
|
expect(page).to have_css(
|
|
|
|
".category-input .select-kit-header[data-value='#{chat_channel_1.chatable.id}']",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|