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.
This commit is contained in:
Loïc Guitaut 2023-08-24 15:22:51 +02:00 committed by Loïc Guitaut
parent 253d4a154c
commit e1ae32103d
36 changed files with 273 additions and 210 deletions

View File

@ -33,15 +33,13 @@ describe Chat::MessageUpdater do
end end
def create_chat_message(user, message, channel, upload_ids: nil) def create_chat_message(user, message, channel, upload_ids: nil)
creator = Fabricate(
Chat::MessageCreator.create( :chat_message,
chat_channel: channel, chat_channel: channel,
user: user, user: user,
in_reply_to_id: nil, message: message,
content: message, upload_ids: upload_ids,
upload_ids: upload_ids, )
)
creator.chat_message
end end
it "errors when length is less than `chat_minimum_message_length`" do it "errors when length is less than `chat_minimum_message_length`" do
@ -643,14 +641,14 @@ describe Chat::MessageUpdater do
it "errors when a blocked word is present" do it "errors when a blocked word is present" do
chat_message = create_chat_message(user1, "something", public_chat_channel) chat_message = create_chat_message(user1, "something", public_chat_channel)
creator = updater =
Chat::MessageCreator.create( Chat::MessageUpdater.update(
chat_channel: public_chat_channel, guardian: guardian,
user: user1, chat_message: chat_message,
content: "bad word - #{watched_word.word}", new_content: "bad word - #{watched_word.word}",
) )
expect(creator.failed?).to eq(true) expect(updater.failed?).to eq(true)
expect(creator.error.message).to match( expect(updater.error.message).to match(
I18n.t("contains_blocked_word", { word: watched_word.word }), I18n.t("contains_blocked_word", { word: watched_word.word }),
) )
end end

View File

@ -49,19 +49,36 @@ Fabricator(:direct_message_channel, from: :chat_channel) do
end end
end end
Fabricator(:chat_message, class_name: "Chat::MessageCreator") do Fabricator(:chat_message, class_name: "Chat::Message") do
transient :chat_channel transient use_service: false
transient :user
transient :message initialize_with do |transients|
transient :in_reply_to Fabricate(
transient :thread transients[:use_service] ? :service_chat_message : :no_service_chat_message,
transient :upload_ids **to_params,
)
end
end
Fabricator(:no_service_chat_message, class_name: "Chat::Message") do
user
chat_channel
message { Faker::Lorem.paragraph_by_chars(number: 500) }
after_build { |message, attrs| message.cook }
after_create { |message, attrs| message.create_mentions }
end
Fabricator(:service_chat_message, class_name: "Chat::MessageCreator") do
transient :chat_channel, :user, :message, :in_reply_to, :thread, :upload_ids
initialize_with do |transients| initialize_with do |transients|
user = transients[:user] || Fabricate(:user)
channel = channel =
transients[:chat_channel] || transients[:thread]&.channel || transients[:chat_channel] || transients[:thread]&.channel ||
transients[:in_reply_to]&.chat_channel || Fabricate(:chat_channel) transients[:in_reply_to]&.chat_channel || Fabricate(:chat_channel)
user = transients[:user] || Fabricate(:user)
Group.refresh_automatic_groups!
channel.add(user)
resolved_class.create( resolved_class.create(
chat_channel: channel, chat_channel: channel,
@ -157,16 +174,14 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
thread.channel = original_message.chat_channel thread.channel = original_message.chat_channel
end end
transient :with_replies transient :with_replies, :channel, :original_message_user, :old_om, use_service: false
transient :channel
transient :original_message_user
transient :old_om
original_message do |attrs| original_message do |attrs|
Fabricate( Fabricate(
:chat_message, :chat_message,
chat_channel: attrs[:channel] || Fabricate(:chat_channel), chat_channel: attrs[:channel] || Fabricate(:chat_channel),
user: attrs[:original_message_user] || Fabricate(:user), user: attrs[:original_message_user] || Fabricate(:user),
use_service: attrs[:use_service],
) )
end end
@ -181,7 +196,12 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
thread.add(thread.original_message_user) thread.add(thread.original_message_user)
if transients[:with_replies] if transients[:with_replies]
Fabricate.times(transients[:with_replies], :chat_message, thread: thread) Fabricate.times(
transients[:with_replies],
:chat_message,
thread: thread,
use_service: transients[:use_service],
)
end end
end end
end end

View File

@ -6,17 +6,19 @@ RSpec.describe Jobs::Chat::MarkAllChannelThreadsRead do
fab!(:thread_2) { Fabricate(:chat_thread, channel: channel) } fab!(:thread_2) { Fabricate(:chat_thread, channel: channel) }
fab!(:user_1) { Fabricate(:user) } fab!(:user_1) { Fabricate(:user) }
fab!(:user_2) { Fabricate(:user) } fab!(:user_2) { Fabricate(:user) }
fab!(:thread_1_message_1) { Fabricate(:chat_message, thread: thread_1) } fab!(:thread_1_message_1) { Fabricate(:chat_message, thread: thread_1, chat_channel: channel) }
fab!(:thread_1_message_2) { Fabricate(:chat_message, thread: thread_1) } fab!(:thread_1_message_2) { Fabricate(:chat_message, thread: thread_1, chat_channel: channel) }
fab!(:thread_1_message_3) { Fabricate(:chat_message, thread: thread_1) } fab!(:thread_1_message_3) { Fabricate(:chat_message, thread: thread_1, chat_channel: channel) }
fab!(:thread_2_message_1) { Fabricate(:chat_message, thread: thread_2) } fab!(:thread_2_message_1) { Fabricate(:chat_message, thread: thread_2, chat_channel: channel) }
fab!(:thread_2_message_2) { Fabricate(:chat_message, thread: thread_2) } fab!(:thread_2_message_2) { Fabricate(:chat_message, thread: thread_2, chat_channel: channel) }
before do before do
channel.add(user_1) channel.add(user_1)
channel.add(user_2) channel.add(user_2)
thread_1.add(user_1) thread_1.add(user_1)
thread_1.update!(last_message: thread_1_message_3)
thread_2.add(user_2) thread_2.add(user_2)
thread_2.update!(last_message: thread_2_message_2)
end end
def unread_count(user) def unread_count(user)

View File

@ -359,10 +359,12 @@ describe Chat::ChannelFetcher do
Chat::DirectMessageUser.create!(direct_message: dm_channel2, user: user1) Chat::DirectMessageUser.create!(direct_message: dm_channel2, user: user1)
Chat::DirectMessageUser.create!(direct_message: dm_channel2, user: user2) Chat::DirectMessageUser.create!(direct_message: dm_channel2, user: user2)
Fabricate(:chat_message, user: user1, chat_channel: direct_message_channel1) dm_1 = Fabricate(:chat_message, user: user1, chat_channel: direct_message_channel1)
Fabricate(:chat_message, user: user1, chat_channel: direct_message_channel2) dm_2 = Fabricate(:chat_message, user: user1, chat_channel: direct_message_channel2)
direct_message_channel1.update!(last_message: dm_1)
direct_message_channel1.last_message.update!(created_at: 1.day.ago) direct_message_channel1.last_message.update!(created_at: 1.day.ago)
direct_message_channel2.update!(last_message: dm_2)
direct_message_channel2.last_message.update!(created_at: 1.hour.ago) direct_message_channel2.last_message.update!(created_at: 1.hour.ago)
expect(described_class.secured_direct_message_channels(user1.id, guardian).map(&:id)).to eq( expect(described_class.secured_direct_message_channels(user1.id, guardian).map(&:id)).to eq(

View File

@ -34,8 +34,11 @@ describe Chat::MessageMover do
fab!(:message4) { Fabricate(:chat_message, chat_channel: destination_channel) } fab!(:message4) { Fabricate(:chat_message, chat_channel: destination_channel) }
fab!(:message5) { Fabricate(:chat_message, chat_channel: destination_channel) } fab!(:message5) { Fabricate(:chat_message, chat_channel: destination_channel) }
fab!(:message6) { Fabricate(:chat_message, chat_channel: destination_channel) } fab!(:message6) { Fabricate(:chat_message, chat_channel: destination_channel) }
let(:move_message_ids) { [message1.id, message2.id, message3.id] } let(:move_message_ids) { [message1.id, message2.id, message3.id] }
before { source_channel.update!(last_message: message3) }
describe "#move_to_channel" do describe "#move_to_channel" do
def move!(move_message_ids = [message1.id, message2.id, message3.id]) def move!(move_message_ids = [message1.id, message2.id, message3.id])
described_class.new( described_class.new(

View File

@ -96,13 +96,7 @@ RSpec.describe Chat::ParsedMentions do
end end
it "returns a user when self-mentioning" do it "returns a user when self-mentioning" do
message = message = create_message("Hey @#{channel_member_1.username}", user: channel_member_1)
Fabricate(
:chat_message,
chat_channel: chat_channel,
message: "Hey @#{channel_member_1.username}",
user: channel_member_1,
)
mentions = described_class.new(message) mentions = described_class.new(message)
@ -174,7 +168,7 @@ RSpec.describe Chat::ParsedMentions do
end end
end end
def create_message(text) def create_message(text, **extra_args)
Fabricate(:chat_message, chat_channel: chat_channel, message: text) Fabricate(:chat_message, chat_channel: chat_channel, message: text, **extra_args)
end end
end end

View File

@ -152,6 +152,11 @@ describe UserNotifications do
) )
end end
before do
channel.add(sender)
channel.update!(last_message: chat_message)
end
it "doesn't return an email if there are no unread mentions" do it "doesn't return an email if there are no unread mentions" do
email = described_class.chat_summary(user, {}) email = described_class.chat_summary(user, {})
@ -272,6 +277,7 @@ describe UserNotifications do
chat_message: another_chat_message, chat_message: another_chat_message,
notification: notification, notification: notification,
) )
another_chat_channel.update!(last_message: another_chat_message)
email = described_class.chat_summary(user, {}) email = described_class.chat_summary(user, {})
@ -311,6 +317,7 @@ describe UserNotifications do
chat_message: another_chat_message, chat_message: another_chat_message,
notification: notification, notification: notification,
) )
another_chat_channel.update!(last_message: another_chat_message)
end end
expected_subject = expected_subject =

