mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 12:46:30 +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.
52 lines
1.4 KiB
Ruby
52 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Removing channel", type: :system do
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
let(:chat_sidebar_page) { PageObjects::Pages::Sidebar.new }
|
|
|
|
before do
|
|
chat_system_bootstrap
|
|
sign_in(current_user)
|
|
end
|
|
|
|
context "when removing last followed channel" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
fab!(:channel_2) { Fabricate(:direct_message_channel, users: [current_user, Fabricate(:user)]) }
|
|
|
|
before do
|
|
Fabricate(
|
|
:user_chat_channel_membership,
|
|
user: current_user,
|
|
chat_channel: channel_1,
|
|
following: false,
|
|
)
|
|
end
|
|
|
|
it "redirects to browse page" do
|
|
chat_page.visit_channel(channel_2)
|
|
chat_sidebar_page.remove_channel(channel_2)
|
|
|
|
expect(page).to have_current_path("/chat/browse/open")
|
|
end
|
|
end
|
|
|
|
context "when removing channel" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
fab!(:channel_2) { Fabricate(:direct_message_channel, users: [current_user, Fabricate(:user)]) }
|
|
|
|
before do
|
|
current_user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel_1.id)
|
|
channel_1.add(current_user)
|
|
end
|
|
|
|
it "redirects to another followed channgel" do
|
|
chat_page.visit_channel(channel_2)
|
|
chat_sidebar_page.remove_channel(channel_2)
|
|
|
|
expect(page).to have_current_path(chat.channel_path(channel_1.slug, channel_1.id))
|
|
end
|
|
end
|
|
end
|