Skip to content

Commit

Permalink
Man 48 improve mms dashboard my cases (#170)
Browse files Browse the repository at this point in the history
* MAN-48 - add recent case tab

* MAN-48 - add recent case tab

* MAN-48 - add recent case tab

* MAN-48 - add recent case tab

* MAN-48 - remove order logic in overview file, as this is done in the b/e api.

* MAN-48 - update overview cypress test

* MAN-48 - add new cypress test

* MAN-48 - update cypress test

* MAN-48 - remove log statement
  • Loading branch information
achimber-moj authored Oct 9, 2024
1 parent 689843f commit 3b7c816
Show file tree
Hide file tree
Showing 13 changed files with 1,124 additions and 25 deletions.
11 changes: 11 additions & 0 deletions integration_tests/e2e/overview.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ context('Overview', () => {
.should('contain.text', 'Previous concerns about coping in a hostel setting')
page.getRowData('risk', 'riskFlags', 'Value').should('contain.text', 'Risk to Known Adult')
page.getRowData('miscellaneous', 'tier', 'Value').should('contain.text', 'B2')

const expected =
'{"name":"Wolff,Caroline","crn":"X000001","dob":"9 January 2002","age":"22","tierScore":"B2","sentence":"12 month Community order"}'

cy.window()
.its('localStorage')
.invoke('getItem', 'recentCases')
.then(result => {
const recentCase = JSON.parse(JSON.stringify(result))
expect(expected, recentCase)
})
})
it('Risk information and tier is not provided due to 500 from ARNS and TIER', () => {
cy.visit('/case/X000002')
Expand Down
56 changes: 56 additions & 0 deletions integration_tests/e2e/recentCases.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Page from '../pages/page'
import RecentCasesPage from '../pages/recentCases'

context('Recent Cases', () => {
it('Recent Cases page is rendered', () => {
cy.visit('/recent-cases', {
onBeforeLoad(win) {
const recentCases = []
const recentCase = {
name: 'Wolff,Caroline',
crn: 'X000001',
dob: '9 January 2002',
age: 22,
tierScore: 'B2',
sentence: '12 month Community order',
}

recentCases.push(recentCase)
win.localStorage.setItem('recentCases', JSON.stringify(recentCases))
},
})

const page = Page.verifyOnPage(RecentCasesPage)

cy.get('h1').contains('Recently viewed cases')

cy.get('thead')
.eq(0)
.within(() => cy.get('th').eq(0).should('contain.text', 'Name / CRN'))
cy.get('thead')
.eq(0)
.within(() => cy.get('th').eq(1).should('contain.text', 'DOB/ Age'))
cy.get('thead')
.eq(0)
.within(() => cy.get('th').eq(2).should('contain.text', 'Tier'))
cy.get('thead')
.eq(0)
.within(() => cy.get('th').eq(3).should('contain.text', 'Sentence'))

page.createAliasAtIndexWithin('tbody', 0, 'td', 0, 'row1col1')
cy.get('@row1col1').within(() => cy.get('a').invoke('attr', 'href').should('equal', './case/X000001'))
cy.get('@row1col1').within(() => cy.contains('a', 'Wolff,Caroline'))
cy.get('@row1col1').within(() => cy.contains('span', 'X000001'))

page.createAliasAtIndexWithin('tbody', 0, 'td', 1, 'row1col2')
cy.get('@row1col2').within(() => cy.contains('9 January 2002'))
cy.get('@row1col2').within(() => cy.contains('span', 22))

cy.get('tbody')
.eq(0)
.within(() => cy.get('td').eq(2).should('contain.text', 'B2'))
cy.get('tbody')
.eq(0)
.within(() => cy.get('td').eq(3).should('contain.text', '12 month Community order'))
})
})
12 changes: 12 additions & 0 deletions integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ export default abstract class Page {
.eq(index)
.within(() => cy.get('a').eq(anchorIndex).invoke('attr', 'href').should('equal', value))
}

createAliasAtIndexWithin = (
element: string,
index: number,
withinElement: string,
withinIndex: number,
aliasName: string,
) => {
cy.get(element)
.eq(index)
.within(() => cy.get(withinElement).eq(withinIndex).as(aliasName))
}
}
7 changes: 7 additions & 0 deletions integration_tests/pages/recentCases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Page from './page'

export default class RecentCasesPage extends Page {
constructor() {
super('Recently viewed cases')
}
}
18 changes: 18 additions & 0 deletions server/routes/caseload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default function caseloadRoutes(router: Router, { hmppsAuthClient }: Serv
page => addParameters(req, { page: page.toString() }),
caseload?.pageSize || config.apis.masApi.pageSize,
)

res.render('pages/caseload/minimal-cases', {
pagination,
caseload,
Expand Down Expand Up @@ -235,4 +236,21 @@ export default function caseloadRoutes(router: Router, { hmppsAuthClient }: Serv
res.redirect(`/teams`)
}
})

get('/recent-cases', async (req, res, _next) => {
const currentNavSection = 'recentCases'

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

res.render('pages/caseload/recent-cases', {
currentNavSection,
})
})
}
7 changes: 7 additions & 0 deletions server/views/pages/caseload/caseload-nav.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
{% endif %}
href="/teams">Team cases</a>
</li>
<li class="moj-sub-navigation__item" data-qa="recentCasesTab">
<a class="moj-sub-navigation__link govuk-link--no-visited-state"
{% if currentNavSection == 'recentCases' %}
aria-current="page"
{% endif %}
href="/recent-cases"> Recently viewed cases</a>
</li>
</ul>
</nav>
</div>
Expand Down
68 changes: 68 additions & 0 deletions server/views/pages/caseload/recent-cases.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{% extends "./caseload.njk" %}
{% set title = 'Recently viewed cases' %}
{% block pageTitle %}{{ title }}{% endblock %}

{% block pageContent %}

<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Name / CRN</th>
<th scope="col" class="govuk-table__header">DOB/ Age</th>
<th scope="col" class="govuk-table__header">Tier</th>
<th scope="col" class="govuk-table__header">Sentence</th>
</tr>
</thead>
<tbody id="tabBody" class="govuk-table__body">
<script nonce="{{ cspNonce }}">
const recentCases = JSON.parse(localStorage.getItem('recentCases'))
if (recentCases != null) {
recentCases.forEach((recentCase) => {
const tableBody = document.getElementById("tabBody")
const row = document.createElement("tr")
row.className = "govuk-table__row"
const rd1 = document.createElement("td")
rd1.className = "govuk-table__cell"
const anchor = document.createElement("a")
anchor.className = "govuk-!-font-weight-bold"
anchor.href = "./case/" + recentCase.crn
anchor.text = recentCase.name
const span1 = document.createElement("span")
span1.className = "govuk-!-font-weight-bold secondary-text"
span1.innerText = recentCase.crn
rd1.appendChild(anchor)
rd1.appendChild(document.createElement("br"))
rd1.appendChild(span1)
const rd2 = document.createElement("td")
rd2.className = "govuk-table__cell"
rd2.innerText = recentCase.dob
const span2 = document.createElement("span")
span2.className = "secondary-text"
span2.innerText = "Age " + recentCase.age
rd2.appendChild(document.createElement("br"))
rd2.appendChild(span2)
const rd3 = document.createElement("td")
rd3.className = "govuk-table__cell"
rd3.innerText = recentCase.tierScore
const rd4 = document.createElement("td")
rd4.className = "govuk-table__cell"
rd4.innerText = recentCase.sentence
row.appendChild(rd1)
row.appendChild(rd2)
row.appendChild(rd3)
row.appendChild(rd4)
tableBody.appendChild(row)
}
)
}
</script>
</table>
{% endblock %}
45 changes: 44 additions & 1 deletion server/views/pages/overview.njk
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,13 @@


{% set numberOfSentences = overview.sentences.length %}
{% for sentence in overview.sentences|sort(attribute='eventNumber', reverse=true) %}
{% for sentence in overview.sentences %}
{% set sentenceHtml %}
{% set order %}
{% if sentence.order %}
{% if loop.first %}
<input type="hidden" id="sentence" name="sentence" value="{{ sentence.order.description }}">
{% endif %}
{{ sentence.order.description }}<br />
From {{ sentence.order.startDate | dateWithNoDay }} to {{ sentence.order.endDate | dateWithNoDay }}<br />
{{ sentence.order.startDate | monthsOrDaysElapsed }} elapsed
Expand Down Expand Up @@ -438,4 +441,44 @@
classes: 'govuk-!-margin-bottom-6 app-summary-card--large-title',
html: miscellaneous
}) }}

