Skip to content

Commit

Permalink
Utilizes Valkyrie patterns for edit_work_spec. (#6480)
Browse files Browse the repository at this point in the history
* Utilizes Valkyrie patterns for edit_work_spec.

* corrects oversight.
  • Loading branch information
bwatson78 authored Nov 30, 2023
1 parent 36c7d9e commit 0e59784
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions spec/features/edit_work_spec.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
# frozen_string_literal: true
RSpec.describe 'Editing a work', type: :feature do
let(:user) { FactoryBot.create(:user, groups: 'librarians') }
let(:user_admin) { FactoryBot.create(:user, groups: 'admin') }
let(:work) { FactoryBot.build(:work, user: user, admin_set: another_admin_set) }
let(:default_admin_set) do
FactoryBot.create(:admin_set, id: AdminSet::DEFAULT_ID,
title: ["Default Admin Set"],
description: ["A description"],
edit_users: [user.user_key])
RSpec.describe 'Editing a work', :clean_repo, type: :feature do
let(:user) { create(:user, groups: 'librarians') }
let(:user_admin) { create(:user, groups: 'admin') }
let(:work) { valkyrie_create(:monograph, :with_one_file_set, depositor: user.user_key, admin_set_id: another_admin_set.id, edit_users: [user.user_key]) }
let!(:default_admin_set) do
valkyrie_create(:hyrax_admin_set,
title: Hyrax::AdminSetCreateService::DEFAULT_TITLE,
edit_users: [user.user_key],
with_permission_template: true,
access_grants: [{ agent_type: Hyrax::PermissionTemplateAccess::USER,
agent_id: user.user_key,
access: Hyrax::PermissionTemplateAccess::DEPOSIT }])
end
let(:another_admin_set) do
FactoryBot.create(:admin_set, title: ["Another Admin Set"],
description: ["A description"],
edit_users: [user.user_key])
valkyrie_create(:hyrax_admin_set,
edit_users: [user.user_key],
with_permission_template: true,
access_grants: [{ agent_type: Hyrax::PermissionTemplateAccess::USER,
agent_id: user.user_key,
access: Hyrax::PermissionTemplateAccess::DEPOSIT }])
end

before do
sign_in user
work.ordered_members << create(:file_set, user: user, title: ['ABC123xyz'])
work.read_groups = []
work.save!

create(:permission_template_access,
:deposit,
permission_template: create(:permission_template, source_id: default_admin_set.id, with_admin_set: true, with_active_workflow: true),
agent_type: 'user',
agent_id: user.user_key)
create(:permission_template_access,
:deposit,
permission_template: create(:permission_template, source_id: another_admin_set.id, with_admin_set: true, with_active_workflow: true),
agent_type: 'user',
agent_id: user.user_key)
Hyrax::DefaultAdministrativeSet.update(default_admin_set_id: default_admin_set.id)
end

context 'when the user changes permissions' do
let(:work) { create(:private_work, user: user, admin_set: default_admin_set) }
let(:work) { valkyrie_create(:monograph, title: ['Haiku'], depositor: user.user_key, admin_set_id: default_admin_set.id, edit_users: [user.user_key]) }

it 'confirms copying permissions to files using Hyrax layout and shows updated value' do
# e.g. /concern/generic_works/jq085k20z/edit
visit edit_hyrax_generic_work_path(work)
choose('generic_work_visibility_open')
visit edit_hyrax_monograph_path(work)
choose('monograph_visibility_open')
check('agreement')
click_on('Save')
expect(page).to have_content 'Apply changes to contents?'
expect(page).not_to have_content "Powered by Hyrax"
click_on("No. I'll update it manually.")
within(".work-title-wrapper") do
expect(page).to have_content('Public')
end
Expand All @@ -53,13 +43,13 @@

context 'when form loads' do
it 'selects admin set already assigned' do
visit edit_hyrax_generic_work_path(work)
visit edit_hyrax_monograph_path(work)
click_link "Relationships" # switch tab
expect(page).to have_select('generic_work_admin_set_id', selected: another_admin_set.title)
expect(page).to have_select('monograph_admin_set_id', selected: another_admin_set.title)
end

it 'selects group assigned to user' do
visit edit_hyrax_generic_work_path(work)
visit edit_hyrax_monograph_path(work)
click_link "Sharing" # switch tab
expect(page).to have_selector('#new_group_name_skel', text: 'librarians')
end
Expand All @@ -73,7 +63,7 @@
it 'selects group all available groups' do
FactoryBot.create(:user, groups: 'donor')

visit edit_hyrax_generic_work_path(work)
visit edit_hyrax_monograph_path(work)
click_link "Sharing" # switch tab
expect(page).to have_selector('#new_group_name_skel', text: 'librarians admin donor')
end
Expand Down

0 comments on commit 0e59784

Please sign in to comment.