Skip to content

Commit

Permalink
Merge pull request #124 from ministryofjustice/CBA-271-risk-structure
Browse files Browse the repository at this point in the history
Add new risk page structure
  • Loading branch information
libuk authored Mar 4, 2025
2 parents 53b8ab9 + 508750e commit 497f38e
Show file tree
Hide file tree
Showing 80 changed files with 1,206 additions and 1,841 deletions.
5 changes: 2 additions & 3 deletions e2e-tests/steps/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
completeEqualityAndDiversityTask,
completePersonalInformationTask,
} from './aboutThePersonSection'
import { completeHealthNeedsTask, completeRiskToSelfTask, completeRoshTask } from './risksAndNeedsSection'
import { completeHealthNeedsTask, completeRiskInformationTask } from './risksAndNeedsSection'
import { completeAreaInformationTask, completeFundingInformationTask } from './areaAndFundingSection'
import {
completeAllegedOffencesTask,
Expand Down Expand Up @@ -84,8 +84,7 @@ export const completeAboutThePersonSection = async (page: Page, name: string) =>

export const completeRisksAndNeedsSection = async (page: Page, name: string) => {
await completeHealthNeedsTask(page, name)
await completeRiskToSelfTask(page, name)
await completeRoshTask(page, name)
await completeRiskInformationTask(page)
}

export const completeOffenceInformationSection = async (page: Page, name: string) => {
Expand Down
106 changes: 35 additions & 71 deletions e2e-tests/steps/risksAndNeedsSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,45 +123,53 @@ async function completeOtherHealthPage(page: Page, name: string) {
await otherHealthPage.clickSave()
}

export const completeRiskToSelfTask = async (page: Page, name: string) => {
export const completeRiskInformationTask = async (page: Page) => {
const taskListPage = new TaskListPage(page)
await taskListPage.clickTask('Add risk to self information')
await taskListPage.clickTask('Add information about risks to the applicant and others')

await completeVulnerabilityPage(page, name)
await completeCurrentRisksPage(page, name)
await completeHistoricalRisksPage(page, name)
await completeConcernsPage(page)
await completeSelfHarmPage(page)
await addAnAcct(page)
await completeAdditionalInformationPage(page, name)
await completeViolenceAndArsonPage(page)
await completeLivingInTheCommunityPage(page)
await completeRisksToStaffPage(page)
await completeAdditionalConcernsPage(page)
}

async function completeVulnerabilityPage(page: Page, name: string) {
const vulnerabilityPage = await ApplyPage.initialize(page, `${name}'s vulnerability`)
async function completeConcernsPage(page: Page) {
const concernsPage = await ApplyPage.initialize(page, 'Concerns')

await vulnerabilityPage.fillField(
`Describe ${name}'s current circumstances, issues and needs related to vulnerability`,
'some vulnerability',
)
await vulnerabilityPage.clickSave()
concernsPage.clickSave()
}

async function completeCurrentRisksPage(page: Page, name: string) {
const currentRisksPage = await ApplyPage.initialize(page, `${name}'s current risks`)
async function completeSelfHarmPage(page: Page) {
const selfHarmPage = await ApplyPage.initialize(page, 'Self harm')

await currentRisksPage.fillField(
`Describe ${name}'s current issues and needs related to self harm and suicide`,
'some needs',
)
await currentRisksPage.clickSave()
selfHarmPage.clickSave()
}

async function completeHistoricalRisksPage(page: Page, name: string) {
const historicalRisksPage = await ApplyPage.initialize(page, `${name}'s historical risks`)
async function completeViolenceAndArsonPage(page: Page) {
const violenceAndArsonPage = await ApplyPage.initialize(page, 'Violence and arson')

await historicalRisksPage.fillField(
`Describe ${name}'s historical issues and needs related to self harm and suicide`,
'some needs',
)
await historicalRisksPage.clickSave()
violenceAndArsonPage.clickSave()
}

async function completeLivingInTheCommunityPage(page: Page) {
const livingInTheCommunityPage = await ApplyPage.initialize(page, 'Living in the community')

livingInTheCommunityPage.clickSave()
}

async function completeRisksToStaffPage(page: Page) {
const risksToStaffPage = await ApplyPage.initialize(page, 'Risks to staff')

risksToStaffPage.clickSave()
}

async function completeAdditionalConcernsPage(page: Page) {
const additionalConcernsPage = await ApplyPage.initialize(page, 'Additional concerns')

additionalConcernsPage.clickSave()
}

async function addAnAcct(page: Page) {
Expand All @@ -179,47 +187,3 @@ async function completeAcctDataPage(page: Page) {
await acctDataPage.fillField('Details about the ACCT', 'some details')
await acctDataPage.clickButton('Save and add ACCT')
}

async function completeAdditionalInformationPage(page: Page, name: string) {
const additionalInformationPage = await ApplyPage.initialize(
page,
`Is there anything else to include about ${name}'s risk to self?`,
)
await additionalInformationPage.checkRadio('No')
await additionalInformationPage.clickSave()
}

export const completeRoshTask = async (page: Page, name: string) => {
const taskListPage = new TaskListPage(page)
await taskListPage.clickTask('Add risk of serious harm (RoSH) information')

await completeRiskToOthersPage(page, name)
await completeRiskManagementArrangementsPage(page, name)
await completeCellShareInformationPage(page, name)
await completeAdditionalRiskPage(page, name)
}

async function completeRiskToOthersPage(page: Page, name: string) {
const riskToOthersPage = await ApplyPage.initialize(page, `Risk to others for ${name}`)
await riskToOthersPage.fillField('Who is at risk?', 'a person')
await riskToOthersPage.fillField('What is the nature of the risk?', 'some details about the risk')
await riskToOthersPage.clickSave()
}

async function completeRiskManagementArrangementsPage(page: Page, name: string) {
const riskManagementPage = await ApplyPage.initialize(page, `Risk management arrangements for ${name}`)
await riskManagementPage.checkCheckboxes(['No, this person does not have risk management arrangements'])
await riskManagementPage.clickSave()
}

async function completeCellShareInformationPage(page: Page, name: string) {
const riskManagementPage = await ApplyPage.initialize(page, `Cell share information for ${name}`)
await riskManagementPage.checkRadio('No')
await riskManagementPage.clickSave()
}

async function completeAdditionalRiskPage(page: Page, name: string) {
const riskManagementPage = await ApplyPage.initialize(page, `Additional risk information for ${name}`)
await riskManagementPage.checkRadio('No')
await riskManagementPage.clickSave()
}
2 changes: 1 addition & 1 deletion e2e-tests/tests/01_apply_as_pom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('create a CAS-2 bail application', async ({ page, person, pomUser }) => {
await completeOffenceInformationSection(page, person.name)
await completeBailInformationSection(page, person.name)
await completeCheckAnswersSection(page, person.name)
await expect(page.getByText('You have completed 18 of 18 tasks')).toBeVisible()
await expect(page.getByText('You have completed 17 of 17 tasks')).toBeVisible()
await submitApplication(page)
})

Expand Down
48 changes: 9 additions & 39 deletions integration_tests/fixtures/applicationData.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"inEducationOrTraining": "no"
},
"applicant-id": {
"idDocuments": "passport"
"idDocuments": ["passport", "travelPass", "birthCertificate", "bankOrDebitCard", "bankStatements", "drivingLicence", "wageSlip", "none"]
}
},
"solicitor-details": {
Expand Down Expand Up @@ -208,19 +208,13 @@
"beingTreatedForCancer": "no"
}
},
"risk-to-self": {
"current-risk": {
"currentRiskDetail": "[R8.1.1] Review 06.10.21:\r\n\r\n There have been numerous ACCTs opened since 2013 and every subsequent year he has been in custody. In 2021...",
"confirmation": "confirmed"
},
"vulnerability": {
"vulnerabilityDetail": "example answer vulnerability",
"confirmation": "confirmed"
},
"historical-risk": {
"historicalRiskDetail": "example answer historical risk",
"confirmation": "confirmed"
},
"risk-information": {
"concerns": {},
"self-harm": {},
"violence-and-arson": {},
"living-in-the-community": {},
"risks-to-staff": {},
"additional-concerns": {},
"acct": {},
"acct-data": [
{
Expand All @@ -242,31 +236,7 @@
"referringInstitution": "HMPPS prison 2",
"acctDetails": "ACCT details 2"
}
],
"additional-information": {
"hasAdditionalInformation": "yes",
"additionalInformationDetail": "some information"
}
},
"risk-of-serious-harm": {
"risk-to-others": {
"whoIsAtRisk": "a person",
"natureOfRisk": "a nature"
},
"risk-management-arrangements": {
"arrangements": ["mappa", "marac", "iom"],
"mappaDetails": "mappa details",
"maracDetails": "marac details",
"iomDetails": "iom details"
},
"cell-share-information": {
"hasCellShareComments": "yes",
"cellShareInformationDetail": "some information"
},
"additional-risk-information": {
"hasAdditionalInformation": "yes",
"additionalInformationDetail": "some information"
}
]
},
"community-supervision-and-current-offences": {
"community-supervision": {
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/fixtures/applicationDocument.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
]
},
{
"title": "Add risk to self information",
"title": "Add information about risks to the applicant and others",
"questionsAndAnswers": [
{
"question": "Describe Aadland Bertrand's current issues and needs related to self harm and suicide",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Cas2v2Application as Application } from '../../../../../server/@types/shared/models/Cas2v2Application'
import ApplyPage from '../../applyPage'
import paths from '../../../../../server/paths/apply'

export default class AcctDataPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Add an ACCT entry', application, 'risk-information', 'acct-data')
}

static visit(application: Application): void {
cy.visit(
paths.applications.pages.show({
id: application.id,
task: 'risk-information',
page: 'acct-data',
}),
)
}

addACCTInformation(): void {
this.completeDateInputs('createdDate', '2022-07-15')
this.checkRadioByNameAndValue('isOngoing', 'no')
this.completeDateInputs('closedDate', '2023-07-15')
this.getTextInputByIdAndEnterDetails('referringInstitution', 'HMPPS prison')
this.getTextInputByIdAndEnterDetails('acctDetails', 'some detail')
}

clickSubmit(): void {
cy.get('button').contains('Save and add ACCT').click()
}

clickAddAnother(): void {
cy.get('button').contains('Save and add another').click()
}

assertFormisEmpty(): void {
cy.get('#createdDate-day').should('have.value', '')
cy.get('#isOngoing').should('not.be.checked')
cy.get('#referringInstitution').should('have.value', '')
cy.get('#acctDetails').should('have.value', '')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Cas2v2Application as Application } from '../../../../../server/@types/shared/models/Cas2v2Application'
import ApplyPage from '../../applyPage'
import paths from '../../../../../server/paths/apply'
import { nameOrPlaceholderCopy } from '../../../../../server/utils/utils'

export default class AcctPage extends ApplyPage {
constructor(private readonly application: Application) {
super(
`${nameOrPlaceholderCopy(application.person, 'The person')}'s ACCT notes`,
application,
'risk-information',
'acct',
)
}

static visit(application: Application): void {
cy.visit(
paths.applications.pages.show({
id: application.id,
task: 'risk-information',
page: 'acct',
}),
)
}

hasListOfAccts(): void {
cy.get('.govuk-summary-card__title').contains('1 February 2012 - 10 October 2013')
cy.get('.govuk-summary-list').contains('HMPPS prison')
cy.get('.govuk-summary-list').should('contain.html', 'ACCT details<br>some more details on another line')
}

hasNoAccts(): void {
cy.get('.govuk-body').contains('No ACCT notes have been added.')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'

export default class AdditionalConcernsPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Additional concerns', application, 'risk-information', 'additional-concerns')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'

export default class ConcernsPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Concerns', application, 'risk-information', 'concerns')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'

export default class LivingInTheCommunityPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Living in the community', application, 'risk-information', 'living-in-the-community')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'

export default class RisksToStaffPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Risks to staff', application, 'risk-information', 'risks-to-staff')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'

export default class SelfHarmPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Self harm', application, 'risk-information', 'self-harm')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'

export default class ViolenceAndArsonPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Violence and arson', application, 'risk-information', 'violence-and-arson')
}
}
12 changes: 12 additions & 0 deletions integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'cypress-axe'
import { Result } from 'axe-core'
import errorLookups from '../../server/i18n/en/errors.json'
import { DateFormats } from '../../server/utils/dateUtils'

export type PageElement = Cypress.Chainable<JQuery>

Expand Down Expand Up @@ -89,4 +90,15 @@ export default abstract class Page {
clickLink(label: string): void {
cy.get('a:visible').contains(label).click()
}

clickRemove(): void {
cy.get('a').contains('Remove').click()
}

completeDateInputs(prefix: string, date: string): void {
const parsedDate = DateFormats.isoToDateObj(date)
cy.get(`#${prefix}-day`).type(parsedDate.getDate().toString())
cy.get(`#${prefix}-month`).type(`${parsedDate.getMonth() + 1}`)
cy.get(`#${prefix}-year`).type(parsedDate.getFullYear().toString())
}
}
Loading

0 comments on commit 497f38e

Please sign in to comment.