Skip to content

Commit

Permalink
Add deposit agreement to checklist on work save form
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored and jcoyne committed Mar 24, 2017
1 parent 9c48db8 commit 52deeb6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
9 changes: 8 additions & 1 deletion app/assets/javascripts/hyrax/save_work/save_work_control.es6
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
3 changes: 3 additions & 0 deletions app/views/hyrax/base/_form_progress.html.erb
Expand Up @@ -11,6 +11,9 @@
<% if Hyrax.config.work_requires_files? %>
<li class="incomplete" id="required-files"><%= t('.required_files') %></li>
<% end %>
<% if Flipflop.active_deposit_agreement_acceptance? %>
<li class="incomplete" id="required-agreement"><%= t('.required_agreement') %></li>
<% end %>
</ul>
</fieldset>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/locales/hyrax.en.yml
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/hyrax.es.yml
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions spec/javascripts/save_work_spec.js
Expand Up @@ -11,7 +11,7 @@ describe("SaveWorkControl", function() {
beforeEach(function() {
var fixture = setFixtures('<form id="edit_generic_work">' +
'<select><option></option></select>' +
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul>' +
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"><li id="required-agreement"></ul>' +
'<input type="checkbox" name="agreement" id="agreement" value="1" required="required" checked="checked" />' +
'<input type="submit"></aside></form>');
admin_set = new AdminSetWidget(fixture.find('select'))
Expand Down Expand Up @@ -49,27 +49,39 @@ describe("SaveWorkControl", function() {
});

describe("validateAgreement", function() {
var target;
var mockCheckbox = {
check: function() { },
uncheck: function() { },
};
beforeEach(function() {
var fixture = setFixtures('<form id="edit_generic_work">' +
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul>' +
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"><li id="required-agreement"></ul>' +
'<input type="checkbox" name="agreement" id="agreement" value="1" required="required" checked="checked" />' +
'<input type="submit"></aside></form>');
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);
});
});

Expand All @@ -83,7 +95,7 @@ describe("SaveWorkControl", function() {
var buildTarget = function(form_id) {
var buildFixture = function(id) {
return setFixtures('<form id="' + id + '">' +
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul>' +
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"><li id="required-agreement"></ul>' +
'<input type="checkbox" name="agreement" id="agreement" value="1" required="required" checked="checked" />' +
'<input type="submit"></aside></form>')
}
Expand Down Expand Up @@ -144,7 +156,7 @@ describe("SaveWorkControl", function() {
describe("activate", function() {
var target;
beforeEach(function() {
var fixture = setFixtures('<form id="new_generic_work"><aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul><input type="submit"></aside></form>');
var fixture = setFixtures('<form id="new_generic_work"><aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"><li id="required-agreement"></ul><input type="submit"></aside></form>');
target = new SaveWorkControl(fixture.find('#form-progress'));
target.activate()
});
Expand All @@ -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();
});

Expand All @@ -163,7 +176,7 @@ describe("SaveWorkControl", function() {
describe("on submit", function() {
var target;
beforeEach(function() {
var fixture = setFixtures('<form id="new_generic_work"><aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul><input type="submit"></aside></form>');
var fixture = setFixtures('<form id="new_generic_work"><aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"><li id="required-agreement"></ul><input type="submit"></aside></form>');
target = new SaveWorkControl(fixture.find('#form-progress'));
target.activate()
});
Expand Down
10 changes: 9 additions & 1 deletion 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
Expand Down Expand Up @@ -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]")
Expand All @@ -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
Expand All @@ -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') }
Expand Down

0 comments on commit 52deeb6

Please sign in to comment.