diff --git a/integration-tests/cypress/e2e/case-summary.feature b/integration-tests/cypress/e2e/case-summary.feature index d93a65943..c85a846c7 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/case-summary.steps.js b/integration-tests/cypress/e2e/case-summary/case-summary.steps.js index a858afe0d..e44410894 100644 --- a/integration-tests/cypress/e2e/case-summary/case-summary.steps.js +++ b/integration-tests/cypress/e2e/case-summary/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/public/src/stylesheets/app/_summary-list.scss b/public/src/stylesheets/app/_summary-list.scss new file mode 100644 index 000000000..cbf05cdab --- /dev/null +++ b/public/src/stylesheets/app/_summary-list.scss @@ -0,0 +1,4 @@ +.pac-list--none { + padding-left: 0; + list-style-type: none; +} \ 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 4c5e47e50..00a0a15bd 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -479,7 +479,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) }) ) @@ -512,7 +512,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) }) ) @@ -542,7 +542,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) }) ) @@ -563,7 +563,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 92f5a1f48..e745a5c59 100644 --- a/server/views/case-summary-record.njk +++ b/server/views/case-summary/case-summary-record.njk @@ -1,5 +1,8 @@ {% extends "partials/case-details.njk" %} +{% from "./partials/orders-active/macro.njk" import activeOrdersBlock %} +{% from "./partials/orders-previous/macro.njk" import previousOrdersBlock %} + {%- set moment = params.moment -%} {%- set communityData = data.communityData -%} {%- set psrRequestedConvictions = data.psrRequestedConvictions -%} @@ -107,108 +110,17 @@ {% endif %} {% if activeOrders | length %} -
- {{ 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 %} -In custody
- {% endif %} - - {% if order.licenceConditions and order.licenceConditions | length %} -On licence
- -On post-sentence supervision (PSS)
- -{{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 %} +