View File

@ -24,17 +24,18 @@ module ChatSystemHelpers
user.activate user.activate
user.user_option.update!(chat_enabled: true) user.user_option.update!(chat_enabled: true)
Group.refresh_automatic_group!("trust_level_#{user.trust_level}".to_sym) Group.refresh_automatic_group!("trust_level_#{user.trust_level}".to_sym)
Fabricate(:user_chat_channel_membership, chat_channel: channel, user: user) channel.add(user)
end end
def chat_thread_chain_bootstrap(channel:, users:, messages_count: 4, thread_attrs: {}) def chat_thread_chain_bootstrap(channel:, users:, messages_count: 4, thread_attrs: {})
last_user = nil last_user = nil
last_message = nil last_message = nil
users.each { |user| chat_system_user_bootstrap(user: user, channel: channel) }
messages_count.times do |i| messages_count.times do |i|
in_reply_to = i.zero? ? nil : last_message.id in_reply_to = i.zero? ? nil : last_message.id
thread_id = i.zero? ? nil : last_message.thread_id thread_id = i.zero? ? nil : last_message.thread_id
last_user = last_user.present? ? (users - [last_user]).sample : users.sample last_user = ((users - [last_user]).presence || users).sample
creator = creator =
Chat::MessageCreator.new( Chat::MessageCreator.new(
chat_channel: channel, chat_channel: channel,

View File

@ -17,12 +17,12 @@ describe Chat do
fab!(:unused_upload) { Fabricate(:upload, user: user, created_at: 1.month.ago) } fab!(:unused_upload) { Fabricate(:upload, user: user, created_at: 1.month.ago) }
let!(:chat_message) do let!(:chat_message) do
Chat::MessageCreator.create( Fabricate(
:chat_message,
chat_channel: chat_channel, chat_channel: chat_channel,
user: user, user: user,
in_reply_to_id: nil, message: "Hello world!",
content: "Hello world!", uploads: [upload],
upload_ids: [upload.id],
) )
end end
@ -43,15 +43,13 @@ describe Chat do
fab!(:unused_upload) { Fabricate(:upload, user: user, created_at: 1.month.ago) } fab!(:unused_upload) { Fabricate(:upload, user: user, created_at: 1.month.ago) }
let!(:chat_message) do let!(:chat_message) do
Chat::MessageCreator.create( Fabricate(
:chat_message,
chat_channel: chat_channel, chat_channel: chat_channel,
user: user, user: user,
in_reply_to_id: nil, message: "Hello world! #{message_upload.sha1}",
content: "Hello world! #{message_upload.sha1}",
upload_ids: [],
) )
end end
let!(:draft_message) do let!(:draft_message) do
Chat::Draft.create!( Chat::Draft.create!(
user: user, user: user,
@ -135,17 +133,16 @@ describe Chat do
fab!(:user_4) { Fabricate(:user, suspended_till: 3.weeks.from_now) } fab!(:user_4) { Fabricate(:user, suspended_till: 3.weeks.from_now) }
let!(:chat_message) do let!(:chat_message) do
Chat::MessageCreator.create( Fabricate(:chat_message, chat_channel: chat_channel, user: user, message: "Hello world!")
chat_channel: chat_channel,
user: user,
in_reply_to_id: nil,
content: "Hello world!",
upload_ids: [],
).chat_message
end end
let(:chat_url) { "#{Discourse.base_url}/chat/c/-/#{chat_channel.id}" } let(:chat_url) { "#{Discourse.base_url}/chat/c/-/#{chat_channel.id}" }
before do
chat_channel.update!(last_message: chat_message)
chat_channel.add(user)
end
context "when inline" do context "when inline" do
it "renders channel" do it "renders channel" do
results = InlineOneboxer.new([chat_url], skip_cache: true).process results = InlineOneboxer.new([chat_url], skip_cache: true).process
@ -166,7 +163,6 @@ describe Chat do
context "when regular" do context "when regular" do
it "renders channel, excluding inactive, staged, and suspended users" do it "renders channel, excluding inactive, staged, and suspended users" do
user.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true)
user_2.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true) user_2.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true)
user_3.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true) user_3.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true)
user_4.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true) user_4.user_chat_channel_memberships.create!(chat_channel: chat_channel, following: true)

