2023-02-03 09:11:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-06 21:26:58 -04:00
|
|
|
RSpec.describe "Drawer", type: :system do
|
2024-06-13 05:17:12 -04:00
|
|
|
fab!(:current_user) { Fabricate(:user) }
|
2023-02-03 09:11:12 -05:00
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
2023-03-03 07:09:25 -05:00
|
|
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
2023-08-21 16:12:05 -04:00
|
|
|
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
2023-02-03 09:11:12 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
chat_system_bootstrap
|
|
|
|
sign_in(current_user)
|
2024-06-06 06:01:09 -04:00
|
|
|
chat_page.prefers_drawer
|
2023-02-03 09:11:12 -05:00
|
|
|
end
|
|
|
|
|
2023-02-14 23:03:29 -05:00
|
|
|
context "when on channel" do
|
|
|
|
fab!(:channel) { Fabricate(:chat_channel) }
|
|
|
|
fab!(:membership) do
|
|
|
|
Fabricate(:user_chat_channel_membership, user: current_user, chat_channel: channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when clicking channel title" do
|
2024-06-06 06:01:09 -04:00
|
|
|
before do
|
2023-02-14 23:03:29 -05:00
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
2023-08-21 16:12:05 -04:00
|
|
|
drawer_page.open_channel(channel)
|
2023-12-18 11:49:58 -05:00
|
|
|
page.find(".c-navbar__channel-title").click
|
2024-06-06 06:01:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "opens channel settings page" do
|
|
|
|
expect(drawer_page).to have_channel_settings
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has tabs for settings and members" do
|
|
|
|
expect(drawer_page).to have_css(".c-channel-info__nav li a", text: "Settings")
|
|
|
|
expect(drawer_page).to have_css(".c-channel-info__nav li a", text: "Members")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "opens correct tab when clicked" do
|
|
|
|
page.find(".c-channel-info__nav li a", text: "Members").click
|
|
|
|
expect(drawer_page).to have_channel_members
|
|
|
|
|
|
|
|
page.find(".c-channel-info__nav li a", text: "Settings").click
|
|
|
|
expect(drawer_page).to have_channel_settings
|
|
|
|
end
|
2023-02-14 23:03:29 -05:00
|
|
|
|
2024-06-06 06:01:09 -04:00
|
|
|
it "has a back button" do
|
|
|
|
expect(drawer_page).to have_css(".c-navbar__back-button")
|
2023-02-14 23:03:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-03 09:11:12 -05:00
|
|
|
context "when opening" do
|
|
|
|
it "uses stored size" do
|
|
|
|
visit("/") # we need to visit the page first to set the local storage
|
|
|
|
|
|
|
|
page.execute_script "window.localStorage.setItem('discourse_chat_drawer_size_width','500');"
|
|
|
|
page.execute_script "window.localStorage.setItem('discourse_chat_drawer_size_height','500');"
|
|
|
|
|
|
|
|
visit("/")
|
|
|
|
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page.find(".chat-drawer").native.style("width")).to eq("500px")
|
|
|
|
expect(page.find(".chat-drawer").native.style("height")).to eq("500px")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a default size" do
|
|
|
|
visit("/")
|
|
|
|
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page.find(".chat-drawer").native.style("width")).to eq("400px")
|
|
|
|
expect(page.find(".chat-drawer").native.style("height")).to eq("530px")
|
|
|
|
end
|
|
|
|
end
|
2023-03-03 07:09:25 -05:00
|
|
|
|
2023-03-10 12:49:59 -05:00
|
|
|
context "when toggling open/close" do
|
|
|
|
it "toggles a css class on body" do
|
|
|
|
visit("/")
|
|
|
|
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page.find("body.chat-drawer-active")).to be_visible
|
|
|
|
|
2023-08-21 16:12:05 -04:00
|
|
|
drawer_page.close
|
2023-03-10 12:49:59 -05:00
|
|
|
|
|
|
|
expect(page.find("body:not(.chat-drawer-active)")).to be_visible
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-10 02:10:01 -04:00
|
|
|
context "when closing the drawer" do
|
|
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
|
|
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
|
|
|
|
it "resets the active message" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
2023-08-21 16:12:05 -04:00
|
|
|
drawer_page.open_channel(channel_1)
|
2023-04-10 02:10:01 -04:00
|
|
|
channel_page.hover_message(message_1)
|
2023-05-26 12:48:45 -04:00
|
|
|
|
2023-07-05 19:33:39 -04:00
|
|
|
expect(page).to have_css(".chat-message-actions-container", visible: :all)
|
2023-04-10 02:10:01 -04:00
|
|
|
|
2023-08-21 16:12:05 -04:00
|
|
|
drawer_page.close
|
2023-04-10 02:10:01 -04:00
|
|
|
|
|
|
|
expect(page).to have_no_css(".chat-message-actions-container")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-10 01:43:11 -04:00
|
|
|
context "when clicking the drawer's header" do
|
|
|
|
it "collapses the drawer" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
2024-08-22 11:46:41 -04:00
|
|
|
|
2023-04-10 01:43:11 -04:00
|
|
|
expect(page).to have_selector(".chat-drawer.is-expanded")
|
2024-08-22 11:46:41 -04:00
|
|
|
expect(page).to have_selector("body.chat-drawer-expanded")
|
2023-04-10 01:43:11 -04:00
|
|
|
|
2023-12-18 11:49:58 -05:00
|
|
|
page.find(".c-navbar").click
|
2023-04-10 01:43:11 -04:00
|
|
|
|
|
|
|
expect(page).to have_selector(".chat-drawer:not(.is-expanded)")
|
2024-08-22 11:46:41 -04:00
|
|
|
expect(page).to have_selector("body:not(.chat-drawer-expanded)")
|
2023-04-10 01:43:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-03 07:09:25 -05:00
|
|
|
context "when going from drawer to full page" do
|
|
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
fab!(:channel_2) { Fabricate(:chat_channel) }
|
|
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
2024-03-18 03:35:07 -04:00
|
|
|
current_user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel_1.id)
|
2023-03-03 07:09:25 -05:00
|
|
|
channel_1.add(current_user)
|
|
|
|
channel_2.add(current_user)
|
|
|
|
channel_1.add(user_1)
|
|
|
|
channel_2.add(user_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly resets subscriptions" do
|
|
|
|
visit("/")
|
|
|
|
|
|
|
|
chat_page.open_from_header
|
2023-08-21 16:12:05 -04:00
|
|
|
drawer_page.maximize
|
2023-03-03 07:09:25 -05:00
|
|
|
chat_page.minimize_full_page
|
2023-08-21 16:12:05 -04:00
|
|
|
drawer_page.maximize
|
2023-03-03 07:09:25 -05:00
|
|
|
|
2023-11-06 09:45:30 -05:00
|
|
|
Fabricate(
|
|
|
|
:chat_message,
|
|
|
|
chat_channel: channel_1,
|
|
|
|
user: user_1,
|
|
|
|
use_service: true,
|
|
|
|
message: "onlyonce",
|
|
|
|
)
|
2023-03-03 07:09:25 -05:00
|
|
|
|
2023-11-06 09:45:30 -05:00
|
|
|
expect(page).to have_content("onlyonce", count: 1)
|
2023-03-03 07:09:25 -05:00
|
|
|
|
|
|
|
chat_page.visit_channel(channel_2)
|
|
|
|
|
2023-11-06 09:45:30 -05:00
|
|
|
expect(page).to have_content("onlyonce", count: 0)
|
2023-03-03 07:09:25 -05:00
|
|
|
end
|
|
|
|
end
|
2023-08-21 16:12:05 -04:00
|
|
|
|
|
|
|
context "when subfolder install" do
|
|
|
|
fab!(:channel) { Fabricate(:chat_channel) }
|
|
|
|
|
|
|
|
before do
|
2024-03-18 03:35:07 -04:00
|
|
|
current_user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel.id)
|
2023-08-21 16:12:05 -04:00
|
|
|
channel.add(current_user)
|
|
|
|
set_subfolder "/discuss"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works to go from full page to drawer" do
|
|
|
|
visit("/discuss/chat")
|
|
|
|
chat_page.minimize_full_page
|
|
|
|
|
|
|
|
expect(drawer_page).to have_open_channel(channel)
|
|
|
|
end
|
|
|
|
end
|
2024-02-13 05:37:15 -05:00
|
|
|
|
|
|
|
context "when sending a message from topic" do
|
|
|
|
fab!(:topic)
|
|
|
|
fab!(:posts) { Fabricate.times(5, :post, topic: topic) }
|
|
|
|
fab!(:channel) { Fabricate(:chat_channel) }
|
|
|
|
fab!(:membership) do
|
|
|
|
Fabricate(:user_chat_channel_membership, user: current_user, chat_channel: channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
|
|
|
|
|
|
context "when on a channel" do
|
2024-02-15 01:14:53 -05:00
|
|
|
xit "has context" do
|
2024-02-13 05:37:15 -05:00
|
|
|
::Chat::CreateMessage
|
|
|
|
.expects(:call)
|
|
|
|
.with do |value|
|
|
|
|
value["topic_id"] === topic.id.to_s &&
|
|
|
|
value["post_ids"] === [posts[1].id.to_s, posts[2].id.to_s, posts[3].id.to_s]
|
|
|
|
end
|
|
|
|
|
|
|
|
topic_page.visit_topic(topic, post_number: 3)
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
channel_page.send_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when on a thread" do
|
|
|
|
before { channel.update!(threading_enabled: true) }
|
|
|
|
|
|
|
|
fab!(:thread_1) { Fabricate(:chat_thread, channel: channel) }
|
|
|
|
|
|
|
|
let(:thread_list_page) { PageObjects::Components::Chat::ThreadList.new }
|
|
|
|
let(:thread_page) { PageObjects::Pages::ChatThread.new }
|
|
|
|
|
2024-02-15 01:14:53 -05:00
|
|
|
xit "has context" do
|
2024-02-13 05:37:15 -05:00
|
|
|
::Chat::CreateMessage
|
|
|
|
.expects(:call)
|
|
|
|
.with do |value|
|
|
|
|
value["topic_id"] === topic.id.to_s &&
|
|
|
|
value["post_ids"] === [posts[1].id.to_s, posts[2].id.to_s, posts[3].id.to_s]
|
|
|
|
end
|
|
|
|
|
|
|
|
topic_page.visit_topic(topic, post_number: 3)
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
drawer_page.open_thread_list
|
|
|
|
thread_list_page.open_thread(thread_1)
|
|
|
|
thread_page.send_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-06-13 05:17:12 -04:00
|
|
|
|
|
|
|
describe "with chat footer" do
|
|
|
|
it "opens channels list by default" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(drawer_page).to have_open_channels
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows footer nav when 2 or more tabs are accessible" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_css(".chat-drawer .c-footer")
|
|
|
|
expect(page).to have_css(".chat-drawer .c-footer__item", count: 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "hides footer nav when only channels are accessible" do
|
|
|
|
SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:staff]
|
|
|
|
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_no_css(".chat-drawer .c-footer")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when clicking footer nav items" do
|
|
|
|
fab!(:channel) { Fabricate(:chat_channel, threading_enabled: true) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.chat_threads_enabled = true
|
|
|
|
channel.add(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows active state" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
drawer_page.click_direct_messages
|
|
|
|
expect(page).to have_css("#c-footer-direct-messages.--active")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to correct route" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
drawer_page.click_direct_messages
|
|
|
|
expect(drawer_page).to have_open_direct_messages
|
|
|
|
|
|
|
|
drawer_page.click_channels
|
|
|
|
expect(drawer_page).to have_open_channels
|
|
|
|
|
|
|
|
drawer_page.click_user_threads
|
|
|
|
expect(drawer_page).to have_open_user_threads
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-02-03 09:11:12 -05:00
|
|
|
end
|