mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 14:13:38 +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.
47 lines
1.4 KiB
Ruby
47 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Chat New Message from params", type: :system do
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:user_2) { Fabricate(:user) }
|
|
fab!(:public_channel) { Fabricate(:chat_channel) }
|
|
fab!(:user_1_channel) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
before do
|
|
chat_system_bootstrap
|
|
public_channel.add(current_user)
|
|
sign_in(current_user)
|
|
end
|
|
|
|
context "with a single user" do
|
|
it "redirects to existing chat channel" do
|
|
chat_page.visit_new_message(user_1)
|
|
|
|
expect(page).to have_current_path("/chat/c/#{user_1.username}/#{user_1_channel.id}")
|
|
end
|
|
|
|
it "creates a dm channel and redirects if none exists" do
|
|
chat_page.visit_new_message(user_2)
|
|
|
|
expect(page).to have_current_path("/chat/c/#{user_2.username}/#{Chat::Channel.last.id}")
|
|
end
|
|
|
|
it "redirects to chat channel if recipients param is missing" do
|
|
visit("/chat/new-message")
|
|
|
|
expect(page).to have_no_current_path("/chat/new-message")
|
|
end
|
|
end
|
|
|
|
context "with multiple users" do
|
|
it "creates a dm channel with multiple users" do
|
|
chat_page.visit_new_message([user_1, user_2])
|
|
|
|
expect(page).to have_current_path(
|
|
"/chat/c/#{user_1.username}-#{user_2.username}/#{Chat::Channel.last.id}",
|
|
)
|
|
end
|
|
end
|
|
end
|