diff --git a/e2e-tests/steps/risksAndNeedsSection.ts b/e2e-tests/steps/risksAndNeedsSection.ts index 1a6291b..b741c2e 100644 --- a/e2e-tests/steps/risksAndNeedsSection.ts +++ b/e2e-tests/steps/risksAndNeedsSection.ts @@ -12,6 +12,7 @@ export const completeHealthNeedsTask = async (page: Page, name: string) => { await completeCommunicationAndLanguagePage(page, name) await completeLearningDifficultiesPage(page, name) await completeBrainInjuryPage(page, name) + await completeLiaisonAndDiversionPage(page, name) await completeOtherHealthPage(page, name) } @@ -92,6 +93,14 @@ async function completeBrainInjuryPage(page: Page, name: string) { await brainInjuryPage.clickSave() } +async function completeLiaisonAndDiversionPage(page: Page, name: string) { + const liaisonAndDiversionPage = await ApplyPage.initialize(page, `Liaison & Diversion Assessment for ${name}`) + + await liaisonAndDiversionPage.checkRadioInGroup('Liaison & Diversion Assessment', 'No') + + await liaisonAndDiversionPage.clickSave() +} + async function completeOtherHealthPage(page: Page, name: string) { const otherHealthPage = await ApplyPage.initialize(page, `Other health needs for ${name}`) diff --git a/integration_tests/fixtures/applicationData.json b/integration_tests/fixtures/applicationData.json index 03f9f8b..37e79fe 100644 --- a/integration_tests/fixtures/applicationData.json +++ b/integration_tests/fixtures/applicationData.json @@ -187,6 +187,9 @@ "requiresAdditionalSupport": "no", "addSupportDetail": "" }, + "liaison-and-diversion": { + "liaisonAndDiversionAssessment": "no" + }, "other-health": { "hasLongTermHealthCondition": "no", "healthConditionDetail": "", diff --git a/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.test.ts b/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.test.ts index c7dcd47..dfe8436 100644 --- a/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.test.ts +++ b/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.test.ts @@ -53,7 +53,7 @@ describe('BrainInjury', () => { }) }) - itShouldHaveNextValue(new BrainInjury({}, application), 'other-health') + itShouldHaveNextValue(new BrainInjury({}, application), 'liaison-and-diversion') itShouldHavePreviousValue(new BrainInjury({}, application), 'learning-difficulties') describe('errors', () => { diff --git a/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.ts b/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.ts index fded8e7..67ef0de 100644 --- a/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.ts +++ b/server/form-pages/apply/risks-and-needs/health-needs/brainInjury.ts @@ -52,7 +52,7 @@ export default class BrainInjury implements TaskListPage { } next() { - return 'other-health' + return 'liaison-and-diversion' } errors() { diff --git a/server/form-pages/apply/risks-and-needs/health-needs/index.ts b/server/form-pages/apply/risks-and-needs/health-needs/index.ts index 96b6906..b19190f 100644 --- a/server/form-pages/apply/risks-and-needs/health-needs/index.ts +++ b/server/form-pages/apply/risks-and-needs/health-needs/index.ts @@ -9,6 +9,7 @@ import MentalHealth from './mentalHealth' import OtherHealth from './otherHealth' import PhysicalHealth from './physicalHealth' import SubstanceMisuse from './substanceMisuse' +import LiaisonAndDiversion from './liaisonAndDiversion' @Task({ name: 'Add health needs', @@ -21,6 +22,7 @@ import SubstanceMisuse from './substanceMisuse' CommunicationAndLanguage, LearningDifficulties, BrainInjury, + LiaisonAndDiversion, OtherHealth, ], }) diff --git a/server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.test.ts b/server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.test.ts new file mode 100644 index 0000000..0b580f3 --- /dev/null +++ b/server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.test.ts @@ -0,0 +1,41 @@ +import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples' +import { personFactory, applicationFactory } from '../../../../testutils/factories/index' +import LiaisonAndDiversion from './liaisonAndDiversion' + +describe('LiaisonAndDiversion', () => { + const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) + + describe('title', () => { + it('personalises the page title', () => { + const page = new LiaisonAndDiversion({}, application) + + expect(page.title).toEqual('Liaison & Diversion Assessment for Roger Smith') + }) + }) + + describe('questions', () => { + const page = new LiaisonAndDiversion({}, application) + + describe('liaisonAndDiversion', () => { + it('has a question', () => { + expect(page.questions.liaisonAndDiversionAssessment.question).toBeDefined() + }) + }) + }) + + itShouldHaveNextValue(new LiaisonAndDiversion({}, application), 'other-health') + itShouldHavePreviousValue(new LiaisonAndDiversion({}, application), 'brain-injury') + + describe('errors', () => { + describe('when top-level questions are unanswered', () => { + const page = new LiaisonAndDiversion({}, application) + + it('includes a validation error for _liaisonAndDiversionAssessment_', () => { + expect(page.errors()).toHaveProperty( + 'liaisonAndDiversionAssessment', + 'Confirm whether a Liaison & Diversion Assessment has been requested', + ) + }) + }) + }) +}) diff --git a/server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.ts b/server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.ts new file mode 100644 index 0000000..809b36d --- /dev/null +++ b/server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.ts @@ -0,0 +1,51 @@ +import type { TaskListErrors, YesOrNo } from '@approved-premises/ui' +import { Cas2Application as Application } from '@approved-premises/api' +import { nameOrPlaceholderCopy } from '../../../../utils/utils' +import { Page } from '../../../utils/decorators' +import TaskListPage from '../../../taskListPage' +import { getQuestions } from '../../../utils/questions' + +type LiaisonAndDiversionBody = { + liaisonAndDiversionAssessment: YesOrNo +} + +@Page({ + name: 'liaison-and-diversion', + bodyProperties: ['liaisonAndDiversionAssessment'], +}) +export default class LiaisonAndDiversion implements TaskListPage { + documentTitle = 'Liaison & Diversion Assessment for the person' + + personName = nameOrPlaceholderCopy(this.application.person) + + title = `Liaison & Diversion Assessment for ${this.personName}` + + questions = getQuestions(this.personName)['health-needs']['liaison-and-diversion'] + + body: LiaisonAndDiversionBody + + constructor( + body: Partial, + private readonly application: Application, + ) { + this.body = body as LiaisonAndDiversionBody + } + + previous() { + return 'brain-injury' + } + + next() { + return 'other-health' + } + + errors() { + const errors: TaskListErrors = {} + + if (!this.body.liaisonAndDiversionAssessment) { + errors.liaisonAndDiversionAssessment = `Confirm whether a Liaison & Diversion Assessment has been requested` + } + + return errors + } +} diff --git a/server/form-pages/utils/questions.ts b/server/form-pages/utils/questions.ts index af18d28..8d5bdb6 100644 --- a/server/form-pages/utils/questions.ts +++ b/server/form-pages/utils/questions.ts @@ -606,6 +606,13 @@ export const getQuestions = (name: string) => { requiresAdditionalSupport: { question: 'Is additional support required?', answers: yesOrNo }, addSupportDetail: { question: 'Please describe the type of support.' }, }, + 'liaison-and-diversion': { + liaisonAndDiversionAssessment: { + question: + 'Did the police or court request a Liaison & Diversion Assessment to be carried out for this applicant?', + answers: yesOrNo, + }, + }, 'other-health': { hasLongTermHealthCondition: { question: 'Are they managing any long term health conditions?', diff --git a/server/views/applications/pages/health-needs/_health-needs-screen.njk b/server/views/applications/pages/health-needs/_health-needs-screen.njk index b3c4d91..162d1d5 100644 --- a/server/views/applications/pages/health-needs/_health-needs-screen.njk +++ b/server/views/applications/pages/health-needs/_health-needs-screen.njk @@ -46,6 +46,10 @@ text: 'Brain injury', href: paths.applications.pages.show({ id: applicationId, task: 'health-needs', page: 'brain-injury' }), active: (pageName === 'brain-injury') + }, { + text: 'Liaison & Diversion', + href: paths.applications.pages.show({ id: applicationId, task: 'health-needs', page: 'liaison-and-diversion' }), + active: (pageName === 'liaison-and-diversion') }, { text: 'Other health', href: paths.applications.pages.show({ id: applicationId, task: 'health-needs', page: 'other-health' }), diff --git a/server/views/applications/pages/health-needs/liaison-and-diversion.njk b/server/views/applications/pages/health-needs/liaison-and-diversion.njk new file mode 100644 index 0000000..b62b5a0 --- /dev/null +++ b/server/views/applications/pages/health-needs/liaison-and-diversion.njk @@ -0,0 +1,31 @@ +{% extends "./_health-needs-screen.njk" %} +{% set pageName = "liaison-and-diversion" %} + +{% block questions %} + + {{ + formPageRadios( + { + fieldName: "liaisonAndDiversionAssessment", + fieldset: { + legend: { + text: page.questions.liaisonAndDiversionAssessment.question, + classes: "govuk-fieldset__legend--m" + } + }, + items: [ + { + value: "yes", + text: "Yes" + }, + { + value: "no", + text: "No" + } + ] + }, + fetchContext() + ) + }} + +{% endblock %}