mirror of
https://github.com/discourse/discourse.git
synced 2025-02-09 12:54:56 +00:00
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.
228 lines
6.7 KiB
Ruby
228 lines
6.7 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
RSpec.describe "User menu notifications | sidebar", type: :system do
|
||
fab!(:current_user) { Fabricate(:user) }
|
||
|
||
let(:chat) { PageObjects::Pages::Chat.new }
|
||
let(:channel) { PageObjects::Pages::ChatChannel.new }
|
||
|
||
before do
|
||
SiteSetting.navigation_menu = "sidebar"
|
||
chat_system_bootstrap
|
||
sign_in(current_user)
|
||
end
|
||
|
||
shared_examples "chat not available" do
|
||
it "doesn’t show the chat tab" do
|
||
visit("/")
|
||
find(".header-dropdown-toggle.current-user").click
|
||
|
||
expect(page).to have_no_css("#user-menu-button-chat-notifications")
|
||
end
|
||
end
|
||
|
||
context "when chat is disabled" do
|
||
before { SiteSetting.chat_enabled = false }
|
||
|
||
include_examples "chat not available"
|
||
end
|
||
|
||
context "when user has chat disabled" do
|
||
before { current_user.user_option.update!(chat_enabled: false) }
|
||
|
||
include_examples "chat not available"
|
||
end
|
||
|
||
context "when mentioning" do
|
||
fab!(:other_user) { Fabricate(:user) }
|
||
|
||
context "when dm channel" do
|
||
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, other_user]) }
|
||
|
||
before { Jobs.run_immediately! }
|
||
|
||
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
|
||
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
|
||
expect(find("#quick-access-chat-notifications")).to have_link(
|
||
I18n.t("js.notifications.popup.direct_message_chat_mention.direct"),
|
||
href: "/chat/c/#{other_user.username}/#{dm_channel_1.id}/#{message.id}",
|
||
)
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when category channel" do
|
||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||
|
||
before do
|
||
Jobs.run_immediately!
|
||
channel_1.add(current_user)
|
||
channel_1.add(other_user)
|
||
end
|
||
|
||
context "when group mention" do
|
||
fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
|
||
|
||
let(:message) do
|
||
Fabricate(
|
||
:chat_message,
|
||
chat_channel: channel_1,
|
||
user: other_user,
|
||
message: "this is fine @#{group.name}",
|
||
use_service: true,
|
||
)
|
||
end
|
||
|
||
before do
|
||
group.add(current_user)
|
||
message
|
||
end
|
||
|
||
it "shows a group mention notification" do
|
||
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
|
||
expect(find("#quick-access-chat-notifications")).to have_link(
|
||
I18n.t(
|
||
"js.notifications.popup.chat_mention.other_plain",
|
||
identifier: "@#{group.name}",
|
||
channel: channel_1.name,
|
||
),
|
||
href: "/chat/c/#{channel_1.slug}/#{channel_1.id}/#{message.id}",
|
||
)
|
||
end
|
||
end
|
||
|
||
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
|
||
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
|
||
|
||
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}/#{message.id}",
|
||
)
|
||
end
|
||
|
||
context "when the message is in a thread" do
|
||
let!(:message) do
|
||
Fabricate(
|
||
:chat_message,
|
||
thread: Fabricate(:chat_thread, channel: channel_1),
|
||
user: other_user,
|
||
message: "this is fine @#{current_user.username}",
|
||
use_service: true,
|
||
)
|
||
end
|
||
|
||
it "shows a mention notification when the message is in a thread" do
|
||
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
|
||
|
||
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
|
||
|
||
context "when @all" do
|
||
let!(:message) do
|
||
Fabricate(
|
||
:chat_message,
|
||
chat_channel: channel_1,
|
||
user: other_user,
|
||
message: "this is fine @all",
|
||
use_service: true,
|
||
)
|
||
end
|
||
|
||
it "shows a mention notification" do
|
||
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
|
||
expect(find("#quick-access-chat-notifications")).to have_link(
|
||
I18n.t(
|
||
"js.notifications.popup.chat_mention.other_plain",
|
||
identifier: "@all",
|
||
channel: channel_1.name,
|
||
),
|
||
href: "/chat/c/#{channel_1.slug}/#{channel_1.id}/#{message.id}",
|
||
)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when inviting a user" do
|
||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||
fab!(:other_user) { Fabricate(:user) }
|
||
|
||
before { channel_1.add(current_user) }
|
||
|
||
xit "shows an invitation notification" do
|
||
Jobs.run_immediately!
|
||
|
||
chat.visit_channel(channel_1)
|
||
channel.send_message("this is fine @#{other_user.username}")
|
||
find(".invite-link", wait: 5).click
|
||
|
||
using_session(:user_1) do |session|
|
||
sign_in(other_user)
|
||
visit("/")
|
||
find(".header-dropdown-toggle.current-user").click
|
||
|
||
expect(find("#user-menu-button-chat-notifications")).to have_content(1)
|
||
expect(find("#quick-access-all-notifications")).to have_css(".chat-invitation.unread")
|
||
session.quit
|
||
end
|
||
end
|
||
end
|
||
end
|