Skip to content

Commit

Permalink
Check your requirements page (with requirements summary cards) (#1019)
Browse files Browse the repository at this point in the history
* Returns required journey - Check your requirements page (with requirements summary cards)

https://eaflood.atlassian.net/browse/WATER-4386

This branch will add summary cards to the `check` page in the returns journey to display the customer's requirements.

Each box will reflect the requirements details (item, quantity etc) and link to the relevant requirement page.

This will provide a quick overview for the user on the `check` page.

---------

Co-authored-by: jonathangoulding <[email protected]>
Co-authored-by: Robert Parkinson <[email protected]>
Co-authored-by: Jonathan Goulding <[email protected]>
  • Loading branch information
4 people authored May 31, 2024
1 parent 8bb5325 commit 825ad2d
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 17 deletions.
28 changes: 23 additions & 5 deletions app/presenters/return-requirements/check.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module CheckPresenter
*/

const { formatLongDate } = require('../base.presenter.js')
const { formatAbstractionDate, formatLongDate } = require('../base.presenter.js')
const { returnRequirementReasons } = require('../../lib/static-lookups.lib.js')

function go (session) {
Expand All @@ -26,6 +26,14 @@ function go (session) {
}
}

function _abstractionPeriod (abstractionPeriod) {
const { 'start-abstraction-period-day': startDay, 'start-abstraction-period-month': startMonth, 'end-abstraction-period-day': endDay, 'end-abstraction-period-month': endMonth } = abstractionPeriod
const startDate = formatAbstractionDate(startDay, startMonth)
const endDate = formatAbstractionDate(endDay, endMonth)

return `From ${startDate} to ${endDate}`
}

function _reasonLink (sessionId, journey) {
if (journey === 'returns-required') {
return `/system/return-requirements/${sessionId}/reason`
Expand All @@ -39,19 +47,29 @@ function _requirements (session) {

const completedRequirements = []

for (const requirement of requirements) {
const { siteDescription, agreementsExceptions } = requirement

for (const [index, requirement] of requirements.entries()) {
const { agreementsExceptions } = requirement
// NOTE: We determine a requirement is complete because agreement exceptions is populated and it is the last step in
// the journey
if (agreementsExceptions) {
completedRequirements.push({ siteDescription })
completedRequirements.push(_mapRequirement(requirement, index))
}
}

return completedRequirements
}

function _mapRequirement (requirement, index) {
return {
abstractionPeriod: _abstractionPeriod(requirement.abstractionPeriod),
frequencyCollected: requirement.frequencyCollected,
frequencyReported: requirement.frequencyReported,
index,
purposes: 'purpose',
siteDescription: requirement.siteDescription
}
}

function _startDate (session) {
const { licence, startDateOptions, startDateDay, startDateMonth, startDateYear } = session

Expand Down
164 changes: 154 additions & 10 deletions app/views/return-requirements/check.njk
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,162 @@
preventDoubleClick: true
}) }}
</form>

{% for requirement in requirements %}
{# Set an easier to use index #}
{% set rowIndex = loop.index0 %}
<div>
<h3 class="govuk-body">{{requirement.siteDescription}}</h3>
{{ govukButton({
text: "Remove requirement",
classes: "govuk-button--warning",
preventDoubleClick: true,
href: "/system/return-requirements/" + sessionId + "/remove/" + rowIndex
}) }}
{{ govukSummaryList({
card: {
title: {
text: requirement.siteDescription
}
},
classes: "govuk-summary-list--no-border",
rows: [
{
key: {
text: "Purpose"
},
value: {
html: "requirement.purposes"
},
actions: {
items: [
{
href: "purpose/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Purpose"
}
]
}
},
{
key: {
text: "Point"
},
value: {
html: "requirement.points"
},
actions: {
items: [
{
href: "points/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Point"
}
]
}
},
{
key: {
text: "Abstraction period"
},
value: {
html: requirement.abstractionPeriod
},
actions: {
items: [
{
href: "abstraction-period/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Abstraction period"
}
]
}
},
{
key: {
text: "Returns cycle"
},
value: {
html: "requirement.returnsCycle"
},
actions: {
items: [
{
href: "returns-cycle/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Returns cycle"
}
]
}
},
{
key: {
text: "Site description"
},
value: {
html: requirement.siteDescription
},
actions: {
items: [
{
href: "site-description/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Site description"
}
]
}
},
{
key: {
text: "Collection"
},
value: {
html: requirement.frequencyCollected | capitalize
},
actions: {
items: [
{
href: "frequency-collected/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Collection"
}
]
}
},
{
key: {
text: "Reporting"
},
value: {
html: requirement.frequencyReported | capitalize
},
actions: {
items: [
{
href: "frequency-reported/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Reporting"
}
]
}
},
{
key: {
text: "Agreements exceptions"
},
value: {
html: "requirement.agreementsExceptions"
},
actions: {
items: [
{
href: "agreements-exceptions/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Agreements exception"
}
]
}
}
]
}) }}
{% if requirements.length >= 2 %}
{{ govukButton({
text: "Remove requirement",
classes: "govuk-button--warning",
preventDoubleClick: true,
href: "/system/return-requirements/" + sessionId + "/remove/" + requirement.index
}) }}
{% endif %}
</div>
{% endfor %}
</div>
Expand Down
63 changes: 61 additions & 2 deletions test/presenters/return-requirements/check.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@ const CheckPresenter = require('../../../app/presenters/return-requirements/chec

describe('Return Requirements - Check presenter', () => {
let session
let requirement

beforeEach(() => {
requirement = {
points: [
'286'
],
purposes: [
'772136d1-9184-417b-90cd-91053287d1df'
],
returnsCycle: 'summer',
siteDescription: 'A place in the sun',
abstractionPeriod: {
'end-abstraction-period-day': '01',
'end-abstraction-period-month': '03',
'start-abstraction-period-day': '01',
'start-abstraction-period-month': '06'
},
frequencyReported: 'daily',
frequencyCollected: 'daily',
agreementsExceptions: [
'gravity-fill'
]
}

session = {
id: '61e07498-f309-4829-96a9-72084a54996d',
checkPageVisited: false,
Expand All @@ -26,7 +49,7 @@ describe('Return Requirements - Check presenter', () => {
startDate: '2022-04-01T00:00:00.000Z'
},
journey: 'returns-required',
requirements: [{}],
requirements: [{ ...requirement }],
startDateOptions: 'licenceStartDate',
reason: 'major-change'
}
Expand All @@ -44,7 +67,14 @@ describe('Return Requirements - Check presenter', () => {
pageTitle: 'Check the return requirements for Turbo Kid',
reason: 'Major change',
reasonLink: '/system/return-requirements/61e07498-f309-4829-96a9-72084a54996d/reason',
requirements: [],
requirements: [{
abstractionPeriod: 'From 1 June to 1 March',
frequencyCollected: 'daily',
frequencyReported: 'daily',
index: 0,
purposes: 'purpose',
siteDescription: 'A place in the sun'
}],
sessionId: '61e07498-f309-4829-96a9-72084a54996d',
startDate: '1 January 2023',
userEmail: 'No notes added'
Expand Down Expand Up @@ -187,4 +217,33 @@ describe('Return Requirements - Check presenter', () => {
})
})
})

describe("the 'requirements' property", () => {
describe('when the requirement has agreements exceptions', () => {
it('correctly returns and requirement with agreements exceptions', () => {
const result = CheckPresenter.go(session)

expect(result.requirements).to.equal([{
abstractionPeriod: 'From 1 June to 1 March',
frequencyCollected: 'daily',
frequencyReported: 'daily',
index: 0,
purposes: 'purpose',
siteDescription: 'A place in the sun'
}
])
})
})
describe('when the requirement does not have any agreements exceptions', () => {
beforeEach(() => {
delete session.requirements[0].agreementsExceptions
})

it('correctly does not return the requirement', () => {
const result = CheckPresenter.go(session)

expect(result.requirements).to.equal([])
})
})
})
})

0 comments on commit 825ad2d

Please sign in to comment.