mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 13:34:08 +08:00
bbb8595107
Prior to this change we would pre-load all the user channels which making initial page load slower. This change will make them be loaded right after initial load. In the past this was not possible as the channels would have to be loaded on each page transition. However since about a year, we made the channels to be cached on the frontend and no other request will be needed. I have decided for now to not show a loading state in the sidebar as I think it would be noise, but we can reconsider this later. Note given we don't have the channels loaded at first certain things where harder to accomplish. The biggest UX change of this commit is that we removed all the complex logic of computing the best channel to display when you load /chat. We will now store the id of the last channel you visited and will use this id to decide which channel to show.
209 lines
5.9 KiB
Ruby
209 lines
5.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Drawer", type: :system do
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
|
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
|
|
|
before do
|
|
chat_system_bootstrap
|
|
sign_in(current_user)
|
|
end
|
|
|
|
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
|
|
it "opens channel settings page" do
|
|
visit("/")
|
|
chat_page.open_from_header
|
|
drawer_page.open_channel(channel)
|
|
page.find(".c-navbar__channel-title").click
|
|
|
|
expect(page).to have_current_path("/chat/c/#{channel.slug}/#{channel.id}/info/settings")
|
|
end
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
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
|
|
|
|
drawer_page.close
|
|
|
|
expect(page.find("body:not(.chat-drawer-active)")).to be_visible
|
|
end
|
|
end
|
|
|
|
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
|
|
drawer_page.open_channel(channel_1)
|
|
channel_page.hover_message(message_1)
|
|
|
|
expect(page).to have_css(".chat-message-actions-container", visible: :all)
|
|
|
|
drawer_page.close
|
|
|
|
expect(page).to have_no_css(".chat-message-actions-container")
|
|
end
|
|
end
|
|
|
|
context "when clicking the drawer's header" do
|
|
it "collapses the drawer" do
|
|
visit("/")
|
|
chat_page.open_from_header
|
|
expect(page).to have_selector(".chat-drawer.is-expanded")
|
|
|
|
page.find(".c-navbar").click
|
|
|
|
expect(page).to have_selector(".chat-drawer:not(.is-expanded)")
|
|
end
|
|
end
|
|
|
|
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
|
|
current_user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel_1.id)
|
|
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
|
|
drawer_page.maximize
|
|
chat_page.minimize_full_page
|
|
drawer_page.maximize
|
|
|
|
Fabricate(
|
|
:chat_message,
|
|
chat_channel: channel_1,
|
|
user: user_1,
|
|
use_service: true,
|
|
message: "onlyonce",
|
|
)
|
|
|
|
expect(page).to have_content("onlyonce", count: 1)
|
|
|
|
chat_page.visit_channel(channel_2)
|
|
|
|
expect(page).to have_content("onlyonce", count: 0)
|
|
end
|
|
end
|
|
|
|
context "when subfolder install" do
|
|
fab!(:channel) { Fabricate(:chat_channel) }
|
|
|
|
before do
|
|
current_user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel.id)
|
|
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
|
|
|
|
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
|
|
xit "has context" do
|
|
::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 }
|
|
|
|
xit "has context" do
|
|
::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
|
|
end
|