Skip to content

Commit

Permalink
Man 287 ensure consistent approach to comments added (#317)
Browse files Browse the repository at this point in the history
* MAN-287 update notes on personal-contact page

* MAN-287 update notes on disabilities page

* MAN-287 update integration tests

* MAN-287 update integration tests
  • Loading branch information
achimber-moj authored Feb 7, 2025
1 parent 01e50a5 commit 2ee3e80
Show file tree
Hide file tree
Showing 23 changed files with 721 additions and 1,155 deletions.
34 changes: 23 additions & 11 deletions integration_tests/e2e/personalDetails/contact.cy.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import Page from '../../pages/page'
import ContactPage from '../../pages/personalDetails/contact'
import ContactGPPage from '../../pages/personalDetails/contact-gp'

context('Contact', () => {
it('Contact page is rendered', () => {
cy.visit('/case/X000001/personal-details/personal-contact/2500232995')
const page = Page.verifyOnPage(ContactPage)
cy.get('p')
.eq(0)
.within(() =>
cy
.get('a')
.invoke('attr', 'href')
.should(
'equal',
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=PersonalContacts&CRN=X000001',
),
)
page.assertAnchorElementAtIndexWithin(
'p',
0,
0,
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=PersonalContacts&CRN=X000001',
)
page.getRowData('contactRelationshipTypeHeader', 'Value').should('contain.text', 'Emergency Contact')
page.getRowData('contactNameHeader', 'Value').should('contain.text', 'Brian Smith')
page.getRowData('contactName', 'Value').should('contain.text', 'Brian Smith')
Expand All @@ -25,4 +21,20 @@ context('Contact', () => {
page.getRowData('contactNotes', 'Value').should('contain.text', 'No notes')
page.getRowData('lastUpdatedBy', 'Value').should('contain.text', 'Last updated by George NDelius03 on 14 Mar 2023')
})

it('Contact page with notes is rendered', () => {
cy.visit('/case/X000001/personal-details/personal-contact/2500233993')
const page = Page.verifyOnPage(ContactGPPage)
page.getRowData('contactNotes', 'Value').should('contain.text', 'Personal Contact')
})

it('Contact page with single note is rendered', () => {
cy.visit('/case/X000001/personal-details/personal-contact/2500233993/note/0')
const page = Page.verifyOnPage(ContactGPPage)
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 4, 'Note added by')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 4, 'Tom Brady')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 5, 'Date added')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 5, '30 October 2024')
page.getRowData('contactNotes', 'Value').should('contain.text', 'Personal Contact')
})
})
34 changes: 32 additions & 2 deletions integration_tests/e2e/personalDetails/disabilities.cy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
import DisabilityPage from '../../pages/personalDetails/disability'
import DisabilitiesPage from '../../pages/personalDetails/disabilities'
import Page from '../../pages/page'

context('Contact', () => {
it('Contact page is rendered', () => {
cy.visit('/case/X000001/personal-details/disabilities')
const page = Page.verifyOnPage(DisabilitiesPage)
page.assertAnchorElementAtIndexWithin(
'p',
0,
0,
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=EqualityMonitoring&CRN=X000001',
)

const page = Page.verifyOnPage(DisabilityPage)
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 0, 'Disability')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 1, 'Start date')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 2, 'Notes')

page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 0, 'Dyslexia')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 1, '3 April 2021')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 2, 'Disability Notes')
})

it('Contact page is rendered', () => {
cy.visit('/case/X000001/personal-details/disability/0/note/0')
const page = Page.verifyOnPage(DisabilitiesPage)
page.assertAnchorElementAtIndexWithin(
'p',
0,
0,
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=EqualityMonitoring&CRN=X000001',
)

page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 0, 'Disability')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 1, 'Start date')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 2, 'Note added by')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 3, 'Date added')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 4, 'Notes')

page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 0, 'Dyslexia')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 1, '3 April 2021')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 2, 'Tom Brady')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 3, '30 October 2024')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 4, 'Disability Notes')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ context('Sentence', () => {

page.assertTextElementAtIndex('h2', 0, 'Previous orders')
page.assertAnchorElementAtIndex(breadCrumbElement, 0, '/case')
page.assertTextAtAnchorElementAtIndex(breadCrumbElement, 0, 'My cases')
page.assertTextAtElementAtIndex(breadCrumbElement, 0, 'My cases')

page.assertAnchorElementAtIndex(breadCrumbElement, 1, '/case/X000001')
page.assertTextAtAnchorElementAtIndex(breadCrumbElement, 1, 'Caroline Wolff')
page.assertTextAtElementAtIndex(breadCrumbElement, 1, 'Caroline Wolff')

page.assertAnchorElementAtIndex(breadCrumbElement, 2, '/case/X000001/sentence')
page.assertTextAtAnchorElementAtIndex(breadCrumbElement, 2, 'Sentence')
page.assertTextAtElementAtIndex(breadCrumbElement, 2, 'Sentence')

page.assertAnchorElementAtIndex(breadCrumbElement, 3, '/case/X000001/sentence/previous-orders')
page.assertTextAtAnchorElementAtIndex(breadCrumbElement, 3, 'Previous orders')
page.assertTextAtElementAtIndex(breadCrumbElement, 3, 'Previous orders')

page.assertTextElementAtIndex('h2', 1, 'CJA - Std Determinate Custody (16 Months)')

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default abstract class Page {
cy.get(element).eq(index).should('contain.text', value)
}

assertTextAtAnchorElementAtIndex = (element: string, index: number, value: string) => {
assertTextAtElementAtIndex = (element: string, index: number, value: string) => {
cy.get(element)
.eq(index)
.within(() => cy.contains(value))
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/pages/personalDetails/contact-gp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Page, { PageElement } from '../page'

export default class ContactGPPage extends Page {
constructor() {
super('GP')
}

getRowData = (rowName: string, type: string): PageElement => {
return cy.get(`[data-qa=${rowName}${type}]`)
}
}
7 changes: 7 additions & 0 deletions integration_tests/pages/personalDetails/disabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Page from '../page'

export default class DisabilitiesPage extends Page {
constructor() {
super('Disabilities')
}
}
8 changes: 8 additions & 0 deletions server/data/masApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export default class MasApiClient extends RestClient {
return this.get({ path: `/personal-details/${crn}/personal-contact/${id}`, handle404: false })
}

async getPersonalContactNote(crn: string, id: string, noteId: string): Promise<PersonalContact | null> {
return this.get({ path: `/personal-details/${crn}/personal-contact/${id}/note/${noteId}`, handle404: false })
}

async getPersonalAddresses(crn: string): Promise<AddressOverview | null> {
return this.get({ path: `/personal-details/${crn}/addresses`, handle404: false })
}
Expand All @@ -115,6 +119,10 @@ export default class MasApiClient extends RestClient {
return this.get({ path: `/personal-details/${crn}/disabilities`, handle404: false })
}

async getPersonDisabilityNote(crn: string, disabilityId: string, noteId: string): Promise<DisabilityOverview | null> {
return this.get({ path: `/personal-details/${crn}/disability/${disabilityId}/note/${noteId}`, handle404: false })
}

async getPersonAdjustments(crn: string): Promise<ProvisionOverview | null> {
return this.get({ path: `/personal-details/${crn}/provisions`, handle404: false })
}
Expand Down
11 changes: 2 additions & 9 deletions server/data/model/licenceConditionNoteDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PersonSummary } from './common'
import { Note } from './note'

export interface LicenceConditionNoteDetails {
personSummary: PersonSummary
Expand All @@ -10,13 +11,5 @@ export interface LicenceCondition {
subTypeDescription: string
imposedReleasedDate: string
actualStartDate: string
licenceNote: LicenceConditionNote
}

export interface LicenceConditionNote {
id: string
createdBy: string
createdByDate: string
note: string
hasNotesBeenTruncated: boolean
licenceNote: Note
}
7 changes: 7 additions & 0 deletions server/data/model/note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Note {
id: number
createdBy: string
createdByDate: string
note: string
hasNotesBeenTruncated: boolean
}
11 changes: 8 additions & 3 deletions server/data/model/personalDetails.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line import/no-cycle
import { Name, PersonalCircumstance, PersonSummary } from './common'
import { Validateable } from '../../utils/validationUtils'
import { Note } from './note'

export interface PersonalDetails {
crn: string
Expand Down Expand Up @@ -51,7 +52,8 @@ export interface PersonalContact {
relationship?: string
relationshipType: string
address?: Address
notes?: string
contactNotes?: Note[]
contactNote?: Note
lastUpdated?: string
lastUpdatedBy?: Name
}
Expand Down Expand Up @@ -153,12 +155,15 @@ export interface Circumstance {

export interface DisabilityOverview {
personSummary: PersonSummary
disabilities: Disability[]
disabilities?: Disability[]
disability?: Disability
}

export interface Disability {
disabilityId: number
description: string
notes?: string
disabilityNotes?: Note[]
disabilityNote?: Note
lastUpdated: string
lastUpdatedBy: Name
}
11 changes: 2 additions & 9 deletions server/data/model/requirementNoteDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PersonSummary } from './common'
import { Note } from './note'

export interface RequirementNoteDetails {
personSummary: PersonSummary
Expand All @@ -15,18 +16,10 @@ export interface Requirement {
description: string
length: number
lengthUnitValue: string
requirementNote: RequirementNote
requirementNote: Note
rar?: {
completed: number
scheduled: number
totalDays: number
}
}

export interface RequirementNote {
id: string
createdBy: string
createdByDate: string
note: string
hasNotesBeenTruncated: boolean
}
21 changes: 4 additions & 17 deletions server/data/model/sentenceDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PersonSummary } from './common'
import { Note } from './note'

export interface SentenceDetails {
personSummary: PersonSummary
Expand Down Expand Up @@ -54,14 +55,6 @@ export interface Order {
startDate: string
}

export interface RequirementNote {
id: number
createdBy: string
createdByDate: string
note: string
hasNoteBeenTruncated: boolean
}

export interface Requirement {
id: number
code: string
Expand All @@ -73,8 +66,8 @@ export interface Requirement {
description: string
codeDescription: string
length: string
requirementNotes: RequirementNote[]
notes: string
requirementNotes?: Note[]
requirementNote?: Note
rar: Rar
}

Expand All @@ -96,15 +89,9 @@ export interface LicenceCondition {
subTypeDescription: string
imposedReleasedDate: string
actualStartDate: string
notes: LicenceConditionNote[]
notes: Note[]
}

export interface LicenceConditionNote {
createdBy: string
createdByDate: string
note: string
hasNotesBeenTruncated: boolean
}
export interface ProbationHistory {
numberOfTerminatedEvents: number
dateOfMostRecentTerminatedEvent: string
Expand Down
59 changes: 57 additions & 2 deletions server/routes/personalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ export default function personalDetailRoutes(router: Router, { hmppsAuthClient }
})

get('/case/:crn/personal-details/personal-contact/:id', async (req, res, _next) => {
const { crn } = req.params
const { id } = req.params
const { crn, id } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)
const arnsClient = new ArnsApiClient(token)
const masClient = new MasApiClient(token)
Expand Down Expand Up @@ -167,6 +166,41 @@ export default function personalDetailRoutes(router: Router, { hmppsAuthClient }
})
})

get('/case/:crn/personal-details/personal-contact/:id/note/:noteId', async (req, res, _next) => {
const { crn, id, noteId } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)
const arnsClient = new ArnsApiClient(token)
const masClient = new MasApiClient(token)
const tierClient = new TierApiClient(token)

await auditService.sendAuditMessage({
action: 'VIEW_MAS_PERSONAL_CONTACT_NOTE',
who: res.locals.user.username,
subjectId: crn,
subjectType: 'CRN',
correlationId: v4(),
service: 'hmpps-manage-people-on-probation-ui',
})

const [personalContact, tierCalculation, risks, predictors] = await Promise.all([
masClient.getPersonalContactNote(crn, id, noteId),
tierClient.getCalculationDetails(crn),
arnsClient.getRisks(crn),
arnsClient.getPredictorsAll(crn),
])

const risksWidget = toRoshWidget(risks)

const predictorScores = toPredictors(predictors)
res.render('pages/personal-details/contact/contact-note', {
personalContact,
tierCalculation,
crn,
risksWidget,
predictorScores,
})
})

get('/case/:crn/personal-details/addresses', async (req, res, _next) => {
const { crn } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)
Expand Down Expand Up @@ -251,6 +285,27 @@ export default function personalDetailRoutes(router: Router, { hmppsAuthClient }
})
})

get('/case/:crn/personal-details/disability/:disabilityId/note/:noteId', async (req, res, _next) => {
const { crn, disabilityId, noteId } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)
const masClient = new MasApiClient(token)

await auditService.sendAuditMessage({
action: `VIEW_MAS_DISABILITY_NOTE`,
who: res.locals.user.username,
subjectId: crn,
subjectType: 'CRN',
correlationId: v4(),
service: 'hmpps-manage-people-on-probation-ui',
})

const disabilityOverview = await masClient.getPersonDisabilityNote(crn, disabilityId, noteId)
res.render(`pages/personal-details/disabilities/disability-note`, {
disabilityOverview,
crn,
})
})

get('/case/:crn/personal-details/adjustments', async (req, res, _next) => {
const { crn } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)
Expand Down
Loading

0 comments on commit 2ee3e80

Please sign in to comment.