Skip to content

Commit

Permalink
Man 274 improve page titles (#292)
Browse files Browse the repository at this point in the history
* MAN-274 improve page titles wip

* MAN-274 add unit test for make page title utility function

* MAN-274 iterate page title for appointments page

* MAN-274 fix failing int test
  • Loading branch information
neil-mills authored Jan 30, 2025
1 parent a612fd5 commit 1478c21
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 25 deletions.
2 changes: 2 additions & 0 deletions server/baseController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Request, Response, NextFunction } from 'express'
import config from './config'
import { defaultName } from './utils/azureAppInsights'
import { makePageTitle } from './utils/utils'

const baseController = () => {
return (req: Request, res: Response, next: NextFunction): void => {
Expand All @@ -10,6 +11,7 @@ const baseController = () => {
res.locals.home = url.length === 0
res.locals.cases = url[0] === 'case'
res.locals.search = url[0] === 'search'
res.locals.makePageTitle = makePageTitle
return next()
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/middleware/validation/activityLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import properties from '../../properties'
import utils from '../../utils'
import { toCamelCase } from '../../utils/utils'

const activityLog: Route<void> = (req, res, next) => {
const activityLog: Route<void> = (req, res, next): void => {
const { dateFrom: dateFromQuery, dateTo: dateToQuery } = req.query
const dateFrom = dateFromQuery as string
const dateTo = dateToQuery as string
Expand Down Expand Up @@ -57,7 +57,7 @@ const activityLog: Route<void> = (req, res, next) => {
}
}

const dateIsValid = (dateName: string) => req?.query?.[dateName] && isValid[dateName]
const dateIsValid = (dateName: string): boolean => req?.query?.[dateName] && isValid[dateName]

const validateDateRanges = (): void => {
isValidDateFormat('date-from', dateFrom)
Expand Down
18 changes: 18 additions & 0 deletions server/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import {
timeFromTo,
toYesNo,
yearsSince,
makePageTitle,
} from './utils'
import { RiskResponse, RiskScore, RiskToSelf } from '../data/arnsApiClient'
import { Name } from '../data/model/common'
import { Activity } from '../data/model/schedule'
import { RecentlyViewedCase, UserAccess } from '../data/model/caseAccess'
import config from '../config'

const appointments = [
{
Expand Down Expand Up @@ -487,3 +489,19 @@ describe('update lao access in local storage', () => {
expect(result[0].limitedAccess).toEqual(expected)
})
})

describe('makePageTitle()', () => {
it('should format the title correctly if heading is a single string value', () => {
expect(makePageTitle({ pageHeading: 'Home' })).toEqual(`Home - ${config.applicationName}`)
})
it('should format the title correctly if heading is an array containing two values', () => {
expect(makePageTitle({ pageHeading: ['Contact', 'Personal details'] })).toEqual(
`Contact - Personal details - ${config.applicationName}`,
)
})
it('should format the title correctly if heading is an array containing three values', () => {
expect(makePageTitle({ pageHeading: ['Contact', 'Sentence', 'Licence condition'] })).toEqual(
`Contact - Sentence - Licence condition - ${config.applicationName}`,
)
})
})
6 changes: 4 additions & 2 deletions server/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,10 @@ export const hasValue = (val: unknown) => {
return isNotNull(val) && isDefined(val)
}

export const makePageTitle = ({ pageHeading, hasErrors }: { pageHeading: string; hasErrors: boolean }) =>
`${hasErrors ? 'Error: ' : ''}${pageHeading} - ${config.applicationName}`
export const makePageTitle = ({ pageHeading }: { pageHeading: string | string[] }): string => {
const titles = !Array.isArray(pageHeading) ? [pageHeading] : pageHeading
return `${titles.join(' - ')} - ${config.applicationName}`
}

export const getDataValue = (data: any, sections: any) => {
const path = Array.isArray(sections) ? sections : [sections]
Expand Down
2 changes: 1 addition & 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 = applicationName + " - Activity log" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Activity log"] }) %}
{% set currentNavSection = 'timeline' %}
{% set currentSectionName = 'Activity log' %}
{% set headerPersonName = personActivity.personSummary.name.forename + ' ' + personActivity.personSummary.name.surname %}
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 = applicationName + " - Appointments" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "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 extraBreadcrumb = '?' + queryParams.join('&') if queryParams.length > 0 else '' %}
{% set category = '/' + category + '/' + extraBreadcrumb if category else extraBreadcrumb %}

Expand Down
1 change: 1 addition & 0 deletions server/views/pages/appointments/record-an-outcome.njk
Original file line number Diff line number Diff line change
@@ -1,6 +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 action = '/case/' + crn + '/record-an-outcome/' + actionType %}
{% set backLink = '/case/' + crn %}
{% block form %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/caseload/minimal-cases.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set hasCases = caseload.caseload | length > 0 %}
{% set hasStaff = caseload !== null %}
{% set title = 'My cases' %}
{% block pageTitle %}{{ title }}{% endblock %}
{% set pageTitle = makePageTitle({ pageHeading: "My cases" }) %}

{% block pageContent %}
{% if currentNavSection == 'teamCases' and caseload.team %}
Expand Down
4 changes: 1 addition & 3 deletions server/views/pages/compliance.njk
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{% extends "../partials/case.njk" %}
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}
{% set pageTitle = applicationName + " - Compliance" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Compliance"] }) %}
{% set currentSectionName = 'Compliance' %}
{% set title = 'Compliance' %}
{% set currentNavSection = 'compliance' %}
{% set headerPersonName = personCompliance.personSummary.name | fullName %}
{% set headerCRN = personCompliance.personSummary.crn %}
{% set headerDob = personCompliance.personSummary.dateOfBirth %}
{% set headerGender = personCompliance.personSummary.gender %}
{% block pageTitle %}{{ title }}{% endblock %}

{% block beforeContent %}
{{ govukBreadcrumbs({
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/error.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../partials/layout.njk" %}

{% set pageTitle = applicationName + " - Error" %}
{% set pageTitle = "Error" + applicationName %}
{% set mainClasses = "app-container govuk-body" %}

{% block content %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/handoff/delius.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../../partials/layout.njk" %}
{% set title = 'Continue on National Delius' %}
{% block pageTitle %}{{ title }}{% endblock %}
{% set pageTitle = makePageTitle({ pageHeading: "Continue on National Delius" }) %}

{% block beforeContent %}
{{ govukBreadcrumbs({
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/index.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../partials/layout.njk" %}

{% set pageTitle = applicationName + " - Home" %}
{% set pageTitle = makePageTitle({ pageHeading: "Home" }) %}
{% set mainClasses = "app-container govuk-body" %}

{% block content %}
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 = applicationName + " - Interventions" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "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 = applicationName + " - Sentence Details" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "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 = applicationName + " - Overview" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "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 = applicationName + " - Personal Details" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Personal details"] }) %}
{% set currentNavSection = 'personal-details' %}
{% set currentSectionName = 'Personal Details' %}
{% set headerPersonName = personalDetails.name.forename + ' ' + personalDetails.name.surname %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/circumstances.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "../../partials/layout.njk" %}
{% set title = 'Personal circumstances' %}
{% block pageTitle %}{{ title }}{% endblock %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Personal details", "Personal circumstances"] }) %}

{% block beforeContent %}
{{ govukBreadcrumbs({
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/probation-history.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "../partials/case.njk" %}
{% set pageTitle = applicationName + " - Sentence Details" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Sentence", "Probation history"] }) %}
{% set currentNavSection = 'sentence' %}
{% set currentSectionName = 'Sentence' %}
{% set headerPersonName = sentenceDetails.personSummary.name.forename + ' ' + sentenceDetails.personSummary.name.surname %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/requirement-note.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "../partials/case.njk" %}
{% set pageTitle = applicationName + " - Sentence Details" %}
{% set pageTitle = makePageTitle({ pageHeading: "Sentence details" }) %}
{% set currentNavSection = 'sentence' %}
{% set currentSectionName = 'Sentence' %}
{% set headerPersonName = requirementNoteDetails.personSummary.name.forename + ' ' + requirementNoteDetails.personSummary.name.surname %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/risk.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% from "../_components/predictor-score/macro.njk" import predictorScore %}
{% from "../_components/predictor-timeline-item/macro.njk" import predictorTimelineItem %}

{% set pageTitle = applicationName + " - Risk" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact" ,"Risk"] }) %}
{% set currentNavSection = 'risk' %}
{% set currentSectionName = 'Risk' %}
{% set headerPersonName = personRisk.personSummary.name | fullName %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/search.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
{% from "probation/case-search/macro.njk" import caseSearch %}

{% set pageTitle = applicationName + " - Search" %}
{% set pageTitle = makePageTitle({ pageHeading: "Search" }) %}
{% set mainClasses = "app-container govuk-body" %}

{% block content %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/sentence.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "../partials/case.njk" %}
{% set pageTitle = applicationName + " - Sentence" %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Sentence"] }) %}
{% set currentNavSection = 'sentence' %}
{% set currentSectionName = 'Sentence' %}
{% set headerPersonName = sentenceDetails.personSummary.name.forename + ' ' + sentenceDetails.personSummary.name.surname %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/sentence/offences.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "../../partials/layout.njk" %}
{% set title = 'Offences' %}
{% set headerPersonName = offences.name.forename + ' ' + offences.name.surname %}

{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Sentence", "Offences"] }) %}
{% block beforeContent %}
{{ govukBreadcrumbs({
items: [
Expand Down
1 change: 1 addition & 0 deletions server/views/pages/sentence/previous-orders.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "../../partials/layout.njk" %}
{% set headerPersonName = previousOrderHistory.name.forename + ' ' + previousOrderHistory.name.surname %}
{% set pageTitle = makePageTitle({ pageHeading: ["Contact", "Sentence", "Previous orders"] }) %}

{% block beforeContent %}
{{ govukBreadcrumbs({
Expand Down

0 comments on commit 1478c21

Please sign in to comment.