View File

@ -119,6 +119,7 @@ RSpec.describe Chat::Admin::IncomingWebhooksController do
describe "#delete" do describe "#delete" do
fab!(:existing) { Fabricate(:incoming_chat_webhook, chat_channel: chat_channel1) } fab!(:existing) { Fabricate(:incoming_chat_webhook, chat_channel: chat_channel1) }
fab!(:webhook_event) { Fabricate(:chat_webhook_event, incoming_chat_webhook: existing) }
it "errors for non-staff" do it "errors for non-staff" do
sign_in(user) sign_in(user)
@ -136,13 +137,6 @@ RSpec.describe Chat::Admin::IncomingWebhooksController do
it "destroys webhook events records" do it "destroys webhook events records" do
sign_in(admin) sign_in(admin)
Chat::MessageCreator.create(
chat_channel: existing.chat_channel,
user: Discourse.system_user,
content: "foo",
incoming_chat_webhook: existing,
)
expect { delete "/admin/plugins/chat/hooks/#{existing.id}.json" }.to change { expect { delete "/admin/plugins/chat/hooks/#{existing.id}.json" }.to change {
Chat::WebhookEvent.count Chat::WebhookEvent.count
}.by(-1) }.by(-1)

View File

@ -17,8 +17,8 @@ RSpec.describe Chat::Api::ChannelThreadMessagesController do
describe "index" do describe "index" do
describe "success" do describe "success" do
fab!(:message_1) { Fabricate(:chat_message, thread: thread) } fab!(:message_1) { Fabricate(:chat_message, thread: thread, chat_channel: thread.channel) }
fab!(:message_2) { Fabricate(:chat_message) } fab!(:message_2) { Fabricate(:chat_message, chat_channel: thread.channel) }
it "works" do it "works" do
get "/chat/api/channels/#{thread.channel.id}/threads/#{thread.id}/messages" get "/chat/api/channels/#{thread.channel.id}/threads/#{thread.id}/messages"

View File

@ -106,6 +106,11 @@ RSpec.describe Chat::Api::ChannelThreadsController do
) )
end end
before do
thread_1.add(current_user)
thread_3.add(current_user)
end
it "returns the threads the user has sent messages in for the channel" do it "returns the threads the user has sent messages in for the channel" do
get "/chat/api/channels/#{public_channel.id}/threads" get "/chat/api/channels/#{public_channel.id}/threads"
expect(response.status).to eq(200) expect(response.status).to eq(200)

View File

@ -10,6 +10,7 @@ RSpec.describe Chat::Api::ChannelThreadsCurrentUserNotificationsSettingsControll
SiteSetting.chat_enabled = true SiteSetting.chat_enabled = true
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone] SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
sign_in(current_user) sign_in(current_user)
thread.update!(last_message: last_reply)
end end
describe "#update" do describe "#update" do

View File

@ -133,6 +133,12 @@ RSpec.describe Chat::Api::ReadsController do
) )
end end
before do
chat_channel_1.update!(last_message: message_2)
chat_channel_2.update!(last_message: message_4)
chat_channel_3.update!(last_message: message_6)
end
it "marks all messages as read across the user's channel memberships with the correct last_read_message_id" do it "marks all messages as read across the user's channel memberships with the correct last_read_message_id" do
put "/chat/api/channels/read.json" put "/chat/api/channels/read.json"

View File

@ -126,13 +126,15 @@ RSpec.describe ::Chat::LookupChannelThreads do
[thread_2, 1.day.ago], [thread_2, 1.day.ago],
[thread_3, 2.seconds.ago], [thread_3, 2.seconds.ago],
].each do |thread, created_at| ].each do |thread, created_at|
Fabricate( message =
:chat_message, Fabricate(
user: current_user, :chat_message,
chat_channel: channel_1, user: current_user,
thread: thread, chat_channel: channel_1,
created_at: created_at, thread: thread,
) created_at: created_at,
)
thread.update!(last_message: message)
end end
expect(result.threads.map(&:id)).to eq([thread_3.id, thread_1.id, thread_2.id]) expect(result.threads.map(&:id)).to eq([thread_3.id, thread_1.id, thread_2.id])
@ -141,6 +143,7 @@ RSpec.describe ::Chat::LookupChannelThreads do
it "sorts by unread over recency" do it "sorts by unread over recency" do
unread_message = Fabricate(:chat_message, chat_channel: channel_1, thread: thread_2) unread_message = Fabricate(:chat_message, chat_channel: channel_1, thread: thread_2)
unread_message.update!(created_at: 2.days.ago) unread_message.update!(created_at: 2.days.ago)
thread_2.update!(last_message: unread_message)
expect(result.threads.map(&:id)).to eq([thread_2.id, thread_1.id, thread_3.id]) expect(result.threads.map(&:id)).to eq([thread_2.id, thread_1.id, thread_3.id])
end end

