discourse/plugins/chat/spec/system/chat_new_message_spec.rb
David Battersby a460dbcb37
FEATURE: Create a link to start a new chat (#25722)
This feature adds the functionality to start a new chat directly from the URL using query params.

The format is: /chat/new-message?recipients=buford,jona

The initial version of this feature allows for the following:

- Open an existing direct message channel with a single user
- Create a new direct message channel with a single user (and auto redirect)
- Create or open a channel with multiple users (and auto redirect)
- Redirects to chat home if the recipients param is missing
2024-02-20 18:08:57 +08:00

48 lines
1.5 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")
# chat service selects public channel from getIdealFirstChannelId
expect(page).to have_current_path("/chat/c/#{public_channel.slug}/#{public_channel.id}")
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