FEATURE: Hook up chat bulk delete for threads (#21109)

Followup to bd5c5c4b5f7b33a64cc12e2ba13e81767ac00edc,
this commit hooks up the bulk delete events for chat
messages inside the thread panel, by fanning out the
deleted message IDs based on whether they belong to
a thread or not.

Also adds a system spec to cover this case, as previously
the bulk delete event would have been broken with an incorrect
`typ` rather than `type` hash key.
This commit is contained in:
Martin Brennan
2023-04-18 08:28:20 +10:00
committed by GitHub
parent b869d35f94
commit 1e85de36e2
10 changed files with 222 additions and 24 deletions

View File

@ -24,4 +24,49 @@ RSpec.describe "Deleted message", type: :system, js: true do
expect(page).to have_content(I18n.t("js.chat.deleted"))
end
end
context "when bulk deleting messages across the channel and a thread" do
let(:side_panel) { PageObjects::Pages::ChatSidePanel.new }
let(:open_thread) { PageObjects::Pages::ChatThread.new }
fab!(:other_user) { Fabricate(:user) }
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, user: other_user) }
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: other_user) }
fab!(:message_3) { Fabricate(:chat_message, chat_channel: channel_1, user: other_user) }
fab!(:thread) { Fabricate(:chat_thread, channel: channel_1) }
fab!(:message_4) do
Fabricate(:chat_message, chat_channel: channel_1, user: other_user, thread: thread)
end
fab!(:message_5) do
Fabricate(:chat_message, chat_channel: channel_1, user: other_user, thread: thread)
end
before do
channel_1.update!(threading_enabled: true)
SiteSetting.enable_experimental_chat_threaded_discussions = true
chat_system_user_bootstrap(user: other_user, channel: channel_1)
end
it "hides the deleted messages" do
chat_page.visit_channel(channel_1)
channel_page.message_thread_indicator(thread.original_message).click
expect(side_panel).to have_open_thread(thread)
expect(channel_page).to have_message(id: message_1.id)
expect(channel_page).to have_message(id: message_2.id)
expect(open_thread).to have_message(thread.id, id: message_4.id)
expect(open_thread).to have_message(thread.id, id: message_5.id)
Chat::Publisher.publish_bulk_delete!(
channel_1,
[message_1.id, message_2.id, message_4.id, message_5.id].flatten,
)
expect(channel_page).to have_no_message(id: message_1.id)
expect(channel_page).to have_no_message(id: message_2.id)
expect(open_thread).to have_no_message(thread.id, id: message_4.id)
expect(open_thread).to have_no_message(thread.id, id: message_5.id)
end
end
end

View File

@ -157,10 +157,19 @@ module PageObjects
end
def has_message?(text: nil, id: nil)
check_message_presence(exists: true, text: text, id: id)
end
def has_no_message?(text: nil, id: nil)
check_message_presence(exists: false, text: text, id: id)
end
def check_message_presence(exists: true, text: nil, id: nil)
css_method = exists ? :has_css? : :has_no_css?
if text
has_css?(".chat-message-text", text: text)
send(css_method, ".chat-message-text", text: text, wait: 5)
elsif id
has_css?(".chat-message-container[data-id=\"#{id}\"]", wait: 10)
send(css_method, ".chat-message-container[data-id=\"#{id}\"]", wait: 10)
end
end

View File

@ -49,10 +49,25 @@ module PageObjects
end
def has_message?(thread_id, text: nil, id: nil)
check_message_presence(thread_id, exists: true, text: text, id: id)
end
def has_no_message?(thread_id, text: nil, id: nil)
check_message_presence(thread_id, exists: false, text: text, id: id)
end
def check_message_presence(thread_id, exists: true, text: nil, id: nil)
css_method = exists ? :has_css? : :has_no_css?
if text
find(thread_selector_by_id(thread_id)).has_css?(".chat-message-text", text: text, wait: 5)
find(thread_selector_by_id(thread_id)).send(
css_method,
".chat-message-text",
text: text,
wait: 5,
)
elsif id
find(thread_selector_by_id(thread_id)).has_css?(
find(thread_selector_by_id(thread_id)).send(
css_method,
".chat-message-container[data-id=\"#{id}\"]",
wait: 10,
)