View File

@ -47,6 +47,12 @@ RSpec.describe Chat::MarkAllUserChannelsRead do
) )
end end
before do
channel_1.update!(last_message: message_2)
channel_2.update!(last_message: message_4)
channel_3.update!(last_message: message_6)
end
context "when the user has no memberships" do context "when the user has no memberships" do
let(:guardian) { Guardian.new(Fabricate(:user)) } let(:guardian) { Guardian.new(Fabricate(:user)) }
@ -170,6 +176,7 @@ RSpec.describe Chat::MarkAllUserChannelsRead do
it "does use thread original messages for last_read_message_id" do it "does use thread original messages for last_read_message_id" do
new_om = Fabricate(:chat_message, chat_channel: channel_1, user: other_user) new_om = Fabricate(:chat_message, chat_channel: channel_1, user: other_user)
channel_1.update!(last_message: new_om)
thread.update!(original_message: new_om, original_message_user: other_user) thread.update!(original_message: new_om, original_message_user: other_user)
result result
expect(membership_1.reload.last_read_message_id).to eq(new_om.id) expect(membership_1.reload.last_read_message_id).to eq(new_om.id)

View File

@ -25,6 +25,7 @@ RSpec.describe Chat::MessageDestroyer do
message_2 = Fabricate(:chat_message, chat_channel: message_1.chat_channel) message_2 = Fabricate(:chat_message, chat_channel: message_1.chat_channel)
message_3 = Fabricate(:chat_message, chat_channel: message_1.chat_channel) message_3 = Fabricate(:chat_message, chat_channel: message_1.chat_channel)
message_4 = Fabricate(:chat_message, chat_channel: message_1.chat_channel) message_4 = Fabricate(:chat_message, chat_channel: message_1.chat_channel)
message_1.chat_channel.update(last_message: message_4)
message_3.trash! message_3.trash!
membership = membership =
Chat::UserChatChannelMembership.create!( Chat::UserChatChannelMembership.create!(
@ -64,7 +65,7 @@ RSpec.describe Chat::MessageDestroyer do
end end
it "sets the last_message_id for the channel if that message is deleted" do it "sets the last_message_id for the channel if that message is deleted" do
expect(message_1.chat_channel.last_message_id).to eq(message_1.id) message_1.chat_channel.update!(last_message: message_1)
described_class.new.destroy_in_batches(Chat::Message.where(id: message_1.id)) described_class.new.destroy_in_batches(Chat::Message.where(id: message_1.id))
expect(message_1.chat_channel.reload.last_message_id).to eq(nil) expect(message_1.chat_channel.reload.last_message_id).to eq(nil)
end end

View File

@ -58,7 +58,7 @@ RSpec.describe Chat::RestoreMessage do
it "does not update the channel last_message_id if the message is not the last one in the channel" do it "does not update the channel last_message_id if the message is not the last one in the channel" do
next_message = Fabricate(:chat_message, chat_channel: message.chat_channel) next_message = Fabricate(:chat_message, chat_channel: message.chat_channel)
expect(message.chat_channel.reload.last_message_id).to eq(next_message.id) message.chat_channel.update!(last_message: next_message)
result result
expect(message.chat_channel.reload.last_message_id).to eq(next_message.id) expect(message.chat_channel.reload.last_message_id).to eq(next_message.id)
end end
@ -97,10 +97,10 @@ RSpec.describe Chat::RestoreMessage do
end end
it "does not update the thread last_message_id if the message is not the last one in the channel" do it "does not update the thread last_message_id if the message is not the last one in the channel" do
next_message = Fabricate(:chat_message, thread: message.thread) next_message =
expect(message.thread.reload.last_message_id).to eq(next_message.id) Fabricate(:chat_message, thread: message.thread, chat_channel: message.chat_channel)
result message.thread.update!(last_message: next_message)
expect(message.thread.reload.last_message_id).to eq(next_message.id) expect { result }.not_to change { message.thread.reload.last_message }
end end
end end
end end

View File

@ -124,7 +124,7 @@ RSpec.describe Chat::TrashMessage do
next_message = next_message =
Fabricate(:chat_message, chat_channel: message.chat_channel, user: current_user) Fabricate(:chat_message, chat_channel: message.chat_channel, user: current_user)
params[:message_id] = next_message.id params[:message_id] = next_message.id
expect(message.chat_channel.reload.last_message).to eq(next_message) message.chat_channel.update!(last_message: next_message)
result result
expect(message.chat_channel.reload.last_message).to eq(message) expect(message.chat_channel.reload.last_message).to eq(message)
end end
@ -174,9 +174,15 @@ RSpec.describe Chat::TrashMessage do
end end
it "updates the thread last_message_id to the previous message in the thread" do it "updates the thread last_message_id to the previous message in the thread" do
next_message = Fabricate(:chat_message, thread: thread, user: current_user) next_message =
Fabricate(
:chat_message,
thread: thread,
user: current_user,
chat_channel: message.chat_channel,
)
params[:message_id] = next_message.id params[:message_id] = next_message.id
expect(thread.reload.last_message).to eq(next_message) thread.update!(last_message: next_message)
result result
expect(thread.reload.last_message).to eq(message) expect(thread.reload.last_message).to eq(message)
end end

View File

@ -26,6 +26,8 @@ RSpec.describe Chat::UpdateThreadNotificationSettings do
} }
end end
before { thread.update!(last_message: last_reply) }
context "when all steps pass" do context "when all steps pass" do
it "sets the service result as successful" do it "sets the service result as successful" do
expect(result).to be_a_success expect(result).to be_a_success

