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.
This commit is contained in:
Alan Guo Xiang Tan 2023-07-04 13:22:58 +08:00 committed by GitHub
parent 134dcdd63a
commit 454a4af0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -142,7 +142,7 @@ RSpec.describe "Chat composer", type: :system do
expect(page).to have_css(".chat-composer-upload--in-progress")
expect(page).to have_css(".chat-composer.is-send-disabled")
ensure
page.driver.browser.network_conditions = { latency: 0 }
end
end

View File

@ -2,9 +2,12 @@
RSpec.describe "Network Disconnected", type: :system do
def with_network_disconnected
page.driver.browser.network_conditions = { offline: true }
yield
page.driver.browser.network_conditions = { offline: false }
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