discourse/spec/system/network_disconnected_spec.rb
Alan Guo Xiang Tan 454a4af0bf
DEV: Ensure browser network conditions is reset in system tests (#22404)
Why this change?

By ensuring the reset happens in an `ensure` code block, we ensure that
the code will always be run even if code fails or an error is raised.
This helps to prevent leaking custom network condition states and
improves the stability of our system tests.
2023-07-04 13:22:58 +08:00

30 lines
851 B
Ruby

# frozen_string_literal: true
RSpec.describe "Network Disconnected", type: :system do
def with_network_disconnected
begin
page.driver.browser.network_conditions = { offline: true }
yield
ensure
page.driver.browser.network_conditions = { offline: false }
end
end
it "NetworkConnectivity service adds class to DOM and displays offline indicator" do
SiteSetting.enable_offline_indicator = true
visit("/c")
expect(page).to have_no_css("html.network-disconnected")
expect(page).to have_no_css(".offline-indicator")
with_network_disconnected do
# Message bus connectivity services adds the disconnected class to the DOM
expect(page).to have_css("html.network-disconnected")
# Offline indicator is rendered
expect(page).to have_css(".offline-indicator")
end
end
end