Skip to content

Commit

Permalink
Valkyrizes spec/support/features/batch_edit_actions.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwatson78 authored and jeremyf committed Jan 24, 2024
1 parent fc3b005 commit 31e6cde
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
79 changes: 54 additions & 25 deletions spec/features/batch_edit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
# frozen_string_literal: true

RSpec.describe 'batch', type: :feature, clean_repo: true, js: true do
let(:wings_disabled) { Hyrax.config.disable_wings }
let(:query_service) { Hyrax.query_service }
let(:expected_element_text) { wings_disabled ? 'monograph' : 'generic_work' }

let(:current_user) { create(:user) }
let(:admin_set) { create(:admin_set) }
let(:admin_set) { wings_disabled ? valkyrie_create(:hyrax_admin_set) : create(:admin_set) }
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) do
if wings_disabled
valkyrie_create(:monograph,
:public,
creator: ["Creator"],
admin_set_id: admin_set.id,
depositor: current_user.user_key,
edit_users: [current_user],
members: [file_set])
else
create(:public_work, creator: ["Creator"], admin_set_id: admin_set.id, user: current_user, ordered_members: [file_set])
end
end
let!(:work2) do
if wings_disabled
valkyrie_create(:monograph,
:public,
creator: ["Creator"],
admin_set_id:
admin_set.id,
depositor: current_user.user_key,
edit_users: [current_user])
else
create(:public_work, creator: ["Creator"], admin_set_id: admin_set.id, user: current_user)
end
end
let!(:file_set) { wings_disabled ? valkyrie_create(:hyrax_file_set) : create(:file_set) }

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) }
let(:count_of_work_objects) { wings_disabled ? Hyrax.query_service.count_all_of_model(model: Monograph) : GenericWork.count }

before do
::User.group_service.add(user: current_user, groups: ['donor'])
Expand All @@ -21,11 +50,11 @@
it 'changes the value of each field for all selected works' do
click_on 'batch-edit'
fill_in_batch_edit_fields_and_verify!
work1.reload
work2.reload
reloaded_work1 = wings_disabled ? Hyrax.query_service.find_by(id: work1.id) : work1.reload
reloaded_work2 = wings_disabled ? Hyrax.query_service.find_by(id: work2.id) : work2.reload
batch_edit_fields.each do |field|
expect(work1.send(field)).to match_array("NEW #{field}")
expect(work2.send(field)).to match_array("NEW #{field}")
expect(reloaded_work1.send(field)).to match_array("NEW #{field}")
expect(reloaded_work2.send(field)).to match_array("NEW #{field}")
end

# Reload the form and verify
Expand All @@ -34,54 +63,54 @@
find('#batch-edit').click
expect(page).to have_content('Batch Edit Descriptions')
batch_edit_expand("creator") do
page.find("input#generic_work_creator[value='NEW creator']")
page.find("input##{expected_element_text}_creator[value='NEW creator']")
end
batch_edit_expand("contributor") do
page.find("input#generic_work_contributor[value='NEW contributor']", visible: false)
page.find("input##{expected_element_text}_contributor[value='NEW contributor']", visible: false)
end
batch_edit_expand("description") do
page.find("textarea#generic_work_description", text: 'NEW description', visible: false)
page.find("textarea##{expected_element_text}_description", text: 'NEW description', visible: false)
end
batch_edit_expand("keyword") do
page.find("input#generic_work_keyword[value='NEW keyword']", visible: false)
page.find("input##{expected_element_text}_keyword[value='NEW keyword']", visible: false)
end
batch_edit_expand("publisher") do
page.find("input#generic_work_publisher[value='NEW publisher']", visible: false)
page.find("input##{expected_element_text}_publisher[value='NEW publisher']", visible: false)
end
batch_edit_expand("date_created") do
page.find("input#generic_work_date_created[value='NEW date_created']", visible: false)
page.find("input##{expected_element_text}_date_created[value='NEW date_created']", visible: false)
end
batch_edit_expand("subject") do
page.find("input#generic_work_subject[value='NEW subject']", visible: false)
page.find("input##{expected_element_text}_subject[value='NEW subject']", visible: false)
end
batch_edit_expand("language") do
page.find("input#generic_work_language[value='NEW language']", visible: false)
page.find("input##{expected_element_text}_language[value='NEW language']", visible: false)
end
batch_edit_expand("identifier") do
page.find("input#generic_work_identifier[value='NEW identifier']", visible: false)
page.find("input##{expected_element_text}_identifier[value='NEW identifier']", visible: false)
end
# batch_edit_expand("based_near")
# expect(page).to have_css "input#generic_work_based_near[value*='NEW based_near']"
batch_edit_expand("related_url") do
page.find("input#generic_work_related_url[value='NEW related_url']", visible: false)
page.find("input##{expected_element_text}_related_url[value='NEW related_url']", visible: false)
end
end

it 'updates visibility' do
click_on 'batch-edit'
find('#edit_permissions_link').click
batch_edit_expand('permissions_visibility')
find('#generic_work_visibility_authenticated').click
find("##{expected_element_text}_visibility_authenticated").click
find('#permissions_visibility_save').click

expect(page).to have_selector('.status', text: 'Changes Saved', visible: true, wait: 30)

# Verify work is updated
visit "/concern/generic_works/#{work1.id}/edit#share"
page.find('#generic_work_visibility_authenticated:checked')
visit "/concern/#{expected_element_text}s/#{work1.id}/edit#share"
page.find("##{expected_element_text}_visibility_authenticated:checked")

# Verify fileset is updated
visit "concern/file_sets/#{work1.file_sets.first.id}/edit#permissions_display"
visit "concern/file_sets/#{file_set.id}/edit#permissions_display"
page.find('#file_set_visibility_authenticated:checked')
end

Expand All @@ -99,11 +128,11 @@
expect(page).to have_selector('.status', text: 'Changes Saved', visible: true, wait: 30)

# Verify work is updated
visit "/concern/generic_works/#{work1.id}/edit#share"
visit "/concern/#{expected_element_text}s/#{work1.id}/edit#share"
page.find('#share table', text: 'donor')

# Verify fileset is updated
visit "concern/file_sets/#{work1.file_sets.first.id}/edit#permissions_display"
visit "concern/file_sets/#{file_set.id}/edit#permissions_display"
page.find('#permissions_display table', text: 'donor')
end
end
Expand All @@ -112,7 +141,7 @@
it 'destroys the selected works' do
accept_confirm { click_button 'Delete Selected' }
expect(page).to have_content('Batch delete complete')
expect(GenericWork.count).to be_zero
expect(count_of_work_objects).to be_zero
end
end
end
4 changes: 2 additions & 2 deletions spec/support/features/batch_edit_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def fill_in_batch_edit_fields_and_verify!
batch_edit_fields.each do |field_id|
within "#form_#{field_id}" do
batch_edit_expand(field_id)
page.find("#generic_work_#{field_id}") # Ensuring that the element is on the page before we fill it
fill_in "generic_work_#{field_id}", with: "NEW #{field_id}"
page.find("##{expected_element_text}_#{field_id}") # Ensuring that the element is on the page before we fill it
fill_in "#{expected_element_text}_#{field_id}", with: "NEW #{field_id}"

find("##{field_id}_save").click

Expand Down

0 comments on commit 31e6cde

Please sign in to comment.