View File

@ -65,19 +65,21 @@ RSpec.describe "Archive channel", type: :system do
end end
context "when archived channels had unreads" do context "when archived channels had unreads" do
before { channel_1.add(current_user) } let(:other_user) { Fabricate(:user) }
it "clears unread indicators" do before do
Jobs.run_immediately! Jobs.run_immediately!
channel_1.add(current_user)
other_user = Fabricate(:user) Fabricate(
channel_1.add(other_user) :chat_message,
Chat::MessageCreator.create(
chat_channel: channel_1, chat_channel: channel_1,
user: other_user, user: other_user,
content: "this is fine @#{current_user.username}", message: "this is fine @#{current_user.username}",
use_service: true,
) )
end
it "clears unread indicators" do
visit("/") visit("/")
expect(page.find(".chat-channel-unread-indicator")).to have_content(1) expect(page.find(".chat-channel-unread-indicator")).to have_content(1)

View File

@ -75,8 +75,10 @@ RSpec.describe "Chat | composer | shortcuts | channel", type: :system do
end end
context "when using ArrowUp" do context "when using ArrowUp" do
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) } fab!(:message_1) do
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1) } Fabricate(:chat_message, chat_channel: channel_1, user: current_user, use_service: true)
end
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, use_service: true) }
it "edits last editable message" do it "edits last editable message" do
chat.visit_channel(channel_1) chat.visit_channel(channel_1)

View File

@ -3,8 +3,10 @@
RSpec.describe "Chat | composer | shortcuts | thread", type: :system do RSpec.describe "Chat | composer | shortcuts | thread", type: :system do
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) } fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
fab!(:current_user) { Fabricate(:admin) } fab!(:current_user) { Fabricate(:admin) }
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) } fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, use_service: true) }
fab!(:thread_1) { Fabricate(:chat_message, user: current_user, in_reply_to: message_1).thread } fab!(:thread_1) do
Fabricate(:chat_message, user: current_user, in_reply_to: message_1, use_service: true).thread
end
let(:chat_page) { PageObjects::Pages::Chat.new } let(:chat_page) { PageObjects::Pages::Chat.new }
let(:thread_page) { PageObjects::Pages::ChatThread.new } let(:thread_page) { PageObjects::Pages::ChatThread.new }
@ -32,7 +34,7 @@ RSpec.describe "Chat | composer | shortcuts | thread", type: :system do
let(:last_thread_message) { thread_1.replies.last } let(:last_thread_message) { thread_1.replies.last }
context "when there are editable messages" do context "when there are editable messages" do
before { Fabricate(:chat_message, user: current_user, thread: thread_1) } before { Fabricate(:chat_message, user: current_user, thread: thread_1, use_service: true) }
it "starts editing the last editable message" do it "starts editing the last editable message" do
chat_page.visit_thread(thread_1) chat_page.visit_thread(thread_1)

View File

@ -3,9 +3,11 @@
RSpec.describe "Chat | composer | thread", type: :system, js: true do RSpec.describe "Chat | composer | thread", type: :system, js: true do
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) } fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
fab!(:current_user) { Fabricate(:admin) } fab!(:current_user) { Fabricate(:admin) }
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) } fab!(:message_1) do
Fabricate(:chat_message, chat_channel: channel_1, user: current_user, use_service: true)
end
fab!(:message_2) do fab!(:message_2) do
Fabricate(:chat_message, chat_channel: channel_1, user: current_user, in_reply_to: message_1) Fabricate(:chat_message, user: current_user, in_reply_to: message_1, use_service: true)
end end
let(:chat_page) { PageObjects::Pages::Chat.new } let(:chat_page) { PageObjects::Pages::Chat.new }

View File

@ -4,8 +4,8 @@ RSpec.describe "Chat message - thread", type: :system do
fab!(:current_user) { Fabricate(:user) } fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) } fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
fab!(:thread_message_1) do fab!(:thread_message_1) do
message_1 = Fabricate(:chat_message, chat_channel: channel_1) message_1 = Fabricate(:chat_message, chat_channel: channel_1, use_service: true)
Fabricate(:chat_message, chat_channel: channel_1, in_reply_to: message_1) Fabricate(:chat_message, in_reply_to: message_1, use_service: true)
end end
let(:chat_page) { PageObjects::Pages::Chat.new } let(:chat_page) { PageObjects::Pages::Chat.new }

View File

