From ed077cf3f181c83561bb1f7b1acc085c05225cd6 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 3 May 2023 11:03:38 +0200 Subject: [PATCH] DEV: after has been proven problematic in other tests (#21358) It seems more reliable to revert state at the end of the it block. In another PR I noticed that the network state was leaking in other tests when I was reverting in the after block. Also trashes a suspicious spec. --- .../system/network_reconciliation_spec.rb | 58 ------------------- .../system/shortcuts/chat_composer_spec.rb | 4 +- 2 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 plugins/chat/spec/system/network_reconciliation_spec.rb diff --git a/plugins/chat/spec/system/network_reconciliation_spec.rb b/plugins/chat/spec/system/network_reconciliation_spec.rb deleted file mode 100644 index 8ceb9b4a19a..00000000000 --- a/plugins/chat/spec/system/network_reconciliation_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "Network reconciliation", type: :system, js: true do - fab!(:current_user) { Fabricate(:user) } - fab!(:other_user) { Fabricate(:user) } - fab!(:channel_1) { Fabricate(:category_channel) } - - let(:chat_page) { PageObjects::Pages::Chat.new } - let(:chat_channel_page) { PageObjects::Pages::ChatChannel.new } - - before do - chat_system_bootstrap - channel_1.add(current_user) - channel_1.add(other_user) - end - - context "when user recovers network" do - it "recovers state" do - using_session(:disconnected_current_user) do - sign_in(current_user) - visit("/") - page.driver.browser.network_conditions = { offline: true, latency: 0, throughput: 0 } - end - - using_session(:other_user) do |session| - sign_in(other_user) - chat_page.visit_channel(channel_1) - chat_channel_page.send_message("hello @#{current_user.username}!") - session.quit - end - - using_session(:connected_current_user) do |session| - sign_in(current_user) - visit("/") - expect(page).to have_css(".chat-header-icon .chat-channel-unread-indicator") - chat_page.visit_channel(channel_1) - expect(page).to have_no_css(".chat-header-icon .chat-channel-unread-indicator") - session.quit - end - - using_session(:disconnected_current_user) do |session| - expect(page).to have_no_css(".chat-header-icon .chat-channel-unread-indicator") - page.driver.browser.network_conditions = { offline: false, latency: 0, throughput: 0 } - expect(page).to have_no_css(".chat-header-icon .chat-channel-unread-indicator") - - # generally speaking sleep should be avoided in tests, but in this case - # we need to wait for the client to reconnect and receive the message - # right at the start the icon won't be there so checking for not will be true - # and checking for present could also be true as it might be within capybara finder delay - # which is what we are testing here and want to avoid - sleep 1 - - expect(page).to have_no_css(".chat-header-icon .chat-channel-unread-indicator") - session.quit - end - end - end -end diff --git a/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb b/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb index 15f3ffd003e..457b1e0d3f9 100644 --- a/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb +++ b/plugins/chat/spec/system/shortcuts/chat_composer_spec.rb @@ -104,8 +104,6 @@ RSpec.describe "Shortcuts | chat composer", type: :system, js: true do end context "when last message is not editable" do - after { page.driver.browser.network_conditions = { offline: false } } - it "does not edit a message" do chat.visit_channel(channel_1) page.driver.browser.network_conditions = { offline: true } @@ -114,6 +112,8 @@ RSpec.describe "Shortcuts | chat composer", type: :system, js: true do find(".chat-composer__input").send_keys(:arrow_up) expect(page).to have_no_css(".chat-composer-message-details") + + page.driver.browser.network_conditions = { offline: false } end end end