From da4cd78eb32faeea776be65fe2a34fb6e9ffb06c Mon Sep 17 00:00:00 2001 From: Neil Mills Date: Fri, 24 Jan 2025 19:42:33 +0000 Subject: [PATCH] MAN-82 add filter menu integration tests wip --- integration_tests/e2e/activityLog.cy.ts | 74 +++++++++++++++++++ .../e2e/licence-condition-note.cy.ts | 1 + integration_tests/pages/activityLog.ts | 18 +++++ server/views/pages/activity-log/_filters.njk | 24 ++++-- wiremock/mappings/X000001-activity-log.json | 60 +++++++++++++++ 5 files changed, 172 insertions(+), 5 deletions(-) diff --git a/integration_tests/e2e/activityLog.cy.ts b/integration_tests/e2e/activityLog.cy.ts index 822710e2..255e8285 100644 --- a/integration_tests/e2e/activityLog.cy.ts +++ b/integration_tests/e2e/activityLog.cy.ts @@ -1,7 +1,81 @@ import Page from '../pages/page' import ActivityLogPage from '../pages/activityLog' +import errorMessages from '../../server/properties/errorMessages' context('Activity log', () => { + const today = new Date() + const day = today.getDate() + const month = today.getMonth() + 1 + const year = today.getFullYear() + const date = `${day}/${month}/${year}` + + it('should render the filter menu', () => { + cy.visit('/case/X000001/activity-log') + const page = Page.verifyOnPage(ActivityLogPage) + cy.get('[data-qa="filter-form"]').within(() => cy.get('h2').should('contain.text', 'Filter activity log')) + page.getApplyFiltersButton().should('contain.text', 'Apply filters') + cy.get('[data-qa="keywords"]').within(() => cy.get('label').should('contain.text', 'Keywords')) + page.getKeywordsInput().should('exist').should('have.value', '') + cy.get('[data-qa="date-from"]').within(() => cy.get('label').should('contain.text', 'Date from')) + cy.get('[data-qa="date-from"]').within(() => cy.get('input').should('exist').should('have.value', '')) + cy.get('[data-qa="date-to"]').within(() => cy.get('label').should('contain.text', 'Date to')) + cy.get('[data-qa="date-to"]').within(() => cy.get('input').should('exist').should('have.value', '')) + cy.get('[data-qa="compliance"]').within(() => + cy.get('legend').should('exist').should('contain.text', 'Compliance filters'), + ) + const filters = ['Without an outcome', 'Complied', 'Not complied'] + cy.get('[data-qa="compliance"] .govuk-checkboxes__item').each(($el, i) => { + cy.wrap($el).find('input').should('not.be.checked') + cy.wrap($el).find('label').should('contain.text', filters[i]) + }) + }) + it('should show the correct validation if date to is selected, but no date from is selected', () => { + cy.visit('/case/X000001/activity-log') + const page = Page.verifyOnPage(ActivityLogPage) + page.getDateToToggle().click() + page.getDateToDialog().should('be.visible').find(`button[data-testid="${date}"]`).click() + page.getDateToInput().should('have.value', date) + page.getDateToDialog().should('not.be.visible') + page.getApplyFiltersButton().click() + page.getErrorSummaryBox().should('be.visible') + page.getAllErrorSummaryLinks().should('have.length', 1) + page.getErrorSummaryLink(1).should('contain.text', errorMessages['activity-log']['date-from'].errors.isEmpty) + page.getErrorSummaryLink(1).click() + page.getDateFromInput().should('be.focused') + }) + it('should show the correct validation if date from is selected, but no date to is selected', () => { + cy.visit('/case/X000001/activity-log') + const page = Page.verifyOnPage(ActivityLogPage) + page.getDateFromToggle().click() + page.getDateFromDialog().should('be.visible').find(`button[data-testid="${date}"]`).click() + page.getDateFromInput().should('have.value', date) + page.getDateFromDialog().should('not.be.visible') + page.getApplyFiltersButton().click() + page.getErrorSummaryBox().should('be.visible') + page.getAllErrorSummaryLinks().should('have.length', 1) + page.getErrorSummaryLink(1).should('contain.text', errorMessages['activity-log']['date-to'].errors.isEmpty) + page.getErrorSummaryLink(1).click() + page.getDateToInput().should('be.focused') + }) + it('should show the correct validation if an invalid date from is entered', () => { + cy.visit('/case/X000001/activity-log') + const page = Page.verifyOnPage(ActivityLogPage) + page.getDateFromInput().type('01/04/2025') + page.getApplyFiltersButton().click() + page.getErrorSummaryBox().should('be.visible') + page.getAllErrorSummaryLinks().should('have.length', 1) + page.getErrorSummaryLink(1).should('contain.text', errorMessages['activity-log']['date-from'].errors.isInvalid) + }) + // it('should show the correct validation if an invalid date to is entered', () => { + // cy.visit('/case/X000001/activity-log') + // const page = Page.verifyOnPage(ActivityLogPage) + // page.getDateToInput().type('01/04/') + // page.getApplyFiltersButton().click() + // page.getErrorSummaryBox().should('be.visible') + // page.getAllErrorSummaryLinks().should('have.length', 1) + // cy.pause() + // page.getErrorSummaryLink(1).should('contain.text', errorMessages['activity-log']['date-to'].errors.isInvalid) + // }) it('Activity log page is rendered in default view', () => { cy.visit('/case/X000001/activity-log') const page = Page.verifyOnPage(ActivityLogPage) diff --git a/integration_tests/e2e/licence-condition-note.cy.ts b/integration_tests/e2e/licence-condition-note.cy.ts index 3a097829..7877054b 100644 --- a/integration_tests/e2e/licence-condition-note.cy.ts +++ b/integration_tests/e2e/licence-condition-note.cy.ts @@ -8,6 +8,7 @@ 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') cy.get(`[class=app-summary-card__header]`).within(() => diff --git a/integration_tests/pages/activityLog.ts b/integration_tests/pages/activityLog.ts index ac8624fc..438b0401 100644 --- a/integration_tests/pages/activityLog.ts +++ b/integration_tests/pages/activityLog.ts @@ -5,5 +5,23 @@ export default class ActivityLogPage extends Page { super('Activity log') } + getApplyFiltersButton = (): PageElement => cy.get('[data-qa="submit-button"]') + + getKeywordsInput = (): PageElement => cy.get('[data-qa="keywords"] input') + + getDateFromInput = (): PageElement => cy.get('[data-qa="date-from"] input') + + getDateFromToggle = (): PageElement => cy.get('[data-qa="date-from"] .moj-datepicker__toggle') + + getDateFromDialog = (): PageElement => cy.get('[data-qa="date-from"] .moj-datepicker__dialog') + + getDateToInput = (): PageElement => cy.get('[data-qa="date-to"] input') + + getDateToToggle = (): PageElement => cy.get('[data-qa="date-to"] .moj-datepicker__toggle') + + getDateToDialog = (): PageElement => cy.get('[data-qa="date-to"] .moj-datepicker__dialog') + getActivity = (index: string): PageElement => cy.get(`[data-qa=timeline${index}Card]`) + + getComplianceFilter = (index: string): PageElement => cy.get(`[data-qa="compliance"] input:nth-of-type(${index})`) } diff --git a/server/views/pages/activity-log/_filters.njk b/server/views/pages/activity-log/_filters.njk index d99d1d0c..c2386192 100644 --- a/server/views/pages/activity-log/_filters.njk +++ b/server/views/pages/activity-log/_filters.njk @@ -13,7 +13,10 @@ classes: "govuk-label--s govuk-!-font-weight-bold" }, formGroup: { - classes: "govuk-!-margin-bottom-3" + classes: "govuk-!-margin-bottom-3", + attributes: { + 'data-qa': 'keywords' + } }, value: query.keywords }) }} @@ -25,7 +28,10 @@ classes: "govuk-label--s govuk-!-font-weight-bold" }, formGroup: { - classes: "govuk-!-margin-bottom-3" + classes: "govuk-!-margin-bottom-3", + attributes: { + 'data-qa': 'date-from' + } }, value: query.dateFrom, maxDate: filters.maxDate, @@ -41,7 +47,10 @@ classes: "govuk-label--s govuk-!-font-weight-bold" }, formGroup: { - classes: "govuk-!-margin-bottom-3" + classes: "govuk-!-margin-bottom-3", + attributes: { + 'data-qa': 'date-to' + } }, value: query.dateTo, maxDate: filters.maxDate, @@ -59,6 +68,11 @@ classes: 'govuk-fieldset__legend--s' } }, + formGroup: { + attributes: { + 'data-qa': 'compliance' + } + }, items: filters.complianceOptions }) }} @@ -66,7 +80,7 @@ {% endset -%}
-
+ {{ mojFilter({ heading: { html: 'Filter activity log', @@ -75,7 +89,7 @@ submit: { value: "submit", attributes: { - "data-test-id": "submit-button" + "data-qa": "submit-button" } }, selectedFilters: { diff --git a/wiremock/mappings/X000001-activity-log.json b/wiremock/mappings/X000001-activity-log.json index c84acc57..79644aa8 100644 --- a/wiremock/mappings/X000001-activity-log.json +++ b/wiremock/mappings/X000001-activity-log.json @@ -245,6 +245,66 @@ } } }, + { + "request": { + "method": "POST", + "urlPathPattern": "/mas/activity/X000001", + "bodyPatterns": [ + { + "matchesJsonPath": { + "expression": "keywords", + "contains": "Phone call" + } + } + ] + }, + "response": { + "status": 200, + "jsonBody": { + "size": 10, + "page": 0, + "totalResults": 1, + "totalPages": 1, + "personSummary": { + "name": { + "forename": "Eula", + "surname": "Schmeler" + }, + "crn": "X000001", + "dateOfBirth": "1979-08-18" + }, + "activities": [ + { + "id": 11, + "type": "Phone call", + "startDateTime": "2044-12-22T09:15:00.382936Z[Europe/London]", + "endDateTime": "2044-12-22T09:30:00.382936Z[Europe/London]", + "rarToolKit": "Choices and Changes", + "rarCategory": "Stepping Stonessssss", + "isSensitive": false, + "hasOutcome": false, + "wasAbsent": true, + "notes": "Phone call from Stuart to say that he is sorry for not attending. He sounded under the influence of alcohol. He has recently heard that his ex partner is getting remarried and stated that he “went on a bit of a bender” He states that he has not attempted to contact the victim but I will make enquiries with the police to confirm this as given that he is audibly drunk i don't think i can take his word for it. I asked him to come in and see me at 9am in the morning and reiterated that if he turns up drunk I will have to mark that as another failure to comply due to behavioural issues. This will result in him being in breach of his order. I reiterated that up until now he has been doing so well with his probation and it’s really important he remember and make use of all the tools and techniques we had discussed during his RAR sessions.\n\nHe agreed to see me at 9am as his next shift at Timpsons isn’t until the afternoon. He apologized many times for “letting me down” and has confirmed that he has put a reminder on his phone about the meeting.", + "isAppointment": false, + "isCommunication": true, + "isPhoneCallFromPop": true, + "officerName": { + "forename": "Terry", + "surname": "Jones" + }, + "lastUpdated": "2023-03-20", + "lastUpdatedBy": { + "forename": "Paul", + "surname": "Smith" + } + } + ] + }, + "headers": { + "Content-Type": "application/json" + } + } + }, { "request": { "urlPattern": "/mas/schedule/X000001/appointment/11",