@ -59,9 +59,8 @@ describe "Thread indicator for chat messages", type: :system do
it "it shows the reply count but no participant avatars when there is only one participant" do it "it shows the reply count but no participant avatars when there is only one participant" do
single_user_thread = single_user_thread =
Fabricate(:chat_thread, channel: channel, original_message_user: current_user) chat_thread_chain_bootstrap(channel: channel, users: [current_user], messages_count: 3)
Fabricate(:chat_message, thread: single_user_thread, user: current_user)
Fabricate(:chat_message, thread: single_user_thread, user: current_user)
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
expect( expect(
channel_page.message_thread_indicator(single_user_thread.original_message), channel_page.message_thread_indicator(single_user_thread.original_message),

View File

@ -122,11 +122,11 @@ RSpec.describe "Navigation", type: :system do
end end
context "when opening a thread" do context "when opening a thread" do
fab!(:thread) { Fabricate(:chat_thread, channel: category_channel) } fab!(:thread) { Fabricate(:chat_thread, channel: category_channel, use_service: true) }
before do before do
category_channel.update!(threading_enabled: true) category_channel.update!(threading_enabled: true)
Fabricate(:chat_message, thread: thread, chat_channel: thread.channel) Fabricate(:chat_message, thread: thread, use_service: true)
thread.add(current_user) thread.add(current_user)
end end
@ -335,7 +335,7 @@ RSpec.describe "Navigation", type: :system do
it "activates the channel in the sidebar" do it "activates the channel in the sidebar" do
visit("/") visit("/")
chat_page.open_from_header chat_page.open_from_header
sidebar_component.click_link(category_channel.name) sidebar_component.click_section_link(category_channel.name)
expect(sidebar_component).to have_section_link(category_channel.name, active: true) expect(sidebar_component).to have_section_link(category_channel.name, active: true)
end end
@ -346,7 +346,7 @@ RSpec.describe "Navigation", type: :system do
visit("/") visit("/")
chat_page.open_from_header chat_page.open_from_header
sidebar_component.click_link(category_channel.name) sidebar_component.click_section_link(category_channel.name)
chat_drawer_page.close chat_drawer_page.close
expect(sidebar_component).to have_no_section_link(category_channel.name, active: true) expect(sidebar_component).to have_no_section_link(category_channel.name, active: true)

View File

@ -12,8 +12,8 @@ RSpec.describe "Reply to message - channel - drawer", type: :system do
Fabricate( Fabricate(
:chat_message, :chat_message,
chat_channel: channel_1, chat_channel: channel_1,
user: Fabricate(:user),
message: "This is a message to reply to!", message: "This is a message to reply to!",
use_service: true,
) )
end end
@ -44,17 +44,7 @@ RSpec.describe "Reply to message - channel - drawer", type: :system do
end end
context "when the message has an existing thread" do context "when the message has an existing thread" do
fab!(:message_1) do fab!(:message_1) { Fabricate(:chat_message, in_reply_to: original_message, use_service: true) }
creator =
Chat::MessageCreator.new(
chat_channel: channel_1,
in_reply_to_id: original_message.id,
user: Fabricate(:user),
content: Faker::Lorem.paragraph,
)
creator.create
creator.chat_message
end
it "replies to the existing thread" do it "replies to the existing thread" do
visit("/") visit("/")

View File

@ -12,8 +12,8 @@ RSpec.describe "Reply to message - channel - full page", type: :system do
Fabricate( Fabricate(
:chat_message, :chat_message,
chat_channel: channel_1, chat_channel: channel_1,
user: Fabricate(:user),
message: "This is a message to reply to!", message: "This is a message to reply to!",
use_service: true,
) )
end end
@ -56,9 +56,7 @@ RSpec.describe "Reply to message - channel - full page", type: :system do
end end
context "when the message has an existing thread" do context "when the message has an existing thread" do
fab!(:message_1) do fab!(:message_1) { Fabricate(:chat_message, in_reply_to: original_message, use_service: true) }
Fabricate(:chat_message, chat_channel: channel_1, in_reply_to: original_message)
end
before { original_message.thread.add(current_user) } before { original_message.thread.add(current_user) }

View File

@ -12,8 +12,8 @@ RSpec.describe "Reply to message - channel - mobile", type: :system, mobile: tru
Fabricate( Fabricate(
:chat_message, :chat_message,
chat_channel: channel_1, chat_channel: channel_1,
user: Fabricate(:user),
message: "This is a message to reply to!", message: "This is a message to reply to!",
use_service: true,
) )
end end
@ -56,9 +56,7 @@ RSpec.describe "Reply to message - channel - mobile", type: :system, mobile: tru
end end
context "when the message has an existing thread" do context "when the message has an existing thread" do
fab!(:message_1) do fab!(:message_1) { Fabricate(:chat_message, in_reply_to: original_message, use_service: true) }
Fabricate(:chat_message, chat_channel: channel_1, in_reply_to: original_message)
end
it "replies to the existing thread" do it "replies to the existing thread" do
chat_page.visit_channel(channel_1) chat_page.visit_channel(channel_1)

View File

@ -14,10 +14,15 @@ RSpec.describe "Shortcuts | mark all read", type: :system do
SiteSetting.navigation_menu = "sidebar" SiteSetting.navigation_menu = "sidebar"
chat_system_bootstrap(user_1, [channel_1, channel_2, channel_3]) chat_system_bootstrap(user_1, [channel_1, channel_2, channel_3])
sign_in(user_1) sign_in(user_1)
Fabricate(:chat_message, chat_channel: channel_1) Fabricate(:chat_message, chat_channel: channel_1, use_service: true)
Fabricate(:chat_message, chat_channel: channel_1) Fabricate(:chat_message, chat_channel: channel_1, use_service: true)
10.times do |i| 10.times do |i|
Fabricate(:chat_message, chat_channel: channel_2, message: "all read message #{i}") Fabricate(
:chat_message,
chat_channel: channel_2,
message: "all read message #{i}",
use_service: true,
)
end end
end end

View File

@ -17,6 +17,7 @@ describe "Single thread in side panel", type: :system do
context "when threading_enabled is false for the channel" do context "when threading_enabled is false for the channel" do
fab!(:channel) { Fabricate(:chat_channel) } fab!(:channel) { Fabricate(:chat_channel) }
before { channel.update!(threading_enabled: false) } before { channel.update!(threading_enabled: false) }
it "does not open the side panel for a single thread" do it "does not open the side panel for a single thread" do
@ -116,7 +117,7 @@ describe "Single thread in side panel", type: :system do
end end
it "changes the tracking bell to be Tracking level in the thread panel" do it "changes the tracking bell to be Tracking level in the thread panel" do
new_thread = Fabricate(:chat_thread, channel: channel, with_replies: 1) new_thread = Fabricate(:chat_thread, channel: channel, with_replies: 1, use_service: true)
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
channel_page.message_thread_indicator(new_thread.original_message).click channel_page.message_thread_indicator(new_thread.original_message).click
expect(side_panel).to have_open_thread(new_thread) expect(side_panel).to have_open_thread(new_thread)
@ -171,11 +172,12 @@ describe "Single thread in side panel", type: :system do
it "does not mark the channel unread if another user sends a message in the thread" do it "does not mark the channel unread if another user sends a message in the thread" do
other_user = Fabricate(:user) other_user = Fabricate(:user)
chat_system_user_bootstrap(user: other_user, channel: channel) chat_system_user_bootstrap(user: other_user, channel: channel)
Chat::MessageCreator.create( Fabricate(
chat_channel: channel, :chat_message,
thread: thread,
user: other_user, user: other_user,
content: "Hello world!", message: "Hello world!",
thread_id: thread.id, use_service: true,
) )
sign_in(current_user) sign_in(current_user)
chat_page.visit_channel(channel) chat_page.visit_channel(channel)

View File

@ -26,12 +26,12 @@ describe "Thread list in side panel | full page", type: :system do
end end
context "for threads the user is not a participant in" do context "for threads the user is not a participant in" do
fab!(:thread_om) { Fabricate(:chat_message, chat_channel: channel) } fab!(:thread_om) { Fabricate(:chat_message, chat_channel: channel, use_service: true) }
before { chat_system_user_bootstrap(user: other_user, channel: channel) } before { chat_system_user_bootstrap(user: other_user, channel: channel) }
it "does not show existing threads in the channel if the user is not tracking them" do it "does not show existing threads in the channel if the user is not tracking them" do
Fabricate(:chat_thread, original_message: thread_om, channel: channel) Fabricate(:chat_thread, original_message: thread_om, channel: channel, use_service: true)
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
channel_page.open_thread_list channel_page.open_thread_list
expect(page).to have_content(I18n.t("js.chat.threads.none")) expect(page).to have_content(I18n.t("js.chat.threads.none"))
@ -118,7 +118,7 @@ describe "Thread list in side panel | full page", type: :system do
it "shows the last reply date of the thread" do it "shows the last reply date of the thread" do
freeze_time freeze_time
last_reply = Fabricate(:chat_message, chat_channel: thread_1.channel, thread: thread_1) last_reply = Fabricate(:chat_message, thread: thread_1, use_service: true)
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
channel_page.open_thread_list channel_page.open_thread_list
expect(thread_list_page.item_by_id(thread_1.id)).to have_css( expect(thread_list_page.item_by_id(thread_1.id)).to have_css(

View File

@ -23,9 +23,9 @@ describe "Thread tracking state | drawer", type: :system do
context "when the user has unread messages for a thread" do context "when the user has unread messages for a thread" do
fab!(:message_1) do fab!(:message_1) do
Fabricate(:chat_message, chat_channel: channel, thread: thread, user: current_user) Fabricate(:chat_message, thread: thread, user: current_user, use_service: true)
end end
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel, thread: thread) } fab!(:message_2) { Fabricate(:chat_message, thread: thread, use_service: true) }
it "shows the count of threads with unread messages on the thread list button" do it "shows the count of threads with unread messages on the thread list button" do
visit("/") visit("/")
@ -63,7 +63,7 @@ describe "Thread tracking state | drawer", type: :system do
expect(drawer_page).to have_no_unread_thread_indicator expect(drawer_page).to have_no_unread_thread_indicator
expect(thread_list_page).to have_no_unread_item(thread.id) expect(thread_list_page).to have_no_unread_item(thread.id)
travel_to(1.minute.from_now) travel_to(1.minute.from_now)
Fabricate(:chat_message, chat_channel: channel, thread: thread, user: other_user) Fabricate(:chat_message, thread: thread, user: other_user, use_service: true)
expect(drawer_page).to have_unread_thread_indicator(count: 1) expect(drawer_page).to have_unread_thread_indicator(count: 1)
expect(thread_list_page).to have_unread_item(thread.id) expect(thread_list_page).to have_unread_item(thread.id)
end end
@ -100,7 +100,7 @@ describe "Thread tracking state | drawer", type: :system do
chat_page.open_from_header chat_page.open_from_header
expect(drawer_page).to have_unread_channel(channel) expect(drawer_page).to have_unread_channel(channel)
drawer_page.open_channel(channel) drawer_page.open_channel(channel)
Fabricate(:chat_message, thread: thread, user: other_user) Fabricate(:chat_message, thread: thread, user: other_user, use_service: true)
drawer_page.back drawer_page.back
expect(drawer_page).to have_no_unread_channel(channel) expect(drawer_page).to have_no_unread_channel(channel)
end end
@ -112,7 +112,7 @@ describe "Thread tracking state | drawer", type: :system do
drawer_page.back drawer_page.back
expect(drawer_page).to have_no_unread_channel(channel) expect(drawer_page).to have_no_unread_channel(channel)
travel_to(1.minute.from_now) travel_to(1.minute.from_now)
Fabricate(:chat_message, thread: thread, user: other_user) Fabricate(:chat_message, thread: thread, user: other_user, use_service: true)
expect(drawer_page).to have_unread_channel(channel) expect(drawer_page).to have_unread_channel(channel)
end end
end end

View File

@ -20,9 +20,9 @@ describe "Thread tracking state | full page", type: :system do
context "when the user has unread messages for a thread" do context "when the user has unread messages for a thread" do
fab!(:message_1) do fab!(:message_1) do
Fabricate(:chat_message, chat_channel: channel, thread: thread, user: current_user) Fabricate(:chat_message, thread: thread, user: current_user, use_service: true)
end end
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel, thread: thread) } fab!(:message_2) { Fabricate(:chat_message, thread: thread, use_service: true) }
it "shows the count of threads with unread messages on the thread list button" do it "shows the count of threads with unread messages on the thread list button" do
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
@ -55,7 +55,7 @@ describe "Thread tracking state | full page", type: :system do
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
channel_page.open_thread_list channel_page.open_thread_list
expect(thread_list_page).to have_no_unread_item(thread.id) expect(thread_list_page).to have_no_unread_item(thread.id)
Fabricate(:chat_message, chat_channel: channel, thread: thread) Fabricate(:chat_message, thread: thread, use_service: true)
expect(thread_list_page).to have_unread_item(thread.id) expect(thread_list_page).to have_unread_item(thread.id)
end end
@ -63,7 +63,7 @@ describe "Thread tracking state | full page", type: :system do
thread.remove(current_user) thread.remove(current_user)
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
expect(channel_page).to have_no_unread_thread_indicator expect(channel_page).to have_no_unread_thread_indicator
Fabricate(:chat_message, chat_channel: channel, thread: thread) Fabricate(:chat_message, thread: thread, use_service: true)
expect(channel_page).to have_no_unread_thread_indicator expect(channel_page).to have_no_unread_thread_indicator
channel_page.open_thread_list channel_page.open_thread_list
expect(thread_list_page).to have_no_unread_item(thread.id) expect(thread_list_page).to have_no_unread_item(thread.id)
@ -76,8 +76,8 @@ describe "Thread tracking state | full page", type: :system do
end end
it "allows the user to start tracking a thread they have not replied to" do it "allows the user to start tracking a thread they have not replied to" do
new_thread = Fabricate(:chat_thread, channel: channel) new_thread = Fabricate(:chat_thread, channel: channel, use_service: true)
Fabricate(:chat_message, chat_channel: channel, thread: new_thread) Fabricate(:chat_message, thread: new_thread, use_service: true)
chat_page.visit_thread(new_thread) chat_page.visit_thread(new_thread)
thread_page.notification_level = :tracking thread_page.notification_level = :tracking
expect(thread_page).to have_notification_level("tracking") expect(thread_page).to have_notification_level("tracking")
@ -114,7 +114,7 @@ describe "Thread tracking state | full page", type: :system do
it "does not show an unread indicator for the channel sidebar if a new thread message arrives while the user is looking at the channel" do it "does not show an unread indicator for the channel sidebar if a new thread message arrives while the user is looking at the channel" do
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
expect(sidebar_page).to have_no_unread_channel(channel) expect(sidebar_page).to have_no_unread_channel(channel)
Fabricate(:chat_message, thread: thread) Fabricate(:chat_message, thread: thread, use_service: true)
expect(sidebar_page).to have_no_unread_channel(channel) expect(sidebar_page).to have_no_unread_channel(channel)
end end
@ -122,7 +122,7 @@ describe "Thread tracking state | full page", type: :system do
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
expect(sidebar_page).to have_no_unread_channel(channel) expect(sidebar_page).to have_no_unread_channel(channel)
chat_page.visit_channel(other_channel) chat_page.visit_channel(other_channel)
Fabricate(:chat_message, thread: thread) Fabricate(:chat_message, thread: thread, use_service: true)
expect(sidebar_page).to have_unread_channel(channel) expect(sidebar_page).to have_unread_channel(channel)
end end
end end

