From d1bb66bcba866e845c77776bb4b3a542b7487b5d Mon Sep 17 00:00:00 2001 From: Daniel Lackenby Date: Wed, 15 Jan 2025 11:06:33 +0000 Subject: [PATCH] Finish replacing Active and Previous Order with Summary Card/Lists. Update Cypruss tests for new format. --- .../cypress/e2e/case-summary.feature | 122 ++++++++++--- .../cypress/e2e/case-summary/steps.js | 2 +- .../support/step_definitions/common.js | 4 + .../support/step_definitions/headings.js | 1 - .../support/step_definitions/summaries.js | 44 +++++ .../cypress/support/utils/time.js | 36 ++++ server/routes/handlers/caseSummary.js | 2 +- .../getProbationRecordRouteHandler.js | 2 +- server/routes/index.js | 8 +- .../case-summary-record-order-breach.njk | 0 .../case-summary-record-order-licence.njk | 0 .../case-summary-record-order.njk | 0 .../case-summary-record.njk | 114 ++---------- .../{ => case-summary}/case-summary-risk.njk | 0 .../views/{ => case-summary}/case-summary.njk | 0 .../partials/orders-active/macro.njk | 3 + .../partials/orders-active/template.njk | 74 ++++++++ .../partials/orders-previous/macro.njk | 3 + .../partials/orders-previous/template.njk | 31 ++++ .../views/components/active-orders/macro.njk | 3 - .../components/active-orders/template.njk | 162 ------------------ .../views/components/summary-card/macro.njk | 3 + .../components/summary-card/template.njk | 26 +++ .../views/components/summary-list/macro.njk | 3 + .../components/summary-list/template.njk | 8 + .../getProbationRecordRouteHandler.test.js | 2 +- 26 files changed, 350 insertions(+), 303 deletions(-) create mode 100644 integration-tests/cypress/support/step_definitions/summaries.js create mode 100644 integration-tests/cypress/support/utils/time.js rename server/views/{ => case-summary}/case-summary-record-order-breach.njk (100%) rename server/views/{ => case-summary}/case-summary-record-order-licence.njk (100%) rename server/views/{ => case-summary}/case-summary-record-order.njk (100%) rename server/views/{ => case-summary}/case-summary-record.njk (56%) rename server/views/{ => case-summary}/case-summary-risk.njk (100%) rename server/views/{ => case-summary}/case-summary.njk (100%) create mode 100644 server/views/case-summary/partials/orders-active/macro.njk create mode 100644 server/views/case-summary/partials/orders-active/template.njk create mode 100644 server/views/case-summary/partials/orders-previous/macro.njk create mode 100644 server/views/case-summary/partials/orders-previous/template.njk delete mode 100644 server/views/components/active-orders/macro.njk delete mode 100644 server/views/components/active-orders/template.njk create mode 100644 server/views/components/summary-card/macro.njk create mode 100644 server/views/components/summary-card/template.njk create mode 100644 server/views/components/summary-list/macro.njk create mode 100644 server/views/components/summary-list/template.njk diff --git a/integration-tests/cypress/e2e/case-summary.feature b/integration-tests/cypress/e2e/case-summary.feature index 5098b5c3f..6de512334 100644 --- a/integration-tests/cypress/e2e/case-summary.feature +++ b/integration-tests/cypress/e2e/case-summary.feature @@ -316,22 +316,63 @@ Feature: Case summary When I clear the filters When I click the "Lenore Marquez" link And I click the sub navigation with "Probation record" text - Then I should see a level 2 heading with text "Current orders (3)" - And I should see link "ORA Community Order (18 Months)" with href "record/1403337513" - And I should see the text "Curfew Arrangement" within element with class "qa-current-licence-conditions-1" - And I should see the text "Curfew Arrangement" within element with class "qa-current-pss-requirements-2" - And I should see the body text "Stealing mail bags or postal packets or unlawfully taking away or opening mail bag - 04200" - And I should see the hint text "Started on 20 May 2019" - And I should see a level 2 heading with text "Previous orders (11)" - And I should see link "CJA - Std Determinate Custody" with href "record/636401162" - And I should see the text "Burglary (dwelling) with intent to commit, or the commission of an offence triable only on indictment - 02801" within element with class "qa-previous-order-1-offence" - And I should see the text "Ended on 23 Jan 2018" within element with class "qa-previous-order-1-end-date" - And I should see a level 1 heading with text "Lenore Marquez" + Then I should see a level 1 heading with text "Lenore Marquez" And I should see a "l" sized level 1 heading with text "Probation record" And I should see the following "m" sized level 2 headings | Pre-sentence report requested | Current orders | Previous orders | Offender manager | Last pre-sentence report | Last OASys assessment | + Then I should see a level 2 heading with text "Current orders (3)" + Then I should see a summary card with id "activeOrder0" and title "ORA Community Order (18 Months)" + And I should see a summary card with id "activeOrder0" and action + | View record | for ORA Community Order | record/1403337513 | + And I should see a summary card with id "activeOrder0" and summary list rows + | Description | Stealing mail bags or postal packets or unlawfully taking away or opening mail bag - 04200 | Started on 20 May 2019 | | | + | Requirements | Unpaid Work – Regular – 60 Hours | Rehabilitation Activity Requirement (RAR) – 20 Days | Court – Accredited Programme – ASRO | Court – Accredited Programme – Building Better Relationships – BBR | + Then I should see a summary card with id "activeOrder1" and title "ORA Adult Custody (inc PSS) (12 Months)" + And I should see a summary card with id "activeOrder1" and action + | View record | for ORA Adult Custody (inc PSS) | record/1309234876 | + And I should see a summary card with id "activeOrder1" and summary list rows + | Description | Dangerous driving/Aid, abet cause or permit reckless driving - 80200 | Started on {6 months ago} | | + | Status | On license | | | + | Licence conditions | Alcohol | Curfew Arrangement | Participate or co-op with Programme or Activities | + Then I should see a summary card with id "activeOrder2" and title "ORA Adult Custody (inc PSS) (18 Months)" + And I should see a summary card with id "activeOrder2" and action + | View record | for ORA Adult Custody (inc PSS) | record/2360414697 | + And I should see a summary card with id "activeOrder2" and summary list rows + | Description | Aggravated burglary in a building other than a dwelling (including attempts) - 03100 | Started on {6 months ago} | | + | Status | On license | | | + | Licence conditions | Alcohol | Curfew Arrangement | Participate or co-op with Programme or Activities | + | Status | On post-sentence supervision (PSS) | | | + | PSS requirements | Standard 7 conditions | Specified Activity – ETE – High intensity | Curfew Arrangement | + + And I should see a level 2 heading with text "Previous orders (11)" + Then I should see a summary card with id "previousOrder0" and title "CJA - Std Determinate Custody (18 Months)" + And I should see a summary card with id "previousOrder0" and action + | View record | CJA - Std Determinate Custody | record/636401162 | + And I should see a summary card with id "previousOrder0" and summary list rows + | Description | Burglary (dwelling) with intent to commit, or the commission of an offence triable only on indictment - 02801 | Started on 23 Jan 2018 | + Then I should see a summary card with id "previousOrder1" and title "Adult Custody < 12m (18 Months)" + And I should see a summary card with id "previousOrder1" and action + | View record | Adult Custody < 12m | record/7925250000 | + And I should see a summary card with id "previousOrder1" and summary list rows + | Description | Arson endangering life - 05601 | Started on 27 Aug 2019 | + Then I should see a summary card with id "previousOrder2" and title "CJA - Indeterminate Public Prot. (18 Months)" + And I should see a summary card with id "previousOrder2" and action + | View record | CJA - Indeterminate Public Prot. | record/1475462502 | + And I should see a summary card with id "previousOrder2" and summary list rows + | Description | Common and other types of assault - 10500 | Started on 9 Aug 2017 | + Then I should see a summary card with id "previousOrder3" and title "ORA Community Order (18 Months)" + And I should see a summary card with id "previousOrder3" and action + | View record | ORA Community Order | record/1906091609 | + And I should see a summary card with id "previousOrder3" and summary list rows + | Description | (Assault PC (Indictable/Either way) - 00807) | Started on 4 Sep 2019 | + Then I should see a summary card with id "previousOrder4" and title "Life imprisonment (Adult) (18 Months)" + And I should see a summary card with id "previousOrder4" and action + | View record | Life imprisonment (Adult) | record/943466740 | + And I should see a summary card with id "previousOrder4" and summary list rows + | Description | High treason - 06200 | Started on 23 Jan 2018 | + And I should see the body text "Angel Extravaganza" And I should see the hint text "Allocated on 12 Aug 2017" And I should see the body text "Email: d@none.com" @@ -348,12 +389,41 @@ Feature: Case summary And I should see the body text "OASys Assessment Layer 3" And I should see the hint text "Completed on 20 Jun 2018" - And I should see the following level 3 headings - | Requirements | Status | Licence conditions | Status | Licence conditions | Status | PSS requirements | - And I should see 5 previous orders When I click the "Show all previous orders" button Then I should see 11 previous orders + + Then I should see a summary card with id "previousOrder5" and title "ORA Suspended Sentence Order (18 Months)" + And I should see a summary card with id "previousOrder5" and action + | View record | ORA Suspended Sentence Order | record/1081636758 | + And I should see a summary card with id "previousOrder5" and summary list rows + | Description | Aiding suicide - 07600 | Started on 4 Sep 2019 | + Then I should see a summary card with id "previousOrder6" and title "ORA Adult Custody (Not PSS) (18 Months)" + And I should see a summary card with id "previousOrder6" and action + | View record | ORA Adult Custody (Not PSS) | record/636401231 | + And I should see a summary card with id "previousOrder6" and summary list rows + | Description | Aiding suicide - 07600 | Started on 25 Dec 2017 | + Then I should see a summary card with id "previousOrder7" and title "ORA Adult Custody (Not PSS) (18 Months)" + And I should see a summary card with id "previousOrder7" and action + | View record | ORA Adult Custody (Not PSS) | record/1999409258 | + And I should see a summary card with id "previousOrder7" and summary list rows + | Description | Burglary (dwelling) with intent to commit, or the commission of an offence triable only on indictment - 02801 | Started on 4 Aug 2018 | + Then I should see a summary card with id "previousOrder8" and title "Fine (18 Months)" + And I should see a summary card with id "previousOrder8" and action + | View record | Fine | record/2319221210 | + And I should see a summary card with id "previousOrder8" and summary list rows + | Description | Arson endangering life - 05601 | Started on 23 Jan 2018 | + Then I should see a summary card with id "previousOrder9" and title "ORA Adult Custody (Not PSS) (18 Months)" + And I should see a summary card with id "previousOrder9" and action + | View record | ORA Adult Custody (Not PSS) | record/754151578 | + And I should see a summary card with id "previousOrder9" and summary list rows + | Description | Acknowledging bail in false name - 08303 | Started on 21 Sep 2018 | + Then I should see a summary card with id "previousOrder10" and title "Fine" + And I should see a summary card with id "previousOrder10" and action + | View record | Fine | record/901046255 | + And I should see a summary card with id "previousOrder10" and summary list rows + | Description | Common and other types of assault - 10500 | Started on 23 Sep 2018 | + And There should be no a11y violations Scenario: View the probation record section of the case summary for a current offender who is currently in custody @@ -367,11 +437,13 @@ Feature: Case summary When I click the "English Madden" link And I click the sub navigation with "Probation record" text Then I should see the level 2 heading "Current orders (1)" - And I should see link "CJA - Std Determinate Custody (18 Months)" with href "record/345464567" - And I should see the body text "Burglary (dwelling) with intent to commit, or the commission of an offence triable only on indictment - 02801" - And I should see the hint text "Started on 8 Mar 2017" - And I should see the text "Status" within element with class "govuk-heading-s" - And I should see the body text "In custody" + Then I should see a summary card with id "activeOrder0" and title "CJA - Std Determinate Custody (18 Months)" + And I should see a summary card with id "activeOrder0" and action + | View record | CJA - Std Determinate Custody | record/345464567 | + And I should see a summary card with id "activeOrder0" and summary list rows + | Description | Burglary (dwelling) with intent to commit, or the commission of an offence triable only on indictment - 02801 | Started on 8 Mar 2017 | + | Requirements | Rehabilitation Activity Requirement (RAR) – 20 Days | Court – Accredited Programme – Building Better Relationships – BBR – 20 Days | + | Status | In custody | | And There should be no a11y violations @@ -407,7 +479,7 @@ Feature: Case summary And I should see the following "m" sized level 2 headings | Pre-sentence report requested | Current orders | Previous orders | Last OASys assessment | - When I click the "ORA Community Order (18 Months)" link + When I click the "View record" link with id "activeOrder0-view" Then I should be on the "ORA Community Order (18 Months)" page And I should see the heading "ORA Community Order (18 Months)" And I should see the level 2 heading "Attendance" @@ -543,9 +615,9 @@ Feature: Case summary And I should see the body text "Pre-Sentence Report - Fast" And I should see the hint text "Completed less than 1 month ago" - And I should see link "ORA Community Order (18 Months)" with href "record/1361422142" + And I should see link "View record" with href "record/1361422142" And I should see the breach badge - When I click the "ORA Community Order (18 Months)" link + When I click the "View record" link with id "activeOrder0-view" Then I should be on the "ORA Community Order (18 Months)" page And I should see the heading "ORA Community Order (18 Months)" @@ -642,7 +714,7 @@ Feature: Case summary And I should see the following "m" sized level 2 headings | Pre-sentence report requested | Current orders | Previous orders | Last OASys assessment | - When I click the "CJA - Std Determinate Custody" link + When I click the "View record" link with id "previousOrder0-view" Then I should be on the "CJA - Std Determinate Custody (18 Months)" page And I should see the heading "CJA - Std Determinate Custody" @@ -683,7 +755,7 @@ Feature: Case summary Then I should be on the "Probation record" page And I should see a level 1 heading with text "Lenore Marquez" - When I click the "ORA Community Order (18 Months)" link + When I click the "View record" link with id "activeOrder0-view" Then I should be on the "ORA Community Order (18 Months)" page And I should see the heading "ORA Community Order (18 Months)" And I should see the level 2 heading "Requirements" @@ -697,7 +769,7 @@ Feature: Case summary Then I should be on the "Probation record" page And I should see a level 1 heading with text "Lenore Marquez" - When I click the "CJA - Std Determinate Custody" link + When I click the "View record" link with id "previousOrder0-view" Then I should be on the "CJA - Std Determinate Custody (18 Months)" page And I should see the heading "CJA - Std Determinate Custody" And I should see the level 2 heading "Requirements" diff --git a/integration-tests/cypress/e2e/case-summary/steps.js b/integration-tests/cypress/e2e/case-summary/steps.js index f624394fb..43c01b4d6 100644 --- a/integration-tests/cypress/e2e/case-summary/steps.js +++ b/integration-tests/cypress/e2e/case-summary/steps.js @@ -5,7 +5,7 @@ import { Then, When } from '@badeball/cypress-cucumber-preprocessor' Then('I should see {int} previous orders', $int => { cy.get('#previousOrders').within(() => { - cy.get('tr').should('have.length', $int) + cy.get('.govuk-summary-card').should('have.length', $int) }) }) diff --git a/integration-tests/cypress/support/step_definitions/common.js b/integration-tests/cypress/support/step_definitions/common.js index 825592294..331edf8d6 100644 --- a/integration-tests/cypress/support/step_definitions/common.js +++ b/integration-tests/cypress/support/step_definitions/common.js @@ -299,6 +299,10 @@ When('I click the {string} link', $string => { cy.get($string === 'Back' ? '.govuk-back-link' : '.govuk-link').contains($string).click() }) +When('I click the {string} link with id {string}', ($string, $id) => { + cy.get(`#${$id}`).contains($string).click() +}) + When('I clear the filters', () => { cy.url().then((url) => { cy.visit(url + '?clearFilters=true') diff --git a/integration-tests/cypress/support/step_definitions/headings.js b/integration-tests/cypress/support/step_definitions/headings.js index 66e3a440d..36b80c3ae 100644 --- a/integration-tests/cypress/support/step_definitions/headings.js +++ b/integration-tests/cypress/support/step_definitions/headings.js @@ -33,7 +33,6 @@ Then('I should see a {string} sized level {int} heading with text {string}', ($s }) Then('I should see the following level {int} headings', ($level, $data) => { - cy.debug($level, $data) $data.raw()[0].forEach((text) => { cy.get(`h${$level}`).contains(text) }) diff --git a/integration-tests/cypress/support/step_definitions/summaries.js b/integration-tests/cypress/support/step_definitions/summaries.js new file mode 100644 index 000000000..0a7679676 --- /dev/null +++ b/integration-tests/cypress/support/step_definitions/summaries.js @@ -0,0 +1,44 @@ +const { Then } = require('@badeball/cypress-cucumber-preprocessor') +const { parseCypressDate } = require('../utils/time') + +Then('I should see a summary card with id {string} and title {string}', ($id, $title) => { + cy.get(`#${$id}`).should('have.attr', 'class').and('include', 'govuk-summary-card') + cy.get(`#${$id}`).within(() => { + cy.get('h3').contains($title).should('have.attr', 'class').and('include', 'govuk-summary-card__title') + }) +}) + +Then('I should see a summary card with id {string} and action', ($id, $data) => { + cy.get(`#${$id}`).within(() => { + $data.raw().forEach((row) => { + cy.get('.govuk-summary-card__action').within(() => { + const link = () => cy.get('.govuk-link') + link().contains(row[0]).should('have.attr', 'href').and('include', row[2]) + link().within(() => { + cy.get('span').contains(row[1]).should('exist') + }) + }) + }) + }) +}) + +Then('I should see a summary card with id {string} and summary list rows', ($id, $data) => { + cy.get(`#${$id}`).within(() => { + const content = () => cy.get('.govuk-summary-card__content') + content().should('exist') + content().within(() => { + cy.get('.govuk-summary-list').should('exist') + $data.raw().forEach((row, index) => { + cy.get('.govuk-summary-list__row').eq(index).within(() => { + cy.get('dt').contains(row[0]).should('have.attr', 'class').and('include', 'govuk-summary-list__key') + const value = () => cy.get('dd') + row.slice(1).forEach((expected) => { + if(expected) { + value().contains(parseCypressDate(expected, 'D MMM YYYY')) + } + }) + }) + }) + }) + }) +}) \ No newline at end of file diff --git a/integration-tests/cypress/support/utils/time.js b/integration-tests/cypress/support/utils/time.js new file mode 100644 index 000000000..b48513fa3 --- /dev/null +++ b/integration-tests/cypress/support/utils/time.js @@ -0,0 +1,36 @@ +const moment = require('moment') + +/** + * Based on the format "{number, period, delta}", will replace the slug with + * the time from today using the provided format + * @param {*} input The input to parse + * @param {*} dateFormat The format to use on the resultant data + * @returns The orignal input if a match is found, else will replace the slug with the caluclated date + */ +const parseCypressDate = (input, dateFormat) => { + if(!input.match('.*{.+}')) { + return input + } else { + const timeString = input.substring(input.indexOf('{') + 1, input.indexOf('}')) + const timeParts = timeString.split(' ') + const number = timeParts[0] + const period = timeParts[1] + const delta = timeParts[2] + let moddedTime = moment(); + // Expand these options as required + switch (delta) { + case 'ago': + moddedTime = moddedTime.add((-1 * number), period) + break; + case 'ahead': + moddedTime = moddedTime.add(number, period) + break; + } + const result = input.slice(0, input.indexOf('{')) + moddedTime.format(dateFormat) + return result + } +} + +module.exports = { + parseCypressDate +} \ No newline at end of file diff --git a/server/routes/handlers/caseSummary.js b/server/routes/handlers/caseSummary.js index a684c361a..ffa76b26a 100644 --- a/server/routes/handlers/caseSummary.js +++ b/server/routes/handlers/caseSummary.js @@ -78,7 +78,7 @@ const caseSummaryHandler = utils => async (req, res) => { session.backLink = path session.caseCommentBlankError = undefined - res.render('case-summary', templateValues) + res.render('case-summary/case-summary', templateValues) } const caseSummaryPostHandler = utils => async (req, res) => { } diff --git a/server/routes/handlers/getProbationRecordRouteHandler.js b/server/routes/handlers/getProbationRecordRouteHandler.js index 142c58a5a..b2206b0c9 100644 --- a/server/routes/handlers/getProbationRecordRouteHandler.js +++ b/server/routes/handlers/getProbationRecordRouteHandler.js @@ -27,7 +27,7 @@ const getProbationRecordRouteHandler = (communityService, getCaseAndTemplateValu templateValues.data.psrRequestedConvictions = getPsrRequestedConvictions(communityResponse) templateValues.data.lastPsrWithSentence = getLastSentencedConvictionPSR(communityResponse) - res.render('case-summary-record', templateValues) + res.render('case-summary/case-summary-record', templateValues) } module.exports = getProbationRecordRouteHandler diff --git a/server/routes/index.js b/server/routes/index.js index f04312b64..91be1b065 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -541,7 +541,7 @@ module.exports = function Index ({ authenticationMiddleware }) { templateValues.title = getOrderTitle(communityResponse) - res.render('case-summary-record-order', templateValues) + res.render('case-summary/case-summary-record-order', templateValues) }) ) @@ -574,7 +574,7 @@ module.exports = function Index ({ authenticationMiddleware }) { ...breachData, ...breachDetails } - res.render('case-summary-record-order-breach', templateValues) + res.render('case-summary/case-summary-record-order-breach', templateValues) }) ) @@ -604,7 +604,7 @@ module.exports = function Index ({ authenticationMiddleware }) { const communityResponse = await getProbationRecord(crn) templateValues.data.communityData = communityResponse || {} - res.render('case-summary-record-order-licence', templateValues) + res.render('case-summary/case-summary-record-order-licence', templateValues) }) ) @@ -625,7 +625,7 @@ module.exports = function Index ({ authenticationMiddleware }) { ...templateValues.params } - res.render('case-summary-risk', templateValues) + res.render('case-summary/case-summary-risk', templateValues) }) ) diff --git a/server/views/case-summary-record-order-breach.njk b/server/views/case-summary/case-summary-record-order-breach.njk similarity index 100% rename from server/views/case-summary-record-order-breach.njk rename to server/views/case-summary/case-summary-record-order-breach.njk diff --git a/server/views/case-summary-record-order-licence.njk b/server/views/case-summary/case-summary-record-order-licence.njk similarity index 100% rename from server/views/case-summary-record-order-licence.njk rename to server/views/case-summary/case-summary-record-order-licence.njk diff --git a/server/views/case-summary-record-order.njk b/server/views/case-summary/case-summary-record-order.njk similarity index 100% rename from server/views/case-summary-record-order.njk rename to server/views/case-summary/case-summary-record-order.njk diff --git a/server/views/case-summary-record.njk b/server/views/case-summary/case-summary-record.njk similarity index 56% rename from server/views/case-summary-record.njk rename to server/views/case-summary/case-summary-record.njk index 646294ec9..e745a5c59 100644 --- a/server/views/case-summary-record.njk +++ b/server/views/case-summary/case-summary-record.njk @@ -1,6 +1,7 @@ {% extends "partials/case-details.njk" %} -{% from "components/active-orders/macro.njk" import activeOrdersBlock %} +{% from "./partials/orders-active/macro.njk" import activeOrdersBlock %} +{% from "./partials/orders-previous/macro.njk" import previousOrdersBlock %} {%- set moment = params.moment -%} {%- set communityData = data.communityData -%} @@ -109,112 +110,17 @@ {% endif %} {% if activeOrders | length %} - {{ activeOrdersBlock(activeOrders, moment, displayDateFormat, false)}} + {{ activeOrdersBlock(activeOrders, moment, displayDateFormat) }} {% endif %} - {# {% if activeOrders | length %} -

Current orders ({{ activeOrders | length }}) -

- {%- for order in activeOrders %} -

- {{ order.sentence.description + (' (' + order.sentence.length + ' ' + order.sentence.lengthUnits + ')' if order.sentence.length) }} - {% if order.inBreach %}Breach{% endif %} -

-

{{ order.offences[0].description }}

-

Started - on {{ moment(order.sentence.startDate, 'YYYY-MM-DD').format(displayDateFormat) }}

- - {% if order.requirements and order.requirements | length %} -

Requirements

- - - {% endif %} - - {% if order.custodialType.description === "In Custody" %} -

Status

-

In custody

- {% endif %} - - {% if order.licenceConditions and order.licenceConditions | length %} -

Status

-

On licence

- -

Licence conditions

- - {% endif %} - - {% if order.pssRequirements and order.pssRequirements | length %} -

Status

-

On post-sentence supervision (PSS)

- -

PSS requirements

- - {% endif %} - -
- - {% endfor -%} - {% endif %} #} - - {% if previousOrders | length %} - {% if params.showAllPreviousOrders === params.hearingId %} - {% set limitPreviousOrders = previousOrders | length %} - {% else %} - {% set limitPreviousOrders = 5 %} - {% endif %} - -
-

- Previous orders ({{ previousOrders | length }}) -

- - - {%- for order in previousOrders | limit(limitPreviousOrders) %} - - - - - {% endfor -%} - -
-

{{ order.sentence.description + (' (' + order.sentence.length + ' ' + order.sentence.lengthUnits + ')' if order.sentence.length ) }} -

-

{{ order.offences[0].description }}

-
-

- Ended - on {{ moment(order.sentence.terminationDate, 'YYYY-MM-DD').format(displayDateFormat) }}

-
- {% if previousOrders | length > limitPreviousOrders %} - - {% endif %} -
+ {% if previousOrders | length %} + {% if params.showAllPreviousOrders === params.hearingId %} + {% set limitPreviousOrders = previousOrders | length %} + {% else %} + {% set limitPreviousOrders = 5 %} + {% endif %} + {{ previousOrdersBlock(previousOrders, limitPreviousOrders, moment, displayDateFormat) }} {% endif %} -
diff --git a/server/views/case-summary-risk.njk b/server/views/case-summary/case-summary-risk.njk similarity index 100% rename from server/views/case-summary-risk.njk rename to server/views/case-summary/case-summary-risk.njk diff --git a/server/views/case-summary.njk b/server/views/case-summary/case-summary.njk similarity index 100% rename from server/views/case-summary.njk rename to server/views/case-summary/case-summary.njk diff --git a/server/views/case-summary/partials/orders-active/macro.njk b/server/views/case-summary/partials/orders-active/macro.njk new file mode 100644 index 000000000..8476647f3 --- /dev/null +++ b/server/views/case-summary/partials/orders-active/macro.njk @@ -0,0 +1,3 @@ +{% macro activeOrdersBlock(orders, moment, displayDateFormat) %} + {%- include "./template.njk" -%} +{% endmacro %} diff --git a/server/views/case-summary/partials/orders-active/template.njk b/server/views/case-summary/partials/orders-active/template.njk new file mode 100644 index 000000000..bdee0380e --- /dev/null +++ b/server/views/case-summary/partials/orders-active/template.njk @@ -0,0 +1,74 @@ +{% from "components/summary-card/macro.njk" import summaryCard %} + +
+

+ Current orders + ({{ orders | length }}) +

+
    + {% for order in orders %} + {% set id = "activeOrder" + loop.index0%} + {% set actionId = id + "-view"%} + {% set title %} + {{ order.sentence.description + (' (' + order.sentence.length + ' ' + order.sentence.lengthUnits + ')' if order.sentence.length) }} + {% if order.inBreach %} + Breach + {% endif %} + {% endset %} + {% set descriptionValue %} +

    {{order.offences[0].description }}

    +

    Started on {{ moment(order.sentence.startDate, 'YYYY-MM-DD').format(displayDateFormat) }}

    + {% endset %} + {% set rows = [{ key: "Description", value: descriptionValue }] %} + {% if order.requirements and order.requirements | length %} + {% set requirementsValue %} +
      + {%- for requirement in order.requirements %} + {% set category = requirement.requirementTypeMainCategory.description or requirement.adRequirementTypeMainCategory.description %} + {% set subCategory = requirement.requirementTypeSubCategory.description or requirement.adRequirementTypeSubCategory.description %} +
    • + {{ category | replace("-", "–") }} {{ " – " + subCategory if category !== subCategory }} + {{ ' – ' + requirement.length + ' ' + requirement.lengthUnit if requirement.length > 0 }} +
    • + {% endfor %} +
    + {% endset %} + {% set rows = (rows.push({ key: "Requirements", value: requirementsValue }), rows) %} + {% endif %} + {% if order.custodialType.description === "In Custody" %} + {% set rows = (rows.push({ key: "Status", value: "In custody"}), rows)%} + {% endif %} + {% if order.licenceConditions and order.licenceConditions | length %} + {% set licenseConditions %} +
      + {%- for licenceCondition in order.licenceConditions %} +
    • {{ licenceCondition.description }}
    • + {% endfor %} +
    + {% endset %} + {% set rows = (rows.push({ key: "Status", value: "On license"}), rows)%} + {% set rows = (rows.push({ key: "Licence conditions", value: licenseConditions}), rows)%} + {% endif%} + {% if order.pssRequirements and order.pssRequirements | length %} + {% set pssRequirements %} +
      + {%- for pssRequirement in order.pssRequirements %} +
    • {{ pssRequirement.description + (' – ' + pssRequirement.subTypeDescription | replace("-", "–") if pssRequirement.subTypeDescription | length) }}
    • + {% endfor %} +
    + {% endset %} + {% set rows = (rows.push({ key: "Status", value: "On post-sentence supervision (PSS)"}), rows)%} + {% set rows = (rows.push({ key: "PSS requirements", value: pssRequirements}), rows)%} + {% endif%} + +
  • + {{ summaryCard( + id, + title, + [{ id: actionId, href: "record/" + order.convictionId, text: "View record", visuallyHidden: "for " + order.sentence.description }], + rows + ) }} +
  • + {% endfor %} +
+
\ No newline at end of file diff --git a/server/views/case-summary/partials/orders-previous/macro.njk b/server/views/case-summary/partials/orders-previous/macro.njk new file mode 100644 index 000000000..0c9082ede --- /dev/null +++ b/server/views/case-summary/partials/orders-previous/macro.njk @@ -0,0 +1,3 @@ +{% macro previousOrdersBlock(orders, limitOrders, moment, displayDateFormat) %} + {%- include "./template.njk" -%} +{% endmacro %} \ No newline at end of file diff --git a/server/views/case-summary/partials/orders-previous/template.njk b/server/views/case-summary/partials/orders-previous/template.njk new file mode 100644 index 000000000..471e4aad0 --- /dev/null +++ b/server/views/case-summary/partials/orders-previous/template.njk @@ -0,0 +1,31 @@ +{% from "components/summary-card/macro.njk" import summaryCard %} + +
+
+

+ Previous orders + ({{ orders | length }}) +

+
    + {% for order in orders.slice(0, limitOrders) %} + {% set id = "previousOrder" + loop.index0%} + {% set actionId = id + "-view"%} + {% set descriptionValue %} +

    {{order.offences[0].description }}

    +

    Started on {{ moment(order.sentence.terminationDate, 'YYYY-MM-DD').format(displayDateFormat) }}

    + {% endset %} +
  • + {{ summaryCard( + id, + order.sentence.description + (' (' + order.sentence.length + ' ' + order.sentence.lengthUnits + ')' if order.sentence.length ), + [{ id: actionId, href: "record/" + order.convictionId, text: "View record", visuallyHidden: "for " + order.sentence.description }], + [{ key: "Description", value: descriptionValue }] + ) }} +
  • + {% endfor %} +
+ {% if orders | length > limitOrders %} + + {% endif %} +
+
\ No newline at end of file diff --git a/server/views/components/active-orders/macro.njk b/server/views/components/active-orders/macro.njk deleted file mode 100644 index 07eece0ad..000000000 --- a/server/views/components/active-orders/macro.njk +++ /dev/null @@ -1,3 +0,0 @@ -{% macro activeOrdersBlock(orders, moment, displayDateFormat, strict) %} - {%- include "./template.njk" -%} -{% endmacro %} diff --git a/server/views/components/active-orders/template.njk b/server/views/components/active-orders/template.njk deleted file mode 100644 index 0566a5760..000000000 --- a/server/views/components/active-orders/template.njk +++ /dev/null @@ -1,162 +0,0 @@ -
-

- Current orders - ({{ orders | length }}) -

- {% if strict %} - {% for order in orders %} -
-
-
- - {{ order.sentence.description + (' (' + order.sentence.length + ' ' + order.sentence.lengthUnits + ')' if order.sentence.length) }} - {% if order.inBreach %} - Breach - {% endif %} - -

{{ order.offences[0].description }}

-

- Started on {{ moment(order.sentence.startDate, 'YYYY-MM-DD').format(displayDateFormat) }} -

- - {% if order.requirements and order.requirements | length %} -

Requirements

- -
    - {%- for requirement in order.requirements %} - {% set category = requirement.requirementTypeMainCategory.description or requirement.adRequirementTypeMainCategory.description %} - {% set subCategory = requirement.requirementTypeSubCategory.description or requirement.adRequirementTypeSubCategory.description %} -
  • - {{ category | replace("-", "–") }} {{ " – " + subCategory if category !== subCategory }} - {{ ' – ' + requirement.length + ' ' + requirement.lengthUnit if requirement.length > 0 }} -
  • - {% endfor %} -
- {% endif %} - - {% if order.custodialType.description === "In Custody" %} -

Status

-

In custody

- {% endif %} - - {% if order.licenceConditions and order.licenceConditions | length %} -

Status

-

On licence

- -

Licence conditions

-
    - {%- for licenceCondition in order.licenceConditions %} -
  • {{ licenceCondition.description }}
  • - {% endfor %} -
- {% endif %} - - {% if order.pssRequirements and order.pssRequirements | length %} -

Status

-

On post-sentence supervision (PSS)

- -

PSS requirements

-
    - {%- for pssRequirement in order.pssRequirements %} -
  • {{ pssRequirement.description + (' – ' + pssRequirement.subTypeDescription | replace("-", "–") if pssRequirement.subTypeDescription | length) }}
  • - {% endfor %} -
- {% endif %} -
-
-
- {% endfor %} - {% else %} -
    - {% for order in orders %} -
  • -
    -
    -

    - {{ order.sentence.description + (' (' + order.sentence.length + ' ' + order.sentence.lengthUnits + ')' if order.sentence.length) }} - {% if order.inBreach %} - Breach - {% endif %} -

    - -
    -
    -
    -
    -
    Description
    -
    -

    {{order.offences[0].description }}

    -

    Started on {{ moment(order.sentence.startDate, 'YYYY-MM-DD').format(displayDateFormat) }}

    -
    -
    - {#
    -
    Started on
    -
    {{ moment(order.sentence.startDate, 'YYYY-MM-DD').format(displayDateFormat) }}
    -
    #} - {% if order.requirements and order.requirements | length %} -
    -
    Requirements
    -
    -
      - {%- for requirement in order.requirements %} - {% set category = requirement.requirementTypeMainCategory.description or requirement.adRequirementTypeMainCategory.description %} - {% set subCategory = requirement.requirementTypeSubCategory.description or requirement.adRequirementTypeSubCategory.description %} -
    • - {{ category | replace("-", "–") }} {{ " – " + subCategory if category !== subCategory }} - {{ ' – ' + requirement.length + ' ' + requirement.lengthUnit if requirement.length > 0 }} -
    • - {% endfor %} -
    -
    -
    - {% endif %} - {% if order.custodialType.description === "In Custody" %} -
    -
    Status
    -
    In custody
    -
    - {% endif %} - {% if order.licenceConditions and order.licenceConditions | length %} -
    -
    Status
    -
    On licence
    -
    -
    -
    Licence conditions
    -
    -
      - {%- for licenceCondition in order.licenceConditions %} -
    • {{ licenceCondition.description }}
    • - {% endfor %} -
    -
    -
    - {% endif %} - {% if order.pssRequirements and order.pssRequirements | length %} -
    -
    Status
    -
    On post-sentence supervision (PSS)
    -
    -
    -
    PSS requirements
    -
    -
      - {%- for pssRequirement in order.pssRequirements %} -
    • {{ pssRequirement.description + (' – ' + pssRequirement.subTypeDescription | replace("-", "–") if pssRequirement.subTypeDescription | length) }}
    • - {% endfor %} -
    -
    -
    - {% endif %} -
    -
    -
    -
  • - {% endfor %} -
- {% endif %} -
\ No newline at end of file diff --git a/server/views/components/summary-card/macro.njk b/server/views/components/summary-card/macro.njk new file mode 100644 index 000000000..805d17277 --- /dev/null +++ b/server/views/components/summary-card/macro.njk @@ -0,0 +1,3 @@ +{% macro summaryCard(id, title, actions, rows) %} + {%- include "./template.njk" -%} +{% endmacro %} \ No newline at end of file diff --git a/server/views/components/summary-card/template.njk b/server/views/components/summary-card/template.njk new file mode 100644 index 000000000..15aa4d228 --- /dev/null +++ b/server/views/components/summary-card/template.njk @@ -0,0 +1,26 @@ +{% from "components/summary-list/macro.njk" import summaryList %} + +
+
+

{{ title | safe }}

+ {% if actions | length %} + + {% endif %} +
+ {% if rows | length %} +
+ {{ summaryList(rows) }} +
+ {% endif %} +
\ No newline at end of file diff --git a/server/views/components/summary-list/macro.njk b/server/views/components/summary-list/macro.njk new file mode 100644 index 000000000..b1743adc2 --- /dev/null +++ b/server/views/components/summary-list/macro.njk @@ -0,0 +1,3 @@ +{% macro summaryList(rows) %} + {%- include "./template.njk" -%} +{% endmacro %} \ No newline at end of file diff --git a/server/views/components/summary-list/template.njk b/server/views/components/summary-list/template.njk new file mode 100644 index 000000000..9789fa6d4 --- /dev/null +++ b/server/views/components/summary-list/template.njk @@ -0,0 +1,8 @@ +
+ {% for row in rows %} +
+
{{ row.key }}
+
{{ row.value | safe }}
+
+ {% endfor %} +
\ No newline at end of file diff --git a/tests/routes/handlers/getProbationRecordRouteHandler.test.js b/tests/routes/handlers/getProbationRecordRouteHandler.test.js index 7ceaf8314..83d688f58 100644 --- a/tests/routes/handlers/getProbationRecordRouteHandler.test.js +++ b/tests/routes/handlers/getProbationRecordRouteHandler.test.js @@ -47,7 +47,7 @@ describe('getProbationRecordRouteHandler', () => { // Then expect(getCaseAndTemplateValuesMock).toHaveBeenLastCalledWith(mockRequest) expect(communityServiceMock.getProbationRecord).toHaveBeenLastCalledWith(testCase.crn, true) - expect(mockResponse.render).toHaveBeenCalledWith('case-summary-record', { + expect(mockResponse.render).toHaveBeenCalledWith('case-summary/case-summary-record', { ...testTemplateValues, params: { ...testTemplateValues.params, showAllPreviousOrders: true }, data: { ...testTemplateValues.data, communityData: testCommunityResponse },