Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPP-146 amend CHANGE SUBSTANCES page #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/epp-amend/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const titles = require('../../../utilities/constants/titles.js');
const precursorList = require('../../../utilities/constants/explosive-precursors.js');
const helpers = require('../../../utilities/helpers/index.js');
const country = require('../../../utilities/constants/countries');

const countersignatoryYears = require('../../../utilities/constants/countersignatory-years.js');

module.exports = {
Expand Down Expand Up @@ -296,6 +295,15 @@ module.exports = {
validate: ['required', 'date', 'before']
}
),
'amend-change-substances-options': {
mixin: 'radio-group',
legend: {
className: 'govuk-label--m'
},
className: ['govuk-radios', 'govuk-radios--inline'],
options: ['yes', 'no'],
validate: 'required'
},
'amend-precursor-field': {
mixin: 'select',
validate: ['required'],
Expand Down
32 changes: 28 additions & 4 deletions apps/epp-amend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const RemoveDocument = require('../epp-common/behaviours/remove-document');
const DobEditRedirect = require('../epp-common/behaviours/dob-edit-redirect');
const RenderPrecursorDetails = require('../epp-common/behaviours/render-precursors-detail');
const SaveHomeAddress = require('../epp-common/behaviours/save-home-address');
const CheckAndRedirect = require('../epp-common/behaviours/check-answer-redirect');

module.exports = {
name: 'EPP form',
Expand Down Expand Up @@ -66,11 +67,19 @@ module.exports = {
locals: { captionHeading: 'Section 4 of 23' }
},
'/contact-details': {
fields: ['amend-phone-number', 'amend-email'],
fields: [
'amend-phone-number',
'amend-email'
],
locals: { captionHeading: 'Section 5 of 23' },
next: '/amend-details'
},
'/amend-details': {
behaviours: [
CheckAndRedirect('amend-name-options',
['amend-change-substances-options', 'amend-name-options', 'amend-home-address-options']
)
],
fields: ['amend-name-options'],
forks: [
{
Expand Down Expand Up @@ -163,6 +172,11 @@ module.exports = {
locals: { captionHeading: 'Section 9 of 23' }
},
'/change-home-address': {
behaviours: [
CheckAndRedirect('amend-home-address-options',
['amend-change-substances-options', 'amend-name-options', 'amend-home-address-options']
)
],
fields: ['amend-home-address-options'],
forks: [
{
Expand Down Expand Up @@ -205,9 +219,19 @@ module.exports = {
locals: { captionHeading: 'Section 12 of 23' }
},
'/change-substances': {
fields: ['amend-explosive-precusor-type'],
locals: { captionHeading: 'Section 13 of 23' },
next: '/explosives-precursors'
behaviours: [
CheckAndRedirect('amend-change-substances-options',
['amend-change-substances-options', 'amend-name-options', 'amend-home-address-options']
)
],
fields: ['amend-change-substances-options'],
continueOnEdit: true,
next: '/explosives-precursors',
locals: { captionHeading: 'Section 13 of 23' }

},
'/no-details-amend': {
locals: { captionHeading: 'Section 13 of 23' }
},
'/explosives-precursors': {
fields: ['amend-regulated-explosives-precursors'],
Expand Down
14 changes: 11 additions & 3 deletions apps/epp-amend/sections/summary-data-sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ module.exports = {
}
]
},
'amend-licence-for-explosives-precursors': {
'amend-change-substances': {
steps: [
{
steps: '/explosives-precursors',
field: 'amend-regulated-explosives-precursors'
step: '/change-substances',
field: 'amend-change-substances-options'
}
]
},
Expand All @@ -269,6 +269,14 @@ module.exports = {
}
]
},
'amend-licence-for-explosives-precursors': {
steps: [
{
steps: '/explosives-precursors',
field: 'amend-regulated-explosives-precursors'
}
]
},
'countersignatory-details': {
steps: [
{
Expand Down
12 changes: 11 additions & 1 deletion apps/epp-amend/translations/src/en/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"label": "What is your driving licence number?",
"hint" : "On section 5 of your licence, for example MORGA657054SM9IJ"
},

"amend-home-address-options": {
"legend": "Do you need to amend your home address on the licence?",
"options": {
Expand Down Expand Up @@ -148,6 +147,17 @@
"legend": "What date did you change your address?",
"hint": " For example, 30 09 1969"
},
"amend-change-substances-options":{
"legend": "Do you need to amend the substances on your licence?",
"options": {
"yes": {
"label": "Yes"
},
"no": {
"label": "No"
}
}
},
"amend-precursor-field": {
"hint": "Select an explosives precursor",
"options":{
Expand Down
10 changes: 10 additions & 0 deletions apps/epp-amend/translations/src/en/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
"not-uploaded": "No files uploaded",
"uploaded": "File uploaded"
},
"change-substances": {
"header": "Change in substances",
"paragraph1": "You must amend the substances on your licence if you:",
"li1": "need to add or remove substances you can acquire, possess or use",
"li2": "need to change the concentration or volume of substances that your licence covers",
"li3": "have changed your storage or usage address since your current licence was issued"
},
"select-precursor": {
"header": "Explosives precursors",
"p1": "Tell us which explosives precursors you want to import acquire use or possess.",
Expand Down Expand Up @@ -153,6 +160,9 @@
"amend-new-home-address": {
"header": "New address"
},
"amend-change-substances": {
"header": "Amend substances"
},
"amend-licence-for-explosives-precursors": {
"header": "Licence for explosives precursors"
},
Expand Down
17 changes: 17 additions & 0 deletions apps/epp-amend/views/change-substances.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{<partials-page}}
{{$page-content}}
<div>
<p class="govuk-body">{{#t}}pages.change-substances.paragraph1{{/t}}</p>
<ul class="govuk-list govuk-list--bullet">
<li>{{#t}}pages.change-substances.li1{{/t}}</li>
<li>{{#t}}pages.change-substances.li2{{/t}}</li>
<li>{{#t}}pages.change-substances.li3{{/t}}</li>
</ul>
</div>

{{#fields}}
{{#renderField}}amend-change-substances-options{{/renderField}}
{{/fields}}
{{#input-submit}}continue{{/input-submit}}
{{/page-content}}
{{/partials-page}}
13 changes: 13 additions & 0 deletions apps/epp-common/behaviours/check-answer-redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = (currentField, fieldsArray) => superclass =>
class extends superclass {
successHandler(req, res, next) {
const allFieldsNo = fieldsArray.every(fieldsArrayValue => req.sessionModel.get(fieldsArrayValue) === 'no');
if (allFieldsNo) {
return res.redirect(`${req.baseUrl}/no-details-amend`);
} else if (req.form.values[currentField] === 'no' && !allFieldsNo
&& currentField === 'amend-change-substances-options') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above logic doesn't seem to cover AC6 on the ticket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since AC6 contains more requirement, can you be more specific? which condition is not covered?

return res.redirect(`${req.baseUrl}/countersignatory-details`);
}
return super.successHandler(req, res, next);
}
};
101 changes: 101 additions & 0 deletions test/unit/behaviours/check-answer-redirect.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const Behaviour = require('../../../apps/epp-common/behaviours/check-answer-redirect');

describe('Tests for check-answer-redirect behaviour', () => {
class Base {
constructor() {}
successHandler() {}
}

let req;
let res;
let instance;
const next = sinon.spy();

beforeEach(() => {
req = reqres.req();
res = reqres.res();
});
describe('successHandler tests', () => {
beforeEach(() => {
sinon.stub(Base.prototype, 'successHandler').returns(req, res, next);
instance = new (Behaviour('test-field-name', [
'test-field-name',
'test-field-name-two',
'test-field-name-three'])(Base))();
});

it('init - successHandler', () => {
instance.successHandler(req, res, next);
expect(Base.prototype.successHandler).to.have.been.called;
});

it('All fields answer is - no - should redirect to the given redirect /no-details-amend - ', () => {
req = {
sessionModel: {
set: sinon.spy(),
get: fieldName => req.sessionModel[fieldName],
'test-field-name-three': 'no',
'test-field-name-two': 'no',
'test-field-name': 'no'
},
originalUrl: 'http://domain/path',
baseUrl: '/amend'
};
instance.successHandler(req, res, next);
expect(res.redirect.calledOnce).to.be.true;
expect(res.redirect.calledWith(`${req.baseUrl}/no-details-amend`)).to.be.true;
expect(req.sessionModel.set.calledWith('test-field-name', 'no'));
});

it('current fields answer is - no - should redirect to the given redirect /countersignatory-details - ', () => {
req = {
sessionModel: {
set: sinon.spy(),
get: fieldName => req.sessionModel[fieldName],
'test-field-name-three': 'yes',
'test-field-name-two': 'yes',
'test-field-name': 'no'
},
originalUrl: 'http://domain/path',
baseUrl: '/amend',
currentField: 'amend-change-substances-options',
form: {
values: {
'amend-change-substances-options': 'no'
}
}
};
instance = new (Behaviour('amend-change-substances-options', [
'test-field-name',
'test-field-name-two',
'test-field-name-three'])(Base))();
instance.successHandler(req, res, next);
expect(res.redirect.calledOnce).to.be.true;
expect(res.redirect.calledWith(`${req.baseUrl}/countersignatory-details`)).to.be.true;
expect(req.sessionModel.set.calledWith('test-field-name', 'no'));
});

it('current fields answer is - yes - should redirect to the next step - ', () => {
req = {
sessionModel: {
get: sinon.stub().returns('yes'),
'test-field-name': 'yes'
},
originalUrl: 'http://domain/path',
baseUrl: '/amend',
form: {
values: {
'test-field-name': 'yes'
}
}
};
instance.successHandler(req, res, next);
expect(res.redirect.calledOnce).to.be.false;
sinon.assert.calledWithExactly(Base.prototype.successHandler, req, res, next);
});

afterEach(() => {
Base.prototype.successHandler.restore();
});
});
});