<input type="hidden" id="caseCrn" name="crn" value="{{ crn }}">
<input type="hidden" id="name" name="name" value="{{ overview.personalDetails.name.surname }},{{ overview.personalDetails.name.forename }}">
<input type="hidden" id="dob" name="dob" value="{{ headerDob | dateWithYear }}">
<input type="hidden" id="age" name="age" value="{{ headerDob | yearsSince }}">
<input type="hidden" id="tier" name="age" value="{{ tierCalculation.tierScore }}">

<script nonce="{{ cspNonce }}">
const crn = document.getElementById("caseCrn").value
const name = document.getElementById("name").value
const dob = document.getElementById("dob").value
const age = document.getElementById("age").value
const tier = document.getElementById("tier").value
const sentence = document.getElementById("sentence").value
let recentCases = []
let recentCase
if (localStorage.getItem("recentCases") != null) {
recentCases = JSON.parse(localStorage.getItem('recentCases'))
recentCase = recentCases.findIndex(obj => obj.crn === crn)
if (recentCase !== -1) {
recentCases.splice(recentCase, 1);
}
}
recentCase = {
name: name,
crn: crn,
dob: dob,
age: age,
tierScore: tier,
sentence: sentence
};
recentCases.unshift(recentCase)
localStorage.setItem('recentCases', JSON.stringify(recentCases))
</script>
{% endblock %}
36 changes: 18 additions & 18 deletions wiremock/mappings/X000001-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@
}
},
"sentences": [
{
"additionalOffences": [],
"eventNumber": "3",
"mainOffence": {
"code": "18502",
"description": "Breach of Restraining Order (Protection from Harassment Act 1997) - 00831"
},
"order": {
"description": "12 month Community order",
"endDate": "2024-12-01",
"startDate": "2023-12-01"
},
"rar": {
"completed": 14,
"scheduled": 2,
"totalDays": 16
}
},
{
"additionalOffences": [
{
Expand All @@ -81,24 +99,6 @@
"scheduled": 1,
"totalDays": 10
}
},
{
"additionalOffences": [],
"eventNumber": "3",
"mainOffence": {
"code": "18502",
"description": "Breach of Restraining Order (Protection from Harassment Act 1997) - 00831"
},
"order": {
"description": "12 month Community order",
"endDate": "2024-12-01",
"startDate": "2023-12-01"
},
"rar": {
"completed": 14,
"scheduled": 2,
"totalDays": 16
}
}
],
"activity": {
Expand Down
Loading

0 comments on commit 3b7c816

Please sign in to comment.