diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index dab44cb6..db91da56 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -11,7 +11,6 @@ require 'capybara/rspec' require 'webmock/rspec' require 'sidekiq/testing' require 'signing_form_helper' -require 'request_helper' Sidekiq::Testing.fake! @@ -55,7 +54,6 @@ RSpec.configure do |config| config.include FactoryBot::Syntax::Methods config.include Devise::Test::IntegrationHelpers config.include SigningFormHelper - config.include RequestHelper config.before(:each, type: :system) do if ENV['HEADLESS'] == 'false' diff --git a/spec/request_helper.rb b/spec/request_helper.rb deleted file mode 100644 index 7240c076..00000000 --- a/spec/request_helper.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -module RequestHelper - module_function - - def wait_for_fetch - page.execute_script( - <<~JS - if (!window.fetchInitialized) { - window.pendingFetchCount = 0; - - const originalFetch = window.fetch; - - window.fetch = function(...args) { - window.pendingFetchCount++; - - return originalFetch.apply(this, args).finally(() => { - window.pendingFetchCount--; - }); - }; - - window.fetchInitialized = true; - } - JS - ) - - yield - - Timeout.timeout(Capybara.default_max_wait_time) do - loop do - break if page.evaluate_script('window.pendingFetchCount') == 0 - - sleep 0.1 - end - end - end -end diff --git a/spec/system/template_builder_spec.rb b/spec/system/template_builder_spec.rb index f150bea9..d14ce3b9 100644 --- a/spec/system/template_builder_spec.rb +++ b/spec/system/template_builder_spec.rb @@ -21,14 +21,14 @@ RSpec.describe 'Template Builder' do doc.click expect do - wait_for_fetch do - doc.find('.replace-document-button').click - doc.find('.replace-document-button input[type="file"]', visible: false) - .attach_file(Rails.root.join('spec/fixtures/sample-image.png')) - end + doc.find('.replace-document-button').click + doc.find('.replace-document-button input[type="file"]', visible: false) + .attach_file(Rails.root.join('spec/fixtures/sample-image.png')) + + page.driver.wait_for_network_idle end.to change { template.documents.count }.by(1) - expect(template.reload['schema'][1]['name']).to eq('sample-image') + expect(page).to have_content('sample-image') end end end