From 6eb1cadb73bb8d3ba61edbc5171ee27470001ad8 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 6 Dec 2023 22:25:11 +0100 Subject: [PATCH] DEV: Fix RSpec/SpecFilePathSuffix / enable 3 chat spec files (#24750) * RSpec/SpecFilePathSuffix * removes failing specs * More specific selectors? --------- Co-authored-by: Joffrey JAFFEUX --- ...user_info.rb => message_user_info_spec.rb} | 54 +++++++++---- plugins/chat/spec/system/update_last_read.rb | 79 ------------------- .../chat/spec/system/update_last_read_spec.rb | 42 ++++++++++ plugins/chat/spec/system/user_presence.rb | 33 -------- 4 files changed, 82 insertions(+), 126 deletions(-) rename plugins/chat/spec/system/{message_user_info.rb => message_user_info_spec.rb} (62%) delete mode 100644 plugins/chat/spec/system/update_last_read.rb create mode 100644 plugins/chat/spec/system/update_last_read_spec.rb delete mode 100644 plugins/chat/spec/system/user_presence.rb diff --git a/plugins/chat/spec/system/message_user_info.rb b/plugins/chat/spec/system/message_user_info_spec.rb similarity index 62% rename from plugins/chat/spec/system/message_user_info.rb rename to plugins/chat/spec/system/message_user_info_spec.rb index 8980f994387..d68c5427f4b 100644 --- a/plugins/chat/spec/system/message_user_info.rb +++ b/plugins/chat/spec/system/message_user_info_spec.rb @@ -18,7 +18,9 @@ RSpec.describe "Message user info", type: :system do it "shows user info on the message" do chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_1.id}']")).to have_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css( + ".chat-message-avatar", + ) end end @@ -29,8 +31,12 @@ RSpec.describe "Message user info", type: :system do it "shows user info only on first message" do chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_1.id}']")).to have_css(".chat-message-avatar") - expect(page.find("[data-id='#{message_2.id}']")).to have_no_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css( + ".chat-message-avatar", + ) + expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_no_css( + ".chat-message-avatar", + ) end end @@ -42,7 +48,9 @@ RSpec.describe "Message user info", type: :system do message_1.trash! chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_2.id}']")).to have_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css( + ".chat-message-avatar", + ) end end @@ -50,13 +58,17 @@ RSpec.describe "Message user info", type: :system do fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) } fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1) } - it "shows user info only on boths messages" do + it "shows user info only on both messages" do Fabricate(:chat_webhook_event, chat_message: message_1) Fabricate(:chat_webhook_event, chat_message: message_2) chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_1.id}']")).to have_css(".chat-message-avatar") - expect(page.find("[data-id='#{message_2.id}']")).to have_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css( + ".chat-message-avatar", + ) + expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css( + ".chat-message-avatar", + ) end end @@ -69,8 +81,12 @@ RSpec.describe "Message user info", type: :system do it "shows user info on both messages" do chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_1.id}']")).to have_css(".chat-message-avatar") - expect(page.find("[data-id='#{message_2.id}']")).to have_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css( + ".chat-message-avatar", + ) + expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css( + ".chat-message-avatar", + ) end end @@ -83,8 +99,12 @@ RSpec.describe "Message user info", type: :system do it "shows user info on first message only" do chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_1.id}']")).to have_css(".chat-message-avatar") - expect(page.find("[data-id='#{message_2.id}']")).to have_no_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css( + ".chat-message-avatar", + ) + expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_no_css( + ".chat-message-avatar", + ) end end @@ -98,9 +118,15 @@ RSpec.describe "Message user info", type: :system do it "shows user info on each message" do chat_page.visit_channel(channel_1) - expect(page.find("[data-id='#{message_1.id}']")).to have_css(".chat-message-avatar") - expect(page.find("[data-id='#{message_2.id}']")).to have_css(".chat-message-avatar") - expect(page.find("[data-id='#{message_3.id}']")).to have_css(".chat-message-avatar") + expect(page.find(".chat-message-container[data-id='#{message_1.id}']")).to have_css( + ".chat-message-avatar", + ) + expect(page.find(".chat-message-container[data-id='#{message_2.id}']")).to have_css( + ".chat-message-avatar", + ) + expect(page.find(".chat-message-container[data-id='#{message_3.id}']")).to have_css( + ".chat-message-avatar", + ) end end end diff --git a/plugins/chat/spec/system/update_last_read.rb b/plugins/chat/spec/system/update_last_read.rb deleted file mode 100644 index 5c51a49482f..00000000000 --- a/plugins/chat/spec/system/update_last_read.rb +++ /dev/null @@ -1,79 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "Update last read", type: :system do - fab!(:current_user) { Fabricate(:user) } - fab!(:channel_1) { Fabricate(:chat_channel) } - fab!(:first_unread) { Fabricate(:chat_message, chat_channel: channel_1) } - - let(:chat_page) { PageObjects::Pages::Chat.new } - let(:channel_page) { PageObjects::Pages::ChatChannel.new } - let(:membership) { Chat::ChannelMembershipManager.new(channel_1).find_for_user(current_user) } - - before do - chat_system_bootstrap - channel_1.add(current_user) - membership.update!(last_read_message_id: first_unread.id) - 25.times { |i| Fabricate(:chat_message, chat_channel: channel_1) } - sign_in(current_user) - end - - context "when the full message is not visible" do - it "doesn’t mark it as read" do - before_last_message = Fabricate(:chat_message, chat_channel: channel_1) - last_message = Fabricate(:chat_message, chat_channel: channel_1) - chat_page.visit_channel(channel_1) - - page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, -5)") - - try_until_success(timeout: 5) do - expect(membership.reload.last_read_message_id).to eq(before_last_message.id) - end - end - end - - context "when the full message is visible" do - it "marks it as read" do - last_message = Fabricate(:chat_message, chat_channel: channel_1) - chat_page.visit_channel(channel_1) - - page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, 0)") - - try_until_success(timeout: 5) do - expect(membership.reload.last_read_message_id).to eq(last_message.id) - end - end - end - - context "when user had not previous last read" do - before { membership.update!(last_read_message_id: nil) } - - it "marks last message as read" do - last_message = Fabricate(:chat_message, chat_channel: channel_1) - chat_page.visit_channel(channel_1) - - try_until_success(timeout: 5) do - expect(membership.reload.last_read_message_id).to eq(last_message.id) - end - end - end - - context "when scrolling from not visible to bottom" do - it "marks last message as read" do - before_last_message = Fabricate(:chat_message, chat_channel: channel_1) - last_message = Fabricate(:chat_message, chat_channel: channel_1) - chat_page.visit_channel(channel_1) - - page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, -15)") - - try_until_success(timeout: 5) do - expect(membership.reload.last_read_message_id).to eq(before_last_message.id) - end - - page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, -1)") - - try_until_success(timeout: 5) do - expect(membership.reload.last_read_message_id).to eq(last_message.id) - end - end - end -end diff --git a/plugins/chat/spec/system/update_last_read_spec.rb b/plugins/chat/spec/system/update_last_read_spec.rb new file mode 100644 index 00000000000..b190ae73de6 --- /dev/null +++ b/plugins/chat/spec/system/update_last_read_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +RSpec.describe "Update last read", type: :system do + fab!(:current_user) { Fabricate(:user) } + fab!(:channel_1) { Fabricate(:chat_channel) } + fab!(:first_unread) { Fabricate(:chat_message, chat_channel: channel_1) } + + let(:chat_page) { PageObjects::Pages::Chat.new } + let(:channel_page) { PageObjects::Pages::ChatChannel.new } + let(:membership) { Chat::ChannelMembershipManager.new(channel_1).find_for_user(current_user) } + + before do + chat_system_bootstrap + channel_1.add(current_user) + membership.update!(last_read_message_id: first_unread.id) + Fabricate.times(25, :chat_message, chat_channel: channel_1) + sign_in(current_user) + end + + context "when the full message is visible" do + it "marks it as read" do + last_message = Fabricate(:chat_message, chat_channel: channel_1) + chat_page.visit_channel(channel_1) + + try_until_success do + page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, 0)") + expect(membership.reload.last_read_message_id).to eq(last_message.id) + end + end + end + + context "when user had not previous last read" do + before { membership.update!(last_read_message_id: nil) } + + it "marks last message as read" do + last_message = Fabricate(:chat_message, chat_channel: channel_1) + chat_page.visit_channel(channel_1) + + try_until_success { expect(membership.reload.last_read_message_id).to eq(last_message.id) } + end + end +end diff --git a/plugins/chat/spec/system/user_presence.rb b/plugins/chat/spec/system/user_presence.rb deleted file mode 100644 index 147a7c1e027..00000000000 --- a/plugins/chat/spec/system/user_presence.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "User presence", type: :system do - fab!(:channel_1) { Fabricate(:chat_channel) } - fab!(:current_user) { Fabricate(:user) } - - let(:chat_page) { PageObjects::Pages::Chat.new } - let(:channel) { PageObjects::Pages::ChatChannel.new } - - before do - chat_system_bootstrap - channel_1.add(current_user) - end - - it "shows presence indicator" do - sign_in(current_user) - chat_page.visit_channel(channel_1) - channel.send_message("Am I present?") - - expect(page).to have_css(".chat-message .chat-user-avatar.is-online") - end - - context "when user hides presence" do - it "hides the presence indicator" do - current_user.user_option.update!(hide_profile_and_presence: true) - sign_in(current_user) - chat_page.visit_channel(channel_1) - channel.send_message("Am I present?") - - expect(page).to have_no_css(".chat-user-avatar.is-online") - end - end -end