From 428fed9930215eedb6c70270a357c01d6471a33d Mon Sep 17 00:00:00 2001 From: Daniel Liburd Date: Thu, 28 Sep 2023 14:32:47 +0100 Subject: [PATCH] Show offence ID on check your answers and full referral pages HPTs currently have no way of knowing which index offence a referral belongs to and are having to ask the CPP, therefore, we want to show the offence ID on the referral page under the 'sentence information' section. To achieve this we are adding the offence ID to the response of the first page of the 'sentence information' task. As there is no way to change the offence ID without starting a new referral, we hide the "change" action on the check your answers page. This isn't an ideal solution as it doesn't follow the conventions of the other form pages, but here is some rationale: * Offence ID is fetched by the server without the need for user input. We only ask the user to choose an offence ID if more than one offence is retrieved from the API. This means making a TaskListPage for offence ID non-trivial and would require a different approach to what we have now. Given there are limited dev days left on CAS3, taking on this work isn't feasible. * I thought about adding a new type of TaskListPage which wouldn't be visible to the user, but changing the existing domain model for this one instance felt a bit premature, and would still be a good chunk of work. * The solution in this commit is a hack, but is fairly non-invasive and easy to change in the future. --- e2e/tests/stepDefinitions/apply.ts | 2 +- .../offendingSummary.test.ts | 1 + .../sentence-information/offendingSummary.ts | 7 +++- .../utils/checkYourAnswersUtils/index.test.ts | 39 ++++++++++++++++++- server/utils/checkYourAnswersUtils/index.ts | 21 +++++----- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/e2e/tests/stepDefinitions/apply.ts b/e2e/tests/stepDefinitions/apply.ts index 71175e5e5..7a3d9905c 100644 --- a/e2e/tests/stepDefinitions/apply.ts +++ b/e2e/tests/stepDefinitions/apply.ts @@ -39,7 +39,7 @@ Given('I start a new application', () => { Given('I fill in and complete an application', () => { cy.url().then(function _(url) { const id = url.match(/referrals\/(.+)/)[1] - const application = applicationFactory.build({ ...this.application, id }) + const application = applicationFactory.build({ ...this.application, id, offenceId: offences[0].id }) const apply = new ApplyHelper(application, person, [], 'e2e') diff --git a/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.test.ts b/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.test.ts index 501f78229..1d419ad46 100644 --- a/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.test.ts +++ b/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.test.ts @@ -47,6 +47,7 @@ describe('OffendingSummary', () => { const page = new OffendingSummary(body, application) expect(page.response()).toEqual({ + 'Offence ID': application.offenceId, 'Summary of offending history': 'Offending summary', }) }) diff --git a/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.ts b/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.ts index 79343f861..2857b017f 100644 --- a/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.ts +++ b/server/form-pages/apply/accommodation-need/sentence-information/offendingSummary.ts @@ -9,6 +9,8 @@ export type OffendingSummaryBody = { summary: string } +export const offenceIdKey = 'Offence ID' + @Page({ name: 'offending-summary', bodyProperties: ['summary'] }) export default class OffendingSummary implements TasklistPage { title: string @@ -23,7 +25,10 @@ export default class OffendingSummary implements TasklistPage { } response() { - return { 'Summary of offending history': this.body.summary } + return { + [offenceIdKey]: this.application.offenceId, + 'Summary of offending history': this.body.summary, + } } previous() { diff --git a/server/utils/checkYourAnswersUtils/index.test.ts b/server/utils/checkYourAnswersUtils/index.test.ts index 2255e7e70..b8f206a72 100644 --- a/server/utils/checkYourAnswersUtils/index.test.ts +++ b/server/utils/checkYourAnswersUtils/index.test.ts @@ -24,6 +24,11 @@ describe('checkYourAnswersUtils', () => { }) describe('getTaskResponsesAsSummaryListItems', () => { + beforeEach(() => { + ;(formatLines as jest.Mock).mockReset() + ;(formatLines as jest.Mock).mockImplementation((value: string) => `Formatted "${value}"`) + }) + it('returns the task responses as Summary List items and adds the actions object', () => { const application = applicationFactory.build() ;(forPagesInTask as jest.MockedFunction).mockImplementation((_1, _2, callback) => { @@ -35,7 +40,6 @@ describe('checkYourAnswersUtils', () => { callback(page, 'some-page') }) - ;(formatLines as jest.Mock).mockImplementation((value: string) => `Formatted "${value}"`) expect( getTaskResponsesAsSummaryListItems( @@ -64,5 +68,38 @@ describe('checkYourAnswersUtils', () => { expect(formatLines).toHaveBeenCalledWith('An answer') }) + + describe('when the item is offence ID', () => { + it('returns the task response as a Summary List item without the actions object', () => { + const application = applicationFactory.build() + ;(forPagesInTask as jest.MockedFunction).mockImplementation((_1, _2, callback) => { + const page = createMock() + + page.response.mockReturnValue({ + 'Offence ID': '1234455', + }) + + callback(page, 'some-page') + }) + + expect( + getTaskResponsesAsSummaryListItems( + { id: 'some-task', title: 'Some task', actionText: 'Complete some task', pages: {} }, + application, + ), + ).toEqual([ + { + key: { + text: 'Offence ID', + }, + value: { + html: 'Formatted "1234455"', + }, + }, + ]) + + expect(formatLines).toHaveBeenCalledWith('1234455') + }) + }) }) }) diff --git a/server/utils/checkYourAnswersUtils/index.ts b/server/utils/checkYourAnswersUtils/index.ts index c16f0b678..d20c58712 100644 --- a/server/utils/checkYourAnswersUtils/index.ts +++ b/server/utils/checkYourAnswersUtils/index.ts @@ -7,6 +7,7 @@ import reviewSections from '../reviewUtils' import { formatLines } from '../viewUtils' import { embeddedSummaryListItem } from './embeddedSummaryListItem' import { forPagesInTask } from '../applicationUtils' +import { offenceIdKey } from '../../form-pages/apply/accommodation-need/sentence-information/offendingSummary' const checkYourAnswersSections = (application: TemporaryAccommodationApplication) => reviewSections(application, getTaskResponsesAsSummaryListItems) @@ -40,20 +41,22 @@ const summaryListItemForResponse = ( pageName: string, application: TemporaryAccommodationApplication, ) => { + const actions = { + items: [ + { + href: paths.applications.pages.show({ task: task.id, page: pageName, id: application.id }), + text: 'Change', + visuallyHiddenText: key, + }, + ], + } + return { key: { text: key, }, value, - actions: { - items: [ - { - href: paths.applications.pages.show({ task: task.id, page: pageName, id: application.id }), - text: 'Change', - visuallyHiddenText: key, - }, - ], - }, + ...(key === offenceIdKey ? {} : { actions }), } }