generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from ministryofjustice/CBA-73-add-a-new-questi…
…on-flow-for-community-supervision CBA-73 - update current offences task with community supervision and CPP details pages
- Loading branch information
Showing
21 changed files
with
462 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import { Page } from '@playwright/test' | ||
import { ApplyPage, TaskListPage } from '../pages/apply' | ||
|
||
export const completeCurrentOffencesTask = async (page: Page, name: string) => { | ||
export const completeCommunitySupervisionAndCurrentOffencesTask = async (page: Page, name: string) => { | ||
const taskListPage = new TaskListPage(page) | ||
await taskListPage.clickTask('Add current offences') | ||
await taskListPage.clickTask('Community supervision and current offences') | ||
|
||
await completeCommunitySupervisionPage(page, name) | ||
await completeCPPDetailsPage(page, name) | ||
await completeCurrentOffenceDetailsPage(page, name) | ||
await completeCurrentOffencesPage(page, name) | ||
} | ||
|
||
async function completeCommunitySupervisionPage(page: Page, name: string) { | ||
const communitySupervisionPage = await ApplyPage.initialize(page, `Is ${name} currently supervised by probation?`) | ||
await communitySupervisionPage.checkRadio('Yes') | ||
await communitySupervisionPage.clickButton('Save and continue') | ||
} | ||
|
||
async function completeCPPDetailsPage(page: Page, name: string) { | ||
const cppDetailsPage = await ApplyPage.initialize(page, `Who is ${name}'s Community Probation Practitioner (CPP)?`) | ||
await cppDetailsPage.fillField('Full name', 'A. CPP') | ||
await cppDetailsPage.fillField('Probation region', 'south') | ||
await cppDetailsPage.fillField('Contact email address', '[email protected]') | ||
await cppDetailsPage.fillField('Contact number', '12345') | ||
await cppDetailsPage.clickSave() | ||
} | ||
|
||
async function completeCurrentOffenceDetailsPage(page: Page, name: string) { | ||
const currentOffenceDetailsPage = await ApplyPage.initialize(page, `Add ${name}'s current offence details`) | ||
await currentOffenceDetailsPage.fillField('Offence title', 'Stalking') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,7 +258,18 @@ | |
"additionalInformationDetail": "some information" | ||
} | ||
}, | ||
"current-offences": { | ||
"community-supervision-and-current-offences": { | ||
"community-supervision": { | ||
"probationSupervision": "yes" | ||
}, | ||
"cpp-details": { | ||
"cppDetails": { | ||
"name": "A. CPP", | ||
"probationRegion": "some region", | ||
"email": "[email protected]", | ||
"telephone": "012345" | ||
} | ||
}, | ||
"current-offence-data": [ | ||
{ | ||
"titleAndNumber": "Arson", | ||
|
45 changes: 45 additions & 0 deletions
45
...fence-information/community-supervision-and-current-offences/communitySupervision.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples' | ||
import { personFactory, applicationFactory } from '../../../../testutils/factories/index' | ||
import CommunitySupervision from './communitySupervision' | ||
|
||
describe('Community supervision', () => { | ||
const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) | ||
|
||
describe('when the applicant is under probation supervision', () => { | ||
itShouldHaveNextValue(new CommunitySupervision({ probationSupervision: 'yes' }, application), 'cpp-details') | ||
}) | ||
|
||
describe('when the applicant is not under probation supervision', () => { | ||
itShouldHaveNextValue(new CommunitySupervision({ probationSupervision: 'no' }, application), '') | ||
}) | ||
|
||
itShouldHavePreviousValue(new CommunitySupervision({}, application), 'taskList') | ||
|
||
describe('items', () => { | ||
it('returns the radio with the expected label text', () => { | ||
const page = new CommunitySupervision({ probationSupervision: 'yes' }, application) | ||
expect(page.items()).toEqual([ | ||
{ | ||
checked: true, | ||
text: 'Yes', | ||
value: 'yes', | ||
}, | ||
{ | ||
checked: false, | ||
text: 'No', | ||
value: 'no', | ||
}, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('errors', () => { | ||
it('should return errors when the questions are blank', () => { | ||
const page = new CommunitySupervision({}, application) | ||
|
||
expect(page.errors()).toEqual({ | ||
probationSupervision: 'Confirm whether the applicant is currently supervised by probation', | ||
}) | ||
}) | ||
}) | ||
}) |
61 changes: 61 additions & 0 deletions
61
...ly/offence-information/community-supervision-and-current-offences/communitySupervision.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Radio, TaskListErrors, YesOrNo } from '@approved-premises/ui' | ||
import { Cas2Application as Application } from '@approved-premises/api' | ||
import { Page } from '../../../utils/decorators' | ||
import TaskListPage from '../../../taskListPage' | ||
import { nameOrPlaceholderCopy } from '../../../../utils/utils' | ||
import { getQuestions } from '../../../utils/questions' | ||
import { convertKeyValuePairToRadioItems } from '../../../../utils/formUtils' | ||
|
||
export type CommunitySupervisionBody = { | ||
probationSupervision: YesOrNo | ||
} | ||
|
||
@Page({ | ||
name: 'community-supervision', | ||
bodyProperties: ['probationSupervision'], | ||
}) | ||
export default class CommunitySupervision implements TaskListPage { | ||
documentTitle = 'Is the person currently supervised by probation?' | ||
|
||
personName = nameOrPlaceholderCopy(this.application.person) | ||
|
||
title | ||
|
||
questions = getQuestions(this.personName)['community-supervision-and-current-offences']['community-supervision'] | ||
|
||
body: CommunitySupervisionBody | ||
|
||
constructor( | ||
body: Partial<CommunitySupervisionBody>, | ||
private readonly application: Application, | ||
) { | ||
this.body = body as CommunitySupervisionBody | ||
this.title = this.questions.probationSupervision.question | ||
} | ||
|
||
previous() { | ||
return 'taskList' | ||
} | ||
|
||
next() { | ||
if (this.body.probationSupervision === 'yes') { | ||
return 'cpp-details' | ||
} | ||
return '' | ||
} | ||
|
||
items() { | ||
return convertKeyValuePairToRadioItems( | ||
this.questions.probationSupervision.answers, | ||
this.body.probationSupervision, | ||
) as Array<Radio> | ||
} | ||
|
||
errors() { | ||
const errors: TaskListErrors<this> = {} | ||
if (!this.body.probationSupervision) { | ||
errors.probationSupervision = 'Confirm whether the applicant is currently supervised by probation' | ||
} | ||
return errors | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...s/apply/offence-information/community-supervision-and-current-offences/cppDetails.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { itShouldHavePreviousValue, itShouldHaveNextValue } from '../../../shared-examples' | ||
import { personFactory, applicationFactory } from '../../../../testutils/factories/index' | ||
import CPPDetails from './cppDetails' | ||
|
||
describe('CPPDetails', () => { | ||
const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) | ||
|
||
describe('title', () => { | ||
it('personalises the page title', () => { | ||
const page = new CPPDetails({}, application) | ||
|
||
expect(page.title).toEqual("Who is Roger Smith's Community Probation Practitioner (CPP)?") | ||
}) | ||
}) | ||
|
||
itShouldHavePreviousValue(new CPPDetails({}, application), 'community-supervision') | ||
itShouldHaveNextValue(new CPPDetails({}, application), 'current-offences') | ||
|
||
describe('errors', () => { | ||
describe('when they have not provided any answer', () => { | ||
it('returns errors', () => { | ||
const page = new CPPDetails({}, application) | ||
expect(page.errors()).toEqual({ | ||
name: "Enter the CPP's full name", | ||
probationRegion: 'Enter the probation region', | ||
email: "Enter the CPP's email address", | ||
telephone: "Enter the CPP's contact number", | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('response', () => { | ||
it('returns data in expected format', () => { | ||
const page = new CPPDetails( | ||
{ | ||
name: 'a name', | ||
probationRegion: 'a probation region', | ||
email: 'an email address', | ||
telephone: 'a phone number', | ||
}, | ||
application, | ||
) | ||
|
||
expect(page.response()).toEqual({ | ||
"Who is Roger Smith's Community Probation Practitioner (CPP)?": `a name\r\na probation region\r\nan email address\r\na phone number`, | ||
}) | ||
}) | ||
}) | ||
}) |
70 changes: 70 additions & 0 deletions
70
...-pages/apply/offence-information/community-supervision-and-current-offences/cppDetails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { TaskListErrors } from '@approved-premises/ui' | ||
import { Cas2Application as Application } from '@approved-premises/api' | ||
import { Page } from '../../../utils/decorators' | ||
import TaskListPage from '../../../taskListPage' | ||
import { nameOrPlaceholderCopy } from '../../../../utils/utils' | ||
import { getQuestions } from '../../../utils/questions' | ||
|
||
type CPPDetailsBody = { | ||
name: string | ||
probationRegion: string | ||
email: string | ||
telephone: string | ||
} | ||
|
||
@Page({ | ||
name: 'cpp-details', | ||
bodyProperties: ['name', 'probationRegion', 'email', 'telephone'], | ||
}) | ||
export default class CPPDetails implements TaskListPage { | ||
documentTitle = "Who is the person's Community Probation Practitioner (CPP)?" | ||
|
||
personName = nameOrPlaceholderCopy(this.application.person) | ||
|
||
title | ||
|
||
questions = getQuestions(this.personName)['community-supervision-and-current-offences']['cpp-details'] | ||
|
||
options: Record<string, string> | ||
|
||
body: CPPDetailsBody | ||
|
||
constructor( | ||
body: Partial<CPPDetailsBody>, | ||
private readonly application: Application, | ||
) { | ||
this.body = body as CPPDetailsBody | ||
this.title = this.questions.cppDetails.question | ||
} | ||
|
||
previous() { | ||
return 'community-supervision' | ||
} | ||
|
||
next() { | ||
return 'current-offences' | ||
} | ||
|
||
response() { | ||
return { | ||
[this.title]: `${this.body.name}\r\n${this.body.probationRegion}\r\n${this.body.email}\r\n${this.body.telephone}`, | ||
} | ||
} | ||
|
||
errors() { | ||
const errors: TaskListErrors<this> = {} | ||
if (!this.body.name) { | ||
errors.name = "Enter the CPP's full name" | ||
} | ||
if (!this.body.probationRegion) { | ||
errors.probationRegion = 'Enter the probation region' | ||
} | ||
if (!this.body.email) { | ||
errors.email = "Enter the CPP's email address" | ||
} | ||
if (!this.body.telephone) { | ||
errors.telephone = "Enter the CPP's contact number" | ||
} | ||
return errors | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.