FIX: new chat from url flaky fix (#27414)

The order of chat direct message groups can sometimes place usernames in an unexpected order, this change tests multiple combinations of usernames and accepts them no matter what order they are in.
This commit is contained in:
David Battersby 2024-06-11 14:13:08 +04:00 committed by GitHub
parent 27efa2d8b7
commit fb11ab5895
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -14,6 +14,10 @@ RSpec.describe "Chat New Message from params", type: :system do
sign_in(current_user)
end
def group_slug(users)
users.pluck(:username).permutation.map { |u| u.join("-") }.join("|")
end
context "with a single user" do
it "redirects to existing chat channel" do
chat_page.visit_new_message(user_1)
@ -42,9 +46,10 @@ RSpec.describe "Chat New Message from params", type: :system do
it "loads existing dm channel when one exists" do
expect { chat_page.visit_new_message([user_1, user_2]) }.not_to change { Chat::Channel.count }
users = [user_1.username, user_2.username].permutation.map { |u| u.join("-") }.join("|")
expect(page).to have_current_path(%r{/chat/c/(#{users})/#{group_dm.id}})
expect(page).to have_current_path(
%r{/chat/c/(#{group_slug([user_1, user_2])})/#{group_dm.id}},
)
end
it "creates a dm channel when none exists" do
@ -53,7 +58,7 @@ RSpec.describe "Chat New Message from params", type: :system do
)
expect(page).to have_current_path(
"/chat/c/#{user_1.username}-#{user_3.username}/#{Chat::Channel.last.id}",
%r{/chat/c/#{group_slug([user_1, user_3])}/#{Chat::Channel.last.id}},
)
end