From fb11ab5895a5b8b838f365da51a7e0a835cfd55b Mon Sep 17 00:00:00 2001 From: David Battersby Date: Tue, 11 Jun 2024 14:13:08 +0400 Subject: [PATCH] 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. --- plugins/chat/spec/system/chat_new_message_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/chat/spec/system/chat_new_message_spec.rb b/plugins/chat/spec/system/chat_new_message_spec.rb index 41301c65537..2a5f4fb7fbb 100644 --- a/plugins/chat/spec/system/chat_new_message_spec.rb +++ b/plugins/chat/spec/system/chat_new_message_spec.rb @@ -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