mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Replace long waits with better polling
Capybara polls under the hood as well. So we do something similar here but tailored to the tested code. This reduced the test run time on my machine from 35 seconds to 15 seconds.
This commit is contained in:
@@ -24,7 +24,7 @@ RSpec.describe "DFC Permissions", feature: "cqcm-dev", vcr: true do
|
||||
# The component displays something and then replaces it with the real
|
||||
# list. That leads to a race condition and we have to just wait until
|
||||
# the component is loaded. :-(
|
||||
sleep 10
|
||||
wait_for_component_loaded
|
||||
|
||||
within(platform_list("without-permissions")) do
|
||||
expect(page).to have_content "Proxy Dev Portal"
|
||||
@@ -38,24 +38,49 @@ RSpec.describe "DFC Permissions", feature: "cqcm-dev", vcr: true do
|
||||
find("button", text: "Agree and share").native.trigger("click")
|
||||
end
|
||||
|
||||
sleep 5
|
||||
within(platform_list("approved")) do
|
||||
within_platform_list("approved") do
|
||||
expect(page).to have_content "Proxy Dev Portal"
|
||||
find("button", text: "Stop sharing").native.trigger("click")
|
||||
end
|
||||
|
||||
sleep 5
|
||||
within(platform_list("without-permissions")) do
|
||||
within_platform_list("without-permissions") do
|
||||
expect(page).to have_content "Proxy Dev Portal"
|
||||
find("button", text: "Agree and share").native.trigger("click")
|
||||
end
|
||||
|
||||
sleep 5
|
||||
within(platform_list("approved")) do
|
||||
within_platform_list("approved") do
|
||||
expect(page).to have_content "Proxy Dev Portal"
|
||||
end
|
||||
end
|
||||
|
||||
def wait_for_component_loaded
|
||||
retry_expectations do
|
||||
within(page.find('solid-permissioning').shadow_root) do
|
||||
expect(page).to have_content "APPROVED PLATFORMS"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def within_platform_list(variant, &block)
|
||||
retry_expectations(on: Ferrum::JavaScriptError) do
|
||||
within(platform_list(variant), &block)
|
||||
end
|
||||
end
|
||||
|
||||
# Handy helper adopted from CERES Fair Food and modified.
|
||||
# We may want to share this but don't have a need for it now.
|
||||
def retry_expectations(on: RSpec::Expectations::ExpectationNotMetError)
|
||||
start = Time.now.utc
|
||||
finish = start + Capybara.default_max_wait_time
|
||||
|
||||
yield
|
||||
rescue on
|
||||
if Time.now.utc < finish
|
||||
sleep 0.1
|
||||
retry
|
||||
end
|
||||
end
|
||||
|
||||
def platform_list(variant)
|
||||
page.find('solid-permissioning').shadow_root
|
||||
.find("platform-block[variant='#{variant}']").shadow_root
|
||||
|
||||
Reference in New Issue
Block a user