Files
openfoodnetwork/spec/system/admin/enterprises/dfc_permissions_spec.rb
Maikel Linke 3a72aefc1c Fail test when timeout reached
In this example it didn't matter but if we re-use the helper then it
needs to raise an error after the timeout has been reached.
2025-08-12 09:54:48 +10:00

89 lines
2.5 KiB
Ruby

# frozen_string_literal: true
require "system_helper"
RSpec.describe "DFC Permissions", feature: "cqcm-dev", vcr: true do
let(:enterprise) { create(:enterprise) }
before do
login_as enterprise.owner
end
it "is not visible when no platform is enabled" do
Flipper.disable("cqcm-dev")
visit edit_admin_enterprise_path(enterprise)
expect(page).not_to have_content "CONNECTED APPS"
end
it "can share data with another platform" do
visit edit_admin_enterprise_path(enterprise)
scroll_to :bottom
click_link "Connected apps"
# 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. :-(
wait_for_component_loaded
within(platform_list("without-permissions")) do
expect(page).to have_content "Proxy Dev Portal"
# NotSupportedError: Failed to execute 'evaluate' on 'Document':
# The node provided is '#document-fragment', which is not a valid context node type.
#
# click_on "Agree and share"
# This hack works
find("button", text: "Agree and share").native.trigger("click")
end
within_platform_list("approved") do
expect(page).to have_content "Proxy Dev Portal"
find("button", text: "Stop sharing").native.trigger("click")
end
within_platform_list("without-permissions") do
expect(page).to have_content "Proxy Dev Portal"
find("button", text: "Agree and share").native.trigger("click")
end
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
raise if Time.now.utc > finish
sleep 0.1
retry
end
def platform_list(variant)
page.find('solid-permissioning').shadow_root
.find("platform-block[variant='#{variant}']").shadow_root
end
end