From 6f3099a11921415b7ee14ea1ea227f66b292a9ad Mon Sep 17 00:00:00 2001 From: Longshou Situ Date: Tue, 15 Aug 2023 15:37:59 -0700 Subject: [PATCH] Fix failed integration tests for valkyrie. --- app/controllers/hyrax/batch_edits_controller.rb | 4 ++-- spec/features/batch_edit_spec.rb | 12 ++++++++---- spec/support/features/batch_edit_actions.rb | 10 +++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/controllers/hyrax/batch_edits_controller.rb b/app/controllers/hyrax/batch_edits_controller.rb index 22ff4c7bd4..3ed8ed30f2 100644 --- a/app/controllers/hyrax/batch_edits_controller.rb +++ b/app/controllers/hyrax/batch_edits_controller.rb @@ -64,7 +64,7 @@ def valkyrie_update_document(obj) form = form_class.new(obj, current_ability, nil) return unless form.validate(params[form_class.model_class.model_name.param_key]) - cleanu_form_fields form + cleanup_form_fields form result = transactions['change_set.update_work'] .with_step_args('work_resource.save_acl' => { permissions_params: form.input_params["permissions"] }) @@ -157,7 +157,7 @@ def redirect_to_return_controller # Clean up form fields # @param form Hyrax::Froms::ResourceBatchEditForm - def cleanu_form_fields(form) + def cleanup_form_fields(form) form.lease = nil if form.lease && form.lease.fields['lease_expiration_date'].nil? form.embargo = nil if form.embargo && form.embargo.fields['embargo_release_date'].nil? form.fields.keys.each do |k| diff --git a/spec/features/batch_edit_spec.rb b/spec/features/batch_edit_spec.rb index 61bd0919c1..4c88e15a0b 100644 --- a/spec/features/batch_edit_spec.rb +++ b/spec/features/batch_edit_spec.rb @@ -6,8 +6,8 @@ let(:permission_template) { create(:permission_template, source_id: admin_set.id) } let!(:workflow) { create(:workflow, allows_access_grant: true, active: true, permission_template_id: permission_template.id) } - let!(:work1) { create(:public_work, admin_set_id: admin_set.id, user: current_user, ordered_members: [file_set]) } - let!(:work2) { create(:public_work, admin_set_id: admin_set.id, user: current_user) } + let!(:work1) { create(:public_work, creator: ["Creator"], admin_set_id: admin_set.id, user: current_user, ordered_members: [file_set]) } + let!(:work2) { create(:public_work, creator: ["Creator"], admin_set_id: admin_set.id, user: current_user) } let!(:file_set) { create(:file_set) } before do @@ -77,10 +77,12 @@ batch_edit_expand('permissions_visibility') find('#generic_work_visibility_authenticated').click find('#permissions_visibility_save').click + + ajax_wait(30) # This was `expect(page).to have_content 'Changes Saved'`, however in debugging, # the `have_content` check was ignoring the `within` scoping and finding # "Changes Saved" for other field areas - find('.status', text: 'Changes Saved', wait: 5) + find('.status', text: 'Changes Saved') end within "#form_permissions" do @@ -91,10 +93,12 @@ find('#collapse_permissions_sharing table', text: 'View/Download') find('#collapse_permissions_sharing table', text: 'donor') find('#permissions_sharing_save').click + + ajax_wait(30) # This was `expect(page).to have_content 'Changes Saved'`, however in debugging, # the `have_content` check was ignoring the `within` scoping and finding # "Changes Saved" for other field areas - find('.status', text: 'Changes Saved', wait: 5) + find('.status', text: 'Changes Saved') end # Visit work permissions and verify diff --git a/spec/support/features/batch_edit_actions.rb b/spec/support/features/batch_edit_actions.rb index c6babcba8c..96a0631c7e 100644 --- a/spec/support/features/batch_edit_actions.rb +++ b/spec/support/features/batch_edit_actions.rb @@ -15,10 +15,12 @@ def fill_in_batch_edit_fields_and_verify! fill_in "generic_work_#{field_id}", with: "NEW #{field_id}" find("##{field_id}_save").click + + ajax_wait(15) # This was `expect(page).to have_content 'Changes Saved'`, however in debugging, # the `have_content` check was ignoring the `within` scoping and finding # "Changes Saved" for other field areas - find('.status', text: 'Changes Saved', wait: 5) + find('.status', text: 'Changes Saved') end end end @@ -27,3 +29,9 @@ def batch_edit_expand(field) find("#expand_link_#{field}").click yield if block_given? end + +def ajax_wait(s) + Timeout.timeout(s) do + loop until page.evaluate_script("jQuery.active").zero? + end +end