View File

@ -39,17 +39,20 @@ RSpec.describe "User menu notifications | sidebar", type: :system do
context "when dm channel" do context "when dm channel" do
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, other_user]) } fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, other_user]) }
before { Jobs.run_immediately! }
context "when @username" do context "when @username" do
let!(:message) do
Fabricate(
:chat_message,
chat_channel: dm_channel_1,
user: other_user,
message: "this is fine @#{current_user.username}",
use_service: true,
)
end
it "shows a mention notification" do it "shows a mention notification" do
Jobs.run_immediately!
message =
Chat::MessageCreator.create(
chat_channel: dm_channel_1,
user: other_user,
content: "this is fine @#{current_user.username}",
).chat_message
visit("/") visit("/")
find(".header-dropdown-toggle.current-user").click find(".header-dropdown-toggle.current-user").click
@ -69,24 +72,30 @@ RSpec.describe "User menu notifications | sidebar", type: :system do
fab!(:channel_1) { Fabricate(:chat_channel) } fab!(:channel_1) { Fabricate(:chat_channel) }
before do before do
Jobs.run_immediately!
channel_1.add(current_user) channel_1.add(current_user)
channel_1.add(other_user) channel_1.add(other_user)
# Jobs.run_immediately!
end end
context "when group mention" do context "when group mention" do
fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) } fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
before { group.add(current_user) } let(:message) do
Fabricate(
:chat_message,
chat_channel: channel_1,
user: other_user,
message: "this is fine @#{group.name}",
use_service: true,
)
end
xit "shows a group mention notification" do before do
message = group.add(current_user)
Chat::MessageCreator.create( message
chat_channel: channel_1, end
user: other_user,
content: "this is fine @#{group.name}",
).chat_message
it "shows a group mention notification" do
visit("/") visit("/")
find(".header-dropdown-toggle.current-user").click find(".header-dropdown-toggle.current-user").click
@ -106,16 +115,17 @@ RSpec.describe "User menu notifications | sidebar", type: :system do
end end
context "when @username" do context "when @username" do
let!(:message) do
Fabricate(
:chat_message,
chat_channel: channel_1,
user: other_user,
message: "this is fine @#{current_user.username}",
use_service: true,
)
end
it "shows a mention notification" do it "shows a mention notification" do
Jobs.run_immediately!
message =
Chat::MessageCreator.create(
chat_channel: channel_1,
user: other_user,
content: "this is fine @#{current_user.username}",
).chat_message
visit("/") visit("/")
find(".header-dropdown-toggle.current-user").click find(".header-dropdown-toggle.current-user").click
@ -130,41 +140,46 @@ RSpec.describe "User menu notifications | sidebar", type: :system do
) )
end end
it "shows a mention notification when the message is in a thread" do context "when the message is in a thread" do
Jobs.run_immediately! let!(:message) do
Fabricate(
message = :chat_message,
Chat::MessageCreator.create( thread: Fabricate(:chat_thread, channel: channel_1),
chat_channel: channel_1,
user: other_user, user: other_user,
content: "this is fine @#{current_user.username}", message: "this is fine @#{current_user.username}",
thread_id: Fabricate(:chat_thread, channel: channel_1).id, use_service: true,
).chat_message )
visit("/")
find(".header-dropdown-toggle.current-user").click
within("#user-menu-button-chat-notifications") do |panel|
expect(panel).to have_content(1)
panel.click
end end
expect(find("#quick-access-chat-notifications")).to have_link( it "shows a mention notification when the message is in a thread" do
I18n.t("js.notifications.popup.chat_mention.direct", channel: channel_1.name), visit("/")
href: "/chat/c/#{channel_1.slug}/#{channel_1.id}/t/#{message.thread_id}",
) find(".header-dropdown-toggle.current-user").click
within("#user-menu-button-chat-notifications") do |panel|
expect(panel).to have_content(1)
panel.click
end
expect(find("#quick-access-chat-notifications")).to have_link(
I18n.t("js.notifications.popup.chat_mention.direct", channel: channel_1.name),
href: "/chat/c/#{channel_1.slug}/#{channel_1.id}/t/#{message.thread_id}",
)
end
end end
end end
context "when @all" do context "when @all" do
xit "shows a mention notification" do let!(:message) do
message = Fabricate(
Chat::MessageCreator.create( :chat_message,
chat_channel: channel_1, chat_channel: channel_1,
user: other_user, user: other_user,
content: "this is fine @all", message: "this is fine @all",
).chat_message use_service: true,
)
end
it "shows a mention notification" do
visit("/") visit("/")
find(".header-dropdown-toggle.current-user").click find(".header-dropdown-toggle.current-user").click