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 #38 from ministryofjustice/CBA-58-add-health-needs…
…-question Add liaison & diversion assessment question to health needs task
- Loading branch information
Showing
10 changed files
with
150 additions
and
2 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
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
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
41 changes: 41 additions & 0 deletions
41
server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.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,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', | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
51 changes: 51 additions & 0 deletions
51
server/form-pages/apply/risks-and-needs/health-needs/liaisonAndDiversion.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,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<LiaisonAndDiversionBody>, | ||
private readonly application: Application, | ||
) { | ||
this.body = body as LiaisonAndDiversionBody | ||
} | ||
|
||
previous() { | ||
return 'brain-injury' | ||
} | ||
|
||
next() { | ||
return 'other-health' | ||
} | ||
|
||
errors() { | ||
const errors: TaskListErrors<this> = {} | ||
|
||
if (!this.body.liaisonAndDiversionAssessment) { | ||
errors.liaisonAndDiversionAssessment = `Confirm whether a Liaison & Diversion Assessment has been requested` | ||
} | ||
|
||
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
31 changes: 31 additions & 0 deletions
31
server/views/applications/pages/health-needs/liaison-and-diversion.njk
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,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 %} |