diff --git a/app/assets/javascripts/hyrax/save_work/save_work_control.es6 b/app/assets/javascripts/hyrax/save_work/save_work_control.es6
index 906fc2eed3..0c34ad9337 100644
--- a/app/assets/javascripts/hyrax/save_work/save_work_control.es6
+++ b/app/assets/javascripts/hyrax/save_work/save_work_control.es6
@@ -87,6 +87,7 @@ export default class SaveWorkControl {
this.depositAgreement = new DepositAgreement(this.form, () => this.formStateChanged())
this.requiredMetadata = new ChecklistItem(this.element.find('#required-metadata'))
this.requiredFiles = new ChecklistItem(this.element.find('#required-files'))
+ this.requiredAgreement = new ChecklistItem(this.element.find('#required-agreement'))
new VisibilityComponent(this.element.find('.visibility'), this.adminSetWidget)
this.preventSubmit()
this.watchMultivaluedFields()
@@ -151,8 +152,14 @@ export default class SaveWorkControl {
if (filesValid && this.uploads.hasNewFiles && this.depositAgreement.mustAgreeAgain) {
// Force the user to agree again
this.depositAgreement.setNotAccepted()
+ this.requiredAgreement.uncheck()
return false
}
- return this.depositAgreement.isAccepted
+ if (!this.depositAgreement.isAccepted) {
+ this.requiredAgreement.uncheck()
+ return false
+ }
+ this.requiredAgreement.check()
+ return true
}
}
diff --git a/app/views/hyrax/base/_form_progress.html.erb b/app/views/hyrax/base/_form_progress.html.erb
index 056aba7eaf..82793481dc 100644
--- a/app/views/hyrax/base/_form_progress.html.erb
+++ b/app/views/hyrax/base/_form_progress.html.erb
@@ -11,6 +11,9 @@
<% if Hyrax.config.work_requires_files? %>
<%= t('.required_files') %>
<% end %>
+ <% if Flipflop.active_deposit_agreement_acceptance? %>
+ <%= t('.required_agreement') %>
+ <% end %>
diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml
index 602c064437..f38b7f8472 100644
--- a/config/locales/hyrax.en.yml
+++ b/config/locales/hyrax.en.yml
@@ -241,6 +241,7 @@ en:
form_progress:
required_descriptions: Describe your work
required_files: Add files
+ required_agreement: Check deposit agreement
requirements: Requirements
items:
actions: Actions
diff --git a/config/locales/hyrax.es.yml b/config/locales/hyrax.es.yml
index ac12cda97d..4eee90c5f7 100644
--- a/config/locales/hyrax.es.yml
+++ b/config/locales/hyrax.es.yml
@@ -240,6 +240,7 @@ es:
form_progress:
required_descriptions: Describa su trabajo
required_files: Agregar archivos
+ required_agreement: Comprobar el acuerdo de depĆ³sito
requirements: Requisitos
items:
actions: Acciones
diff --git a/spec/javascripts/save_work_spec.js b/spec/javascripts/save_work_spec.js
index bec64a32a3..672cce4006 100644
--- a/spec/javascripts/save_work_spec.js
+++ b/spec/javascripts/save_work_spec.js
@@ -11,7 +11,7 @@ describe("SaveWorkControl", function() {
beforeEach(function() {
var fixture = setFixtures('');
admin_set = new AdminSetWidget(fixture.find('select'))
@@ -49,27 +49,39 @@ describe("SaveWorkControl", function() {
});
describe("validateAgreement", function() {
- var target;
+ var mockCheckbox = {
+ check: function() { },
+ uncheck: function() { },
+ };
beforeEach(function() {
var fixture = setFixtures('');
target = new SaveWorkControl(fixture.find('#form-progress'));
+ spyOn(mockCheckbox, 'check').and.stub();
+ spyOn(mockCheckbox, 'uncheck').and.stub();
target.activate()
+ target.requiredAgreement = mockCheckbox;
});
it("forces user to agree if new files are added", function() {
// Agreement starts as accepted...
target.uploads = { hasNewFiles: false };
expect(target.validateAgreement(true)).toEqual(true);
+ expect(mockCheckbox.uncheck.calls.count()).toEqual(0);
+ expect(mockCheckbox.check.calls.count()).toEqual(1);
// ...and becomes not accepted as soon as the user adds new files...
target.uploads = { hasNewFiles: true };
expect(target.validateAgreement(true)).toEqual(false);
+ expect(mockCheckbox.uncheck.calls.count()).toEqual(1);
+ expect(mockCheckbox.check.calls.count()).toEqual(1);
// ...but allows the user to manually agree again.
target.depositAgreement.setAccepted();
expect(target.validateAgreement(true)).toEqual(true);
+ expect(mockCheckbox.uncheck.calls.count()).toEqual(1);
+ expect(mockCheckbox.check.calls.count()).toEqual(2);
});
});
@@ -83,7 +95,7 @@ describe("SaveWorkControl", function() {
var buildTarget = function(form_id) {
var buildFixture = function(id) {
return setFixtures('')
}
@@ -144,7 +156,7 @@ describe("SaveWorkControl", function() {
describe("activate", function() {
var target;
beforeEach(function() {
- var fixture = setFixtures('');
+ var fixture = setFixtures('');
target = new SaveWorkControl(fixture.find('#form-progress'));
target.activate()
});
@@ -155,6 +167,7 @@ describe("SaveWorkControl", function() {
expect(target.depositAgreement).toBeDefined();
expect(target.requiredMetadata).toBeDefined();
expect(target.requiredFiles).toBeDefined();
+ expect(target.requiredAgreement).toBeDefined();
expect(target.saveButton).toBeDisabled();
});
@@ -163,7 +176,7 @@ describe("SaveWorkControl", function() {
describe("on submit", function() {
var target;
beforeEach(function() {
- var fixture = setFixtures('');
+ var fixture = setFixtures('');
target = new SaveWorkControl(fixture.find('#form-progress'));
target.activate()
});
diff --git a/spec/views/hyrax/base/_form_progress.html.erb_spec.rb b/spec/views/hyrax/base/_form_progress.html.erb_spec.rb
index 1f10c3f8ff..8c3fa81a26 100644
--- a/spec/views/hyrax/base/_form_progress.html.erb_spec.rb
+++ b/spec/views/hyrax/base/_form_progress.html.erb_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'hyrax/base/_form_progress.html.erb', type: :view do
+RSpec.describe 'hyrax/base/_form_progress.html.erb', type: :view do
let(:ability) { double }
let(:user) { stub_model(User) }
let(:form) do
@@ -47,7 +47,12 @@
end
context "with active deposit agreement" do
+ before do
+ allow(Flipflop).to receive(:active_deposit_agreement_acceptance?)
+ .and_return(true)
+ end
it "shows accept text" do
+ expect(page).to have_content 'Check deposit agreement'
expect(page).to have_content 'I have read and agree to the'
expect(page).to have_link 'Deposit Agreement', href: '/agreement'
expect(page).not_to have_selector("#agreement[checked]")
@@ -60,6 +65,7 @@
.and_return(false)
end
it "shows accept text" do
+ expect(page).not_to have_content 'Check deposit agreement'
expect(page).to have_content 'By saving this work I agree to the'
expect(page).to have_link 'Deposit Agreement', href: '/agreement'
end
@@ -85,6 +91,8 @@
# TODO: stub_model is not stubbing new_record? correctly on ActiveFedora models.
allow(work).to receive(:new_record?).and_return(false)
assign(:form, form)
+ allow(Hyrax.config).to receive(:active_deposit_agreement_acceptance)
+ .and_return(true)
end
let(:work) { stub_model(GenericWork, id: '456', etag: '123456') }