Skip to content

Commit

Permalink
Return to Check Your Answers after making a change (#959)
Browse files Browse the repository at this point in the history
* Return to Check Your Answers after making a change

This is a PR focused on adding the ability to return to the Check Your Answers page after
updating a previously submitted page in the return requirements journey.

When a user reaches the Check Your Answers page at the end of the return requirements journey,
they are given the option to update previously entered options. After making a change, users
should be navigated back to the Check Your Answers page instead of continuing through the
already completed journey.
  • Loading branch information
rvsiyad authored May 1, 2024
1 parent 12903e2 commit c05be58
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 24 deletions.
32 changes: 32 additions & 0 deletions app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ async function submitAbstractionPeriod (request, h) {
return h.view('return-requirements/abstraction-period.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/returns-cycle`)
}

Expand All @@ -229,6 +233,10 @@ async function submitAgreementsExceptions (request, h) {
return h.view('return-requirements/agreements-exceptions.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

Expand All @@ -254,6 +262,10 @@ async function submitFrequencyCollected (request, h) {
return h.view('return-requirements/frequency-collected.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/frequency-reported`)
}

Expand All @@ -266,6 +278,10 @@ async function submitFrequencyReported (request, h) {
return h.view('return-requirements/frequency-reported.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/agreements-exceptions`)
}

Expand All @@ -290,6 +306,10 @@ async function submitPoints (request, h) {
return h.view('return-requirements/points.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/abstraction-period`)
}

Expand All @@ -302,6 +322,10 @@ async function submitPurpose (request, h) {
return h.view('return-requirements/purpose.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/points`)
}

Expand Down Expand Up @@ -330,6 +354,10 @@ async function submitReturnsCycle (request, h) {
return h.view('return-requirements/returns-cycle.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/site-description`)
}

Expand All @@ -354,6 +382,10 @@ async function submitSiteDescription (request, h) {
return h.view('return-requirements/site-description.njk', pageData)
}

if (pageData.checkYourAnswersVisited) {
return h.redirect(`/system/return-requirements/${sessionId}/check-your-answers`)
}

return h.redirect(`/system/return-requirements/${sessionId}/frequency-collected`)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const submittedSessionData = _submittedSessionData(session, payload)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Enter the abstraction period for the requirements for returns',
...submittedSessionData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const formattedData = AgreementsExceptionsPresenter.go(session, payload)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select agreements and exceptions for the requirements for returns',
...formattedData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const formattedData = FrequencyCollectedPresenter.go(session)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select how often readings or volumes are collected',
...formattedData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const formattedData = FrequencyReportedPresenter.go(session)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select how often readings or volumes are reported',
...formattedData
Expand Down
5 changes: 4 additions & 1 deletion app/services/return-requirements/submit-points.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const pointsData = await FetchPointsService.go(session.data.licence.id)
const formattedData = PointsPresenter.go(session, pointsData)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select the points for the requirements for returns',
...formattedData
Expand Down
5 changes: 4 additions & 1 deletion app/services/return-requirements/submit-purpose.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const purposesData = await FetchPurposesService.go(session.data.licence.id)
const formattedData = PurposePresenter.go(session, purposesData)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select the purpose for the requirements for returns',
...formattedData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const formattedData = ReturnsCyclePresenter.go(session)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Select the returns cycle for the requirements for returns',
...formattedData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

return {}
return {
checkYourAnswersVisited: session.data.checkYourAnswersVisited
}
}

const submittedSessionData = _submittedSessionData(session, payload)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
pageTitle: 'Enter a site description for the requirements for returns',
...submittedSessionData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Submit Abstraction Period service', () => {

session = await SessionHelper.add({
data: {
checkYourAnswersVisited: false,
licence: {
id: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
currentVersionStartDate: '2023-01-01T00:00:00.000Z',
Expand Down Expand Up @@ -60,10 +61,12 @@ describe('Submit Abstraction Period service', () => {
})
})

it('returns an empty object (no page data needed for a redirect)', async () => {
it('returns the checkYourAnswersVisited property (no page data needed for a redirect)', async () => {
const result = await SubmitAbstractionPeriodService.go(session.id, payload)

expect(result).to.equal({})
expect(result).to.equal({
checkYourAnswersVisited: false
})
})
})

Expand All @@ -85,6 +88,7 @@ describe('Submit Abstraction Period service', () => {
expect(result).to.equal({
abstractionPeriod: null,
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Enter the abstraction period for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down Expand Up @@ -126,6 +130,7 @@ describe('Submit Abstraction Period service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Enter the abstraction period for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down Expand Up @@ -173,6 +178,7 @@ describe('Submit Abstraction Period service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Enter the abstraction period for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down Expand Up @@ -220,6 +226,7 @@ describe('Submit Abstraction Period service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Enter the abstraction period for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down Expand Up @@ -267,6 +274,7 @@ describe('Submit Abstraction Period service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Enter the abstraction period for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down Expand Up @@ -314,6 +322,7 @@ describe('Submit Abstraction Period service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Enter the abstraction period for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Submit Agreements and Exceptions service', () => {

session = await SessionHelper.add({
data: {
checkYourAnswersVisited: false,
licence: {
id: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
currentVersionStartDate: '2023-01-01T00:00:00.000Z',
Expand Down Expand Up @@ -60,10 +61,12 @@ describe('Submit Agreements and Exceptions service', () => {
])
})

it('returns an empty object (no page data needed for a redirect)', async () => {
it('returns the checkYourAnswersVisited property (no page data needed for a redirect)', async () => {
const result = await SubmitAgreementsExceptionsService.go(session.id, payload)

expect(result).to.equal({})
expect(result).to.equal({
checkYourAnswersVisited: false
})
})
})
})
Expand All @@ -85,6 +88,7 @@ describe('Submit Agreements and Exceptions service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
error: null,
pageTitle: 'Select agreements and exceptions for the requirements for returns',
id: 'aeb46f58-3431-42af-8724-361a7779becf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Submit Frequency Collected service', () => {

session = await SessionHelper.add({
data: {
checkYourAnswersVisited: false,
licence: {
id: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
currentVersionStartDate: '2023-01-01T00:00:00.000Z',
Expand Down Expand Up @@ -52,10 +53,12 @@ describe('Submit Frequency Collected service', () => {
expect(refreshedSession.data.frequencyCollected).to.equal('weekly')
})

it('returns an empty object (no page data needed for a redirect)', async () => {
it('returns the checkYourAnswersVisited property (no page data needed for a redirect)', async () => {
const result = await SubmitFrequencyCollectedService.go(session.id, payload)

expect(result).to.equal({})
expect(result).to.equal({
checkYourAnswersVisited: false
})
})
})

Expand All @@ -76,6 +79,7 @@ describe('Submit Frequency Collected service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
licenceId: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
licenceRef: '01/ABC',
pageTitle: 'Select how often readings or volumes are collected',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Submit Frequency Reported service', () => {

session = await SessionHelper.add({
data: {
checkYourAnswersVisited: false,
licence: {
id: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
currentVersionStartDate: '2023-01-01T00:00:00.000Z',
Expand Down Expand Up @@ -52,10 +53,12 @@ describe('Submit Frequency Reported service', () => {
expect(refreshedSession.data.frequencyReported).to.equal('weekly')
})

it('returns an empty object (no page data needed for a redirect)', async () => {
it('returns the checkYourAnswersVisited property (no page data needed for a redirect)', async () => {
const result = await SubmitFrequencyReportedService.go(session.id, payload)

expect(result).to.equal({})
expect(result).to.equal({
checkYourAnswersVisited: false
})
})
})

Expand All @@ -76,6 +79,7 @@ describe('Submit Frequency Reported service', () => {

expect(result).to.equal({
activeNavBar: 'search',
checkYourAnswersVisited: false,
licenceId: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
licenceRef: '01/ABC',
pageTitle: 'Select how often readings or volumes are reported',
Expand Down
Loading

0 comments on commit c05be58

Please sign in to comment.