Skip to content

Commit

Permalink
Show offence ID on check your answers and full referral pages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
libuk committed Oct 4, 2023
1 parent fa7329d commit 428fed9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion e2e/tests/stepDefinitions/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
39 changes: 38 additions & 1 deletion server/utils/checkYourAnswersUtils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof forPagesInTask>).mockImplementation((_1, _2, callback) => {
Expand All @@ -35,7 +40,6 @@ describe('checkYourAnswersUtils', () => {

callback(page, 'some-page')
})
;(formatLines as jest.Mock).mockImplementation((value: string) => `Formatted "${value}"`)

expect(
getTaskResponsesAsSummaryListItems(
Expand Down Expand Up @@ -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<typeof forPagesInTask>).mockImplementation((_1, _2, callback) => {
const page = createMock<TasklistPage>()

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')
})
})
})
})
21 changes: 12 additions & 9 deletions server/utils/checkYourAnswersUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 }),
}
}

Expand Down

0 comments on commit 428fed9

Please sign in to comment.