Skip to content

Commit

Permalink
MAN-287 update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Feb 6, 2025
2 parents b14d881 + afb9afd commit f6dce84
Show file tree
Hide file tree
Showing 29 changed files with 146 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-zap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
java-version: 17

- name: Get ZAP version
id: latest
Expand Down
16 changes: 16 additions & 0 deletions integration_tests/e2e/activityLog.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ context('Activity log', () => {
cy.get('.toggle-menu .toggle-menu__list-item:nth-of-type(2) a').should('contain.text', 'Compact view')
cy.get('[data-qa="filter-form"]').within(() => cy.get('h2').should('contain.text', 'Filter activity log'))
page.getApplyFiltersButton().should('contain.text', 'Apply filters')
page.getSelectedFiltersBox().should('not.exist')
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'))
Expand Down Expand Up @@ -159,6 +160,8 @@ context('Activity log', () => {
const page = Page.verifyOnPage(ActivityLogPage)
page.getKeywordsInput().type(value)
page.getApplyFiltersButton().click()
page.getSelectedFiltersBox().find('h2').should('contain.text', 'Selected filters')
page.getSelectedFiltersBox().find('h3:nth-of-type(1)').should('contain.text', 'Search term')
page.getSelectedFilterTags().should('have.length', 1)
page.getSelectedFilterTag(1).should('contain.text', value)
page.getCardHeader('timeline1').should('contain.text', 'Phone call from Eula Schmeler')
Expand All @@ -172,6 +175,7 @@ context('Activity log', () => {
page.getApplyFiltersButton().click()
page.getSelectedFilterTag(1).click()
page.getSelectedFilterTag(1).should('not.exist')
page.getSelectedFiltersBox().should('not.exist')
page.getKeywordsInput().should('have.value', '')
page.getCardHeader('timeline1').should('contain.text', 'Video call')
})
Expand All @@ -183,6 +187,7 @@ context('Activity log', () => {
page.getDateFromInput().type(fromDate)
page.getDateToInput().type(toDate)
page.getApplyFiltersButton().click()
page.getSelectedFiltersBox().find('h3:nth-of-type(1)').should('contain.text', 'Date range')
page.getDateFromInput().should('have.value', fromDate)
page.getDateToInput().should('have.value', toDate)
page.getSelectedFilterTags().should('have.length', 1)
Expand All @@ -202,6 +207,7 @@ context('Activity log', () => {
page.getApplyFiltersButton().click()
page.getSelectedFilterTag(1).click()
page.getSelectedFilterTag(1).should('not.exist')
page.getSelectedFiltersBox().should('not.exist')
page.getDateFromInput().should('have.value', '')
page.getDateToInput().should('have.value', '')
page.getCardHeader('timeline1').should('contain.text', 'Video call')
Expand All @@ -216,6 +222,8 @@ context('Activity log', () => {
page.getComplianceFilter(2).click()
page.getComplianceFilter(3).click()
page.getApplyFiltersButton().click()
page.getSelectedFiltersBox().find('h3:nth-of-type(1)').should('contain.text', 'Compliance filters')
page.getSelectedFiltersBox().should('exist')
page.getComplianceFilter(1).should('be.checked')
page.getComplianceFilter(2).should('be.checked')
page.getComplianceFilter(3).should('be.checked')
Expand Down Expand Up @@ -278,13 +286,17 @@ context('Activity log', () => {
page.getComplianceFilter(2).click()
page.getComplianceFilter(3).click()
page.getApplyFiltersButton().click()
page.getSelectedFiltersBox().find('h3:nth-of-type(1)').should('contain.text', 'Search term')
page.getSelectedFiltersBox().find('h3:nth-of-type(2)').should('contain.text', 'Date range')
page.getSelectedFiltersBox().find('h3:nth-of-type(3)').should('contain.text', 'Compliance filters')
page.getSelectedFilterTags().should('have.length', 5)
page.getCardHeader('timeline1').should('contain.text', 'Phone call from Eula Schmeler')
cy.get('[data-qa="results-count-start"]').should('contain.text', '1')
cy.get('[data-qa="results-count-end"]').should('contain.text', '1')
cy.get('[data-qa="results-count-total"]').should('contain.text', '1')
cy.get('.govuk-pagination').should('not.exist')
cy.get('.moj-filter__heading-action a').click()
page.getSelectedFiltersBox().should('not.exist')
page.getSelectedFilterTags().should('not.exist')
page.getKeywordsInput().should('have.value', '')
page.getDateFromInput().should('have.value', '')
Expand Down Expand Up @@ -459,6 +471,10 @@ context('Activity log', () => {
.getNoResults()
.find('li:nth-of-type(3)')
.should('contain.text', 'removing special characters like characters and accent letters')
page
.getNoResults()
.find('li:nth-of-type(4)')
.should('contain.text', 'using an asterisk (*) to search with a partial keyword, for example app*')
})
it('should persist the selected filters when a pagination link is clicked', () => {
cy.visit('/case/X000001/activity-log')
Expand Down
41 changes: 30 additions & 11 deletions integration_tests/e2e/personalDetails/disabilities.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,42 @@ context('Contact', () => {
it('Contact page is rendered', () => {
cy.visit('/case/X000001/personal-details/disabilities')
const page = Page.verifyOnPage(DisabilitiesPage)
cy.get('p')
.eq(0)
.within(() =>
cy
.get('a')
.invoke('attr', 'href')
.should(
'equal',
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=EqualityMonitoring&CRN=X000001',
),
)
page.assertAnchorElementAtIndexWithin(
'p',
0,
0,
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=EqualityMonitoring&CRN=X000001',
)

page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 0, 'Disability')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 1, 'Start date')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 2, 'Notes')

page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 0, 'Dyslexia')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 1, '3 April 2021')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 2, 'Disability Notes')
})

it('Contact page is rendered', () => {
cy.visit('/case/X000001/personal-details/disability/0/note/0')
const page = Page.verifyOnPage(DisabilitiesPage)
page.assertAnchorElementAtIndexWithin(
'p',
0,
0,
'https://ndelius-dummy-url/NDelius-war/delius/JSP/deeplink.xhtml?component=EqualityMonitoring&CRN=X000001',
)

page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 0, 'Disability')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 1, 'Start date')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 2, 'Note added by')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 3, 'Date added')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__key]', 4, 'Notes')

page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 0, 'Dyslexia')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 1, '3 April 2021')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 2, 'Tom Brady')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 3, '30 October 2024')
page.assertTextAtElementAtIndex('[class=govuk-summary-list__value]', 4, 'Disability Notes')
})
})
7 changes: 5 additions & 2 deletions integration_tests/e2e/risk.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ context('Risk', () => {
it('Risk overview page is rendered', () => {
cy.visit('/case/X000001/risk')
const page = Page.verifyOnPage(RiskPage)
page.getElementData('highScoringNeedsValue').should('contain.text', 'Relationships')
page.getElementData('lowScoringNeedsValue').should('contain.text', 'Accommodation')
page.getElementData('severeScoringNeedsLabel').should('contain.text', 'Severe')
page.getElementData('severeScoringNeedsValue').should('contain.text', 'Relationships')
page.getElementData('standardScoringNeedsLabel').should('contain.text', 'Standard')
page.getElementData('standardScoringNeedsValue').should('contain.text', 'Accommodation')
page.getElementData('noScoreNeedsLabel').should('contain.text', 'Areas without a need score')
page.getElementData('noScoreNeedsValue').should('contain.text', 'Emotional wellbeing')
page.getElementData('mappa-heading').should('contain.text', 'Cat 0/Level 2')
})
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/pages/activityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default class ActivityLogPage extends Page {
super('Activity log')
}

getSelectedFiltersBox = (): PageElement => cy.get('.moj-filter__selected')

getApplyFiltersButton = (): PageElement => cy.get('[data-qa="submit-button"]')

getKeywordsInput = (): PageElement => cy.get('[data-qa="keywords"] input')
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/pages/personalDetails/disability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Page from '../page'

export default class DisabilityPage extends Page {
constructor() {
super('Disabilities')
}
}
2 changes: 1 addition & 1 deletion server/@types/ActivityLog.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface SelectedFilterItem {

export interface ActivityLogFiltersResponse extends ActivityLogFilters {
errors: Errors
selectedFilterItems: SelectedFilterItem[]
selectedFilterItems: Record<string, SelectedFilterItem[]>
complianceOptions: Option[]
baseUrl: string
queryStr: string
Expand Down
45 changes: 18 additions & 27 deletions server/middleware/filterActivityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const filterActivityLog: Route<void> = (req, res, next) => {
}
return acc
}, '')

return queryStr
}

Expand All @@ -73,38 +72,30 @@ export const filterActivityLog: Route<void> = (req, res, next) => {
? `${baseUrl}?${queryStr}&clearFilterKey=${key}&clearFilterValue=${encodeURI(value)}`
: `${baseUrl}?clearFilterKey=${key}&clearFilterValue=${encodeURI(value)}`

const selectedFilterItems: SelectedFilterItem[] = Object.entries(filters)
const selectedFilterItems: Record<string, SelectedFilterItem[]> = Object.entries(filters)
.filter(([_key, value]) => value)
.reduce((acc, [key, value]) => {
if (Array.isArray(value)) {
for (const text of value) {
acc = [
...acc,
{
text: complianceFilterOptions.find(option => option.value === text).text,
href: filterHref(key, text),
},
]
.reduce((acc, [filterKey, filterValue]) => {
let value: string | SelectedFilterItem[] = null
if (Array.isArray(filterValue)) {
value = []
for (const text of filterValue) {
value.push({
text: complianceFilterOptions.find(option => option.value === text).text,
href: filterHref(filterKey, text),
})
}
} else if (key !== 'dateTo') {
let text = value
let cfKey = key
if (key === 'dateFrom') {
text = value && filters.dateTo ? `${value} - ${filters.dateTo}` : ''
cfKey = 'dateRange'
} else if (filterKey !== 'dateTo') {
let text = filterValue
if (filterKey === 'dateFrom') {
text = filterValue && filters.dateTo ? `${filterValue} - ${filters.dateTo}` : ''
filterKey = 'dateRange'
}
if (text) {
acc = [
...acc,
{
text,
href: filterHref(cfKey, value),
},
]
value = [{ text, href: filterHref(filterKey, filterValue) }]
}
}
return acc
}, [])
return filterKey !== 'dateTo' ? { ...acc, [filterKey]: value } : acc
}, {})

const complianceOptions: Option[] = complianceFilterOptions.map(({ text, value }) => ({
text,
Expand Down
2 changes: 1 addition & 1 deletion server/middleware/getPersonActivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('/middleware/getPersonActivity', () => {
...filterVals,
complianceOptions: [],
errors: null,
selectedFilterItems: [],
selectedFilterItems: {},
baseUrl: '',
query: { ...filterVals },
queryStr: '',
Expand Down
3 changes: 2 additions & 1 deletion server/views/pages/activity-log.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "../partials/case.njk" %}
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}
{% from "govuk/components/pagination/macro.njk" import govukPagination %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Activity log"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: "Activity log" }) %}
{% set currentNavSection = 'timeline' %}
{% set currentSectionName = 'Activity log' %}
{% set headerPersonName = personActivity.personSummary.name.forename + ' ' + personActivity.personSummary.name.surname %}
Expand Down Expand Up @@ -109,6 +109,7 @@
<li>removing filters</li>
<li>double-checking the spelling</li>
<li>removing special characters like characters and accent letters</li>
<li>using an asterisk (*) to search with a partial keyword, for example app*</li>
</ul>
</div>
{% endif %}
Expand Down
40 changes: 32 additions & 8 deletions server/views/pages/activity-log/_filters.njk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@

{% endset -%}

{% set filterCategories = [] %}
{% if filters.selectedFilterItems.keywords.length %}
{% set filterCategories = (filterCategories.push(
{
heading: {
text: 'Search term'
},
items: filters.selectedFilterItems.keywords
}), filterCategories) %}
{% endif %}
{% if filters.selectedFilterItems.dateRange.length %}
{% set filterCategories = (filterCategories.push(
{
heading: {
text: 'Date range'
},
items: filters.selectedFilterItems.dateRange
}), filterCategories) %}
{% endif %}
{% if filters.selectedFilterItems.compliance.length %}
{% set filterCategories = (filterCategories.push(
{
heading: {
text: 'Compliance filters'
},
items: filters.selectedFilterItems.compliance
}), filterCategories) %}
{% endif %}

<div class="govuk-grid-column-one-third">
<form method="get" data-qa="filter-form">
{{ mojFilter({
Expand All @@ -94,19 +123,14 @@
},
selectedFilters: {
heading: {
html: '<span class="govuk-heading-s">Selected filters</span>',
classes: 'govuk-heading-s'
html: '<span class="govuk-heading-m">Selected filters</span>'
},
clearLink: {
text: 'Clear filters',
href: '/case/' + crn + '/activity-log'
},
categories: [
{
items: filters.selectedFilterItems
}
]
} if filters.selectedFilterItems.length,
categories: filterCategories
} if filters.selectedFilterItems.keywords.length or filters.selectedFilterItems.dateRange.length or filters.selectedFilterItems.compliance.length,
optionsHtml: filterOptionsHtml
}) }}
<input type="hidden" name="submit" value="true">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/appointments.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "../partials/case.njk" %}
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}
{% from "moj/components/button-menu/macro.njk" import mojButtonMenu %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Appointments"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: "Appointments" }) %}
{% set currentNavSection = 'appointments' %}
{% set headerPersonName = upcomingAppointments.personSummary.name.forename + ' ' + upcomingAppointments.personSummary.name.surname %}
{% set headerCRN = upcomingAppointments.personSummary.crn %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/appointments/appointment.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../../partials/layout.njk" %}
{% set appointment = personAppointment.appointment %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Appointments" if not isActivityLog else "Activity log", appointment.type] }) %}
{% set pageTitle = makePageTitle({ pageHeading: ["Appointments" if not isActivityLog else "Activity log", appointment.type] }) %}
{% set extraBreadcrumb = '?' + queryParams.join('&') if queryParams.length > 0 else '' %}
{% set category = '/' + category + '/' + extraBreadcrumb if category else extraBreadcrumb %}

Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/appointments/record-an-outcome.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "../_form.njk" %}
{% set headerPersonName = schedule.personSummary.name.forename + ' ' + schedule.personSummary.name.surname %}
{% set title = "Which appointment are you recording an outcome for?" if actionType == "outcome" else "Which appointment?" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Record an outcome", "Outcome"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: ["Record an outcome", "Outcome"] }) %}
{% set action = '/case/' + crn + '/record-an-outcome/' + actionType %}
{% set backLink = '/case/' + crn %}
{% block form %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/compliance.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../partials/case.njk" %}
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Compliance"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: "Compliance" }) %}
{% set currentSectionName = 'Compliance' %}
{% set currentNavSection = 'compliance' %}
{% set headerPersonName = personCompliance.personSummary.name | fullName %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/interventions.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "../partials/case.njk" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Interventions"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: "Interventions" }) %}
{% set currentNavSection = 'interventions' %}
{% set currentSectionName = 'Interventions' %}
{% set headerPersonName = personSummary.name.forename + ' ' + personSummary.name.surname %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/licence-condition-note.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "../partials/case.njk" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Sentence", "Licence condition"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: ["Sentence", "Licence condition"] }) %}
{% set currentNavSection = 'sentence' %}
{% set currentSectionName = 'Sentence' %}
{% set headerPersonName = licenceNoteDetails.personSummary.name.forename + ' ' + licenceNoteDetails.personSummary.name.surname %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/overview.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../partials/case.njk" %}
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Overview"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: "Overview" }) %}
{% set currentNavSection = 'overview' %}
{% set currentSectionName = 'Overview' %}
{% set appointmentsWithoutAnOutcomeCount = overview.appointmentsWithoutOutcome %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "../partials/case.njk" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Personal details"] }) %}
{% set pageTitle = makePageTitle({ pageHeading: "Personal details" }) %}
{% set currentNavSection = 'personal-details' %}
{% set currentSectionName = 'Personal details' %}
{% set headerPersonName = personalDetails.name.forename + ' ' + personalDetails.name.surname %}
Expand Down
Loading

0 comments on commit f6dce84

Please sign in to comment.