Skip to content

Commit

Permalink
MAN-82 filter menu integration tests + bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-mills committed Jan 27, 2025
1 parent da4cd78 commit 48b1666
Show file tree
Hide file tree
Showing 9 changed files with 865 additions and 30 deletions.
351 changes: 338 additions & 13 deletions integration_tests/e2e/activityLog.cy.ts

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion integration_tests/pages/activityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ export default class ActivityLogPage extends Page {

getDateToDialog = (): PageElement => cy.get('[data-qa="date-to"] .moj-datepicker__dialog')

getSelectedFilterTags = (): PageElement => cy.get('.moj-filter__tag')

getSelectedFilterTag = (index: number) => cy.get(`.moj-filter-tags li:nth-of-type(${index}) a`)

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})`)
getComplianceFilter = (index: number): PageElement =>
cy.get(`[data-qa="compliance"] .govuk-checkboxes__item:nth-of-type(${index}) input`)

getPaginationLink = (index: number): PageElement => cy.get(`.govuk-pagination li:nth-of-type(${index}) a`)

getPaginationItem = (index: number): PageElement => cy.get(`.govuk-pagination li:nth-of-type(${index})`)

getTimelineCard = (index: number): PageElement => cy.get(`.app-summary-card:nth-type-of(${index})`)

getNoResults = (): PageElement => cy.get('[data-qa="no-results"]')
}
14 changes: 7 additions & 7 deletions server/middleware/filterActivityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export const filterActivityLog: Route<void> = (req, res, next) => {
if (compliance?.length && clearFilterKey === 'compliance') {
compliance = compliance.filter(value => value !== clearFilterValue)

Check failure on line 20 in server/middleware/filterActivityLog.ts

View workflow job for this annotation

GitHub Actions / node build / Run the node build

Property 'filter' does not exist on type 'string | string[] | ParsedQs | ParsedQs[]'.

Check failure on line 20 in server/middleware/filterActivityLog.ts

View workflow job for this annotation

GitHub Actions / node build / Run the node build

Parameter 'value' implicitly has an 'any' type.
}

const complianceFilterOptions: Option[] = [
{ text: 'Without an outcome', value: 'no outcome' },
{ text: 'Complied', value: 'complied' },
{ text: 'Not complied', value: 'not complied' },
]
const filters: ActivityLogFilters = {
keywords: keywords && clearFilterKey !== 'keywords' ? (keywords as string) : '',
dateFrom:
Expand Down Expand Up @@ -70,7 +74,7 @@ export const filterActivityLog: Route<void> = (req, res, next) => {
acc = [
...acc,
{
text,
text: complianceFilterOptions.find(option => option.value === text).text,
href: filterHref(key, text),
},
]
Expand All @@ -95,11 +99,7 @@ export const filterActivityLog: Route<void> = (req, res, next) => {
return acc
}, [])

const complianceOptions: Option[] = [
{ text: 'Without an outcome', value: 'no outcome' },
{ text: 'Complied', value: 'complied' },
{ text: 'Not complied', value: 'not complied' },
].map(({ text, value }) => ({
const complianceOptions: Option[] = complianceFilterOptions.map(({ text, value }) => ({
text,
value,
checked: filters.compliance.includes(value),
Expand Down
1 change: 0 additions & 1 deletion server/properties/errorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const errorMessages: ErrorMessages = {
isNotReal: 'Enter a real date',
isIncomplete: 'Enter a full date, for example 17/5/2024',
isInFuture: 'The to date must be today or in the past',
isBeforeFrom: 'The to date must be on or after the from date',
},
},
},
Expand Down
10 changes: 9 additions & 1 deletion server/routes/activityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function activityLogRoutes(router: Router, { hmppsAuthClient }: S
dateFrom === cacheItem.dateFrom &&
dateTo === cacheItem.dateTo &&
compliance.every(option => cacheItem.compliance.includes(option)) &&
cacheItem.compliance.length === compliance.length &&
parseInt(page as string, 10) === cacheItem.response.page,
)
if (cache) {
Expand Down Expand Up @@ -84,7 +85,12 @@ export default function activityLogRoutes(router: Router, { hmppsAuthClient }: S
}

const queryParams = getQueryString(req.query)

const currentPage = parseInt(page as string, 10)
const resultsStart = currentPage > 0 ? 10 * currentPage + 1 : 1
let resultsEnd = currentPage > 0 ? (currentPage + 1) * 10 : 10
if (personActivity.totalResults >= resultsStart && personActivity.totalResults <= resultsEnd) {
resultsEnd = personActivity.totalResults
}
await auditService.sendAuditMessage({
action: 'VIEW_MAS_ACTIVITY_LOG',
who: res.locals.user.username,
Expand All @@ -103,6 +109,8 @@ export default function activityLogRoutes(router: Router, { hmppsAuthClient }: S
tierCalculation,
url: req.url,
query,
resultsStart,
resultsEnd,
})
},
)
Expand Down
2 changes: 1 addition & 1 deletion server/views/_components/pagination/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

{{ govukPagination({
previous: {
href: url + (currentPage - 1)
href: url + 'page=' + (currentPage - 1)
} if currentPage > 0 and totalPages > 1,
next: {
href: url + 'page=' + (currentPage + 1)
Expand Down
4 changes: 3 additions & 1 deletion server/views/pages/activity-log.njk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{% if personActivity.activities.length %}
<div class="flex flex--space-between">
{% include "./activity-log/_switch-views.njk" %}
<p class="govuk-!-margin-bottom-0">Showing {{ personActivity.activities.length }} result{% if personActivity.activities.length !== 1 %}s{% endif %} of {{ personActivity.totalResults }}</p>
<p class="govuk-!-margin-bottom-0" data-qa="results-count">Showing results {{ resultsStart }} to {{ resultsEnd }} of {{ personActivity.totalResults }}</p>
</div>
{% set entries = activityLog(entries, category or 'all-previous-activity') %}
{% if entries.length > 0 %}
Expand All @@ -101,13 +101,15 @@
</div>
{% endif %}
{% else %}
<div data-qa="no-results">
<h3 class="govuk-heading-s">0 search results found</h3>
<p>Improve your search by:</p>
<ul class="govuk-list govuk-list--bullet">
<li>removing filters</li>
<li>double-checking the spelling</li>
<li>removing special characters like characters and accent letters</li>
</ul>
</div>
{% endif %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/activity-log/_timeline-notes.njk
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{% set notes %}
{% if entry.notes %}
<p class="govuk-!-margin-bottom-0">{{ entry.notes | nl2br | safe }}</p>
<p class="govuk-body-s secondary-text govuk-!-padding-bottom-2">Comment added by {{ entry.lastUpdatedBy.forename }} {{ entry.lastUpdatedBy.surname }} on {{ entry.lastUpdated | dateWithYear }}</p>
<p class="govuk-body-s secondary-text govuk-!-padding-top-2">Comment added by {{ entry.lastUpdatedBy.forename }} {{ entry.lastUpdatedBy.surname }} on {{ entry.lastUpdated | dateWithYear }}</p>
{% endif %}
{% endset %}

Expand Down
Loading

0 comments on commit 48b1666

Please sign in to comment.