Skip to content

Commit

Permalink
MAN-36 requirement note ui changes and int tests completed
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-mills committed Jan 8, 2025
1 parent 82e07c5 commit 51f9da9
Show file tree
Hide file tree
Showing 27 changed files with 381 additions and 27 deletions.
1 change: 0 additions & 1 deletion integration_tests/e2e/licence-condition-note.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SentencePage from '../pages/sentence'
context('Sentence', () => {
it('Licence condition note page is rendered', () => {
cy.visit('/case/X000001/sentence/licence-condition/7007/note/0')

const page = Page.verifyOnPage(SentencePage)
page.headerCrn().should('contain.text', 'X000001')
page.headerName().should('contain.text', 'Caroline Wolff')
Expand Down
38 changes: 38 additions & 0 deletions integration_tests/e2e/requirement-note.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Page from '../pages/page'
import SentencePage from '../pages/sentence'

context('Sentence', () => {
it('Requirement note page is rendered', () => {
cy.visit('/case/X000001/sentence/requirement/F/note/0')
const page = Page.verifyOnPage(SentencePage)
page.headerCrn().should('contain.text', 'X000001')
page.headerName().should('contain.text', 'Caroline Wolff')
cy.get('[data-qa=pageHeading]').eq(0).should('contain.text', 'Sentence')

cy.get(`[class=app-summary-card__header]`).within(() =>
cy.get('h2').should('contain.text', '1 of 12 RAR days completed'),
)

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').should('have.length', 6))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').should('have.length', 6))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(0).should('contain.text', 'Length of RAR'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(0).should('contain.text', '12 days'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(1).should('contain.text', 'Completed RAR'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(1).should('contain.text', '1 day'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(2).should('contain.text', 'Start date'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(2).should('contain.text', '12 April 2024'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(3).should('contain.text', 'Note added by'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(3).should('contain.text', 'Jon Jones'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(4).should('contain.text', 'Date added'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(4).should('contain.text', '21 August 2024'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(5).should('contain.text', 'Note'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(5).should('contain.text', '123456'))
})
})
52 changes: 51 additions & 1 deletion integration_tests/e2e/sentence.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ context('Sentence', () => {
const page = Page.verifyOnPage(SentencePage)
page.headerCrn().should('contain.text', 'X000001')
page.headerName().should('contain.text', 'Caroline Wolff')
cy.get('[data-qa=pageHeading]').eq(0).should('contain.text', 'Sentence')

page.getTab('overview').should('contain.text', 'Overview')
page.getTab('personalDetails').should('contain.text', 'Personal details')
Expand Down Expand Up @@ -183,4 +182,55 @@ context('Sentence', () => {
.getCardHeader('probationHistory')
.within(() => cy.get('a').eq(1).invoke('attr', 'href').should('equal', '/case/X000001/address-book-professional'))
})

it('Sentence page is rendered with requirements', () => {
cy.visit('/case/X000001/sentence?number=1')
const page = Page.verifyOnPage(SentencePage)

cy.get(`[data-qa="sentenceCard"]`).within(() => cy.get('dt').eq(5).should('contain.text', 'Requirements'))
cy.get(`[data-qa="requirementsValue"]`).within(() =>
cy.get('details').eq(0).should('contain.text', '1 of 12 RAR days completed'),
)
cy.get(`[data-qa="requirementsValue"]`).within(() =>
cy.get('details').eq(1).should('contain.text', 'Curfew (Electronic Monitored)'),
)
cy.get(`[data-qa="requirementsValue"]`).within(() =>
cy.get('details').eq(2).should('contain.text', 'Unpaid Work - Regular'),
)
cy.get(`[data-qa="requirementsValue"] `).within(() => cy.get('details').eq(1).click())
page.getRequirementLabel(2, 1).should('contain.text', 'Length')
page.getRequirementValue(2, 1).should('contain.text', '10 hours')
page.getRequirementLabel(2, 2).should('contain.text', 'Start date')
page.getRequirementValue(2, 2).should('contain.text', '12 January 2024')
page.getRequirementLabel(2, 3).should('contain.text', 'End date')
page.getRequirementValue(2, 3).should('contain.text', '9 January 2024')
page.getRequirementLabel(2, 4).should('contain.text', 'Result')
page.getRequirementValue(2, 4).should('contain.text', 'Expired (Normal)')
page.getRequirementLabel(2, 5).should('contain.text', 'Notes')
page.getRequirementValue(2, 5).should('contain.text', 'curfew notes')
page
.getRequirementValue(2, 5)
.find('p:nth-of-type(2)')
.should('contain.text', 'Comment added by Jon Jones on 21 August 2024')
page.getRequirementValue(2, 5).find('a').should('not.exist')

cy.get(`[data-qa="requirementsValue"] `).within(() => cy.get('details').eq(0).click())
page.getRequirementLabel(1, 1).should('contain.text', 'Length of RAR')
page.getRequirementValue(1, 1).should('contain.text', '12 days')
page.getRequirementLabel(1, 2).should('contain.text', 'Completed RAR')
page.getRequirementValue(1, 2).should('contain.text', '1 day')
page.getRequirementLabel(1, 3).should('contain.text', 'Start date')
page.getRequirementValue(1, 3).should('contain.text', '12 April 2024')
page.getRequirementLabel(1, 4).should('contain.text', 'Notes')
page.getRequirementValue(1, 4).should('contain.text', 'Requirement created automatically')
page.getRequirementValue(1, 4).should('not.contain.text', '123456')
page.getRequirementValue(1, 4).find('a').should('contain.text', 'View full note')
page
.getRequirementValue(1, 4)
.find('p:nth-of-type(2)')
.should('contain.text', 'Comment added by Jon Jones on 21 August 2024')
page.getRequirementValue(1, 4).find('a').click()
cy.get(`[data-qa="name"]`).should('contain.text', 'Caroline Wolff')
cy.get('.app-summary-card__header').should('contain.text', '1 of 12 RAR days completed')
})
})
2 changes: 1 addition & 1 deletion integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default abstract class Page {
}

checkOnPage(): void {
cy.get('h1').contains(this.title)
cy.get('[data-qa=pageHeading]').contains(this.title)
}

signOut = (): PageElement => cy.get('[data-qa=signOut]')
Expand Down
12 changes: 11 additions & 1 deletion integration_tests/pages/sentence.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import Page from './page'
import Page, { PageElement } from './page'

export default class SentencePage extends Page {
constructor() {
super('Sentence')
}

getRequirementLabel = (requirementIndex: number, index: number): PageElement =>
cy.get(
`[data-qa="requirementsValue"] details:nth-of-type(${requirementIndex}) .govuk-summary-list__row:nth-of-type(${index}) dt`,
)

getRequirementValue = (requirementIndex: number, index: number): PageElement =>
cy.get(
`[data-qa="requirementsValue"] details:nth-of-type(${requirementIndex}) .govuk-summary-list__row:nth-of-type(${index}) dd`,
)
}
12 changes: 12 additions & 0 deletions server/data/masApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { TeamCaseload, UserCaseload, UserTeam } from './model/caseload'
import { ProfessionalContact } from './model/professionalContact'
import { CaseAccess, UserAccess } from './model/caseAccess'
import { LicenceConditionNoteDetails } from './model/licenceConditionNoteDetails'
import { RequirementNoteDetails } from './model/requirementNoteDetails'

export default class MasApiClient extends RestClient {
constructor(token: string) {
Expand Down Expand Up @@ -57,6 +58,17 @@ export default class MasApiClient extends RestClient {
})
}

async getSentenceRequirementNote(
crn: string,
requirementId: string,
noteId: string,
): Promise<RequirementNoteDetails | null> {
return this.get({
path: `/sentence/${crn}/requirement/${requirementId}/note/${noteId}`,
handle404: false,
})
}

async getContacts(crn: string): Promise<ProfessionalContact | null> {
return this.get({ path: `/sentence/${crn}/contacts`, handle404: false })
}
Expand Down
32 changes: 32 additions & 0 deletions server/data/model/requirementNoteDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PersonSummary } from './common'

export interface RequirementNoteDetails {
personSummary: PersonSummary
requirement: Requirement
}

export interface Requirement {
code: string
expectedStartDate?: string
actualStartDate: string
expectedEndDate?: string
actualEndDate?: string
terminationReason?: string
description: string
length: number
lengthUnitValue: string
requirementNote: RequirementNote
rar?: {
completed: number
scheduled: number
totalDays: number
}
}

export interface RequirementNote {
id: string
createdBy: string
createdByDate: string
note: string
hasNotesBeenTruncated: boolean
}
9 changes: 9 additions & 0 deletions server/data/model/sentenceDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ export interface Order {
startDate: string
}

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

export interface Requirement {
code: string
expectedStartDate: string
Expand All @@ -59,6 +67,7 @@ export interface Requirement {
description: string
codeDescription: string
length: string
requirementNotes: RequirementNote[]
notes: string
rar: Rar
}
Expand Down
27 changes: 27 additions & 0 deletions server/routes/sentence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,31 @@ export default function sentenceRoutes(router: Router, { hmppsAuthClient }: Serv
crn,
})
})

get('/case/:crn/sentence/requirement/:requirementId/note/:noteId', async (req, res, _next) => {
const { crn, requirementId, noteId } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)

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

const masClient = new MasApiClient(token)
const tierClient = new TierApiClient(token)

const [requirementNoteDetails, tierCalculation] = await Promise.all([
masClient.getSentenceRequirementNote(crn, requirementId, noteId),
tierClient.getCalculationDetails(crn),
])
res.render('pages/requirement-note', {
requirementNoteDetails,
tierCalculation,
crn,
})
})
}
2 changes: 1 addition & 1 deletion server/views/pages/address-book-professional.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{ title }}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{ title }}</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/appointments/appointment.njk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6" data-qa="pageHeading">
<span class="govuk-caption-xl" data-qa="appointmentType">
{% include './_appointment-prefix.njk' %}</span>
<span data-qa="appointmentTitle">{{ title }}</span>
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/caseload/caseload.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% endif %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h1 class="govuk-heading-xl">
<h1 class="govuk-heading-xl" data-qa="pageHeading">
{{ title }}
</h1>
{% include "./caseload-nav.njk" %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/handoff/delius.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

<p>You’ll need to use National Delius to:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/handoff/oasys.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

<p>You’ll need to use OASys to:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% set mainClasses = "app-container govuk-body" %}

{% block content %}
<h1 class="govuk-heading-l">Manage a Supervision</h1>
<h1 class="govuk-heading-l" data-qa="pageHeading">Manage a Supervision</h1>
<div class="govuk-grid-column-two-thirds">
<p>Not all cases are suitable for the Manage supervisions pilot. This service is only suitable for cases that have:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/addresses.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{ title }}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{ title }}</h1>


<!-- {{ govukWarningText({
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/adjustments.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

{% for adjustment in adjustments.provisions %}
{% set adjustmentsHtml %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/circumstances.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

{% for circumstance in circumstances.circumstances %}
{% set circumstanceHtml %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/contact.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">
<h1 class="govuk-heading-xl" data-qa="pageHeading">
<span data-qa="contactRelationshipTypeHeaderValue" class="govuk-caption-xl">{{ personalContact.relationshipType }}</span>
<span data-qa="contactNameHeaderValue">{{ title }}</span>
</h1>
Expand Down
Loading

0 comments on commit 51f9da9

Please sign in to comment.