Skip to content

Commit

Permalink
Merge pull request #665 from ministryofjustice/change/1595-show-index…
Browse files Browse the repository at this point in the history
…-offence-id-in-referral

Show offence ID on check your answers and full referral pages
  • Loading branch information
libuk authored Oct 4, 2023
2 parents fa7329d + 15e8c13 commit de419d8
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].offenceId })

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 de419d8

Please sign in to comment.