Skip to content

Commit

Permalink
Fix save button remaining inactive after upload completes (with passi…
Browse files Browse the repository at this point in the history
…ve deposit agreements) (#6530)

* Add test to verify agreement button goes away when active deposit agreement is toggled off, which should currently fail due to issue 6517

* Track whether an upload is in progress directly via an instance variable, since fileupload('active') is not getting updated before the completed or done event triggers.

* Switch to using have_selector
  • Loading branch information
bbpennel authored Dec 12, 2023
1 parent 9b5b5ed commit d201349
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/assets/javascripts/hyrax/save_work/uploaded_files.es6
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ export class UploadedFiles {
constructor(form, callback) {
this.form = form
this.element = $('#fileupload')
this.element.on('fileuploadcompleted', callback)
this.uploadsInProgress = 0
this.element.on('fileuploadadded', (e, data) => {
this.uploadsInProgress += 1
callback(e, data)
})
this.element.on('fileuploadcompleted', (e, data) => {
this.uploadsInProgress -= 1
callback(e, data)
})
this.element.on('fileuploaddestroyed', callback)
}

Expand All @@ -13,7 +21,7 @@ export class UploadedFiles {
}

get inProgress() {
return this.element.fileupload('active') > 0
return this.uploadsInProgress > 0;
}

get hasFiles() {
Expand Down
50 changes: 50 additions & 0 deletions spec/features/deposit_agreements_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true
RSpec.describe 'Deposit Agreement options', :js, :workflow, :clean_repo do
let(:user) { create(:user) }
let(:admin_user) { create(:admin) }
# let(:adminset) { create(:admin_set) }
let!(:ability) { ::Ability.new(user) }
let(:permission_template) { create(:permission_template, with_admin_set: true, with_active_workflow: true) }

before do
# Grant the user access to deposit into an admin set.
create(:permission_template_access, :deposit, permission_template: permission_template, agent_type: 'user', agent_id: user.user_key)
# stub out characterization
allow(CharacterizeJob).to receive(:perform_later)
end

context "with activate deposit agreement off" do
before do
sign_in admin_user
# Disable active agreements
visit "/admin/features"
first("tr[data-feature='active-deposit-agreement-acceptance'] input[value='off']").click

sign_in user
click_link 'Works'
find('#add-new-work-button').click
choose "payload_concern", option: "GenericWork"
click_button 'Create work'
end

it "allows saving work when active deposit agreement is off" do
expect(page).to have_selector('input[name="save_with_files"][disabled]')

# Fill in required metadata
fill_in('Title', with: 'My Test Work')
fill_in('Creator', with: 'Doe, Jane')
select('In Copyright', from: 'Rights statement')

expect(page).to have_selector('input[name="save_with_files"]:not([disabled])')

# Add a file
click_link "Files"
within('div#add-files') do
attach_file("files[]", "#{Hyrax::Engine.root}/spec/fixtures/image.jp2", visible: false)
end

expect(page).not_to have_selector('#agreement')
expect(page).to have_selector('input[name="save_with_files"]:not([disabled])')
end
end
end

0 comments on commit d201349

Please sign in to comment.