From a612fd55c5dde7b766f59f7dfd6be465eea2daaa Mon Sep 17 00:00:00 2001 From: Neil Mills <35219002+neil-mills@users.noreply.github.com> Date: Wed, 29 Jan 2025 12:57:23 +0000 Subject: [PATCH] MAN-270 update primary nav links, add tests (#291) --- integration_tests/e2e/myCases.cy.ts | 7 +++++++ integration_tests/e2e/search.cy.ts | 15 +++++++++++++++ integration_tests/pages/page.ts | 2 ++ integration_tests/pages/search.ts | 7 +++++++ server/baseController.ts | 6 +++++- server/views/pages/search.njk | 9 ++++++++- server/views/partials/header.njk | 7 +++++-- 7 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 integration_tests/e2e/search.cy.ts create mode 100644 integration_tests/pages/search.ts diff --git a/integration_tests/e2e/myCases.cy.ts b/integration_tests/e2e/myCases.cy.ts index 74679d66..e695201f 100644 --- a/integration_tests/e2e/myCases.cy.ts +++ b/integration_tests/e2e/myCases.cy.ts @@ -12,5 +12,12 @@ context('My cases', () => { page.getRowData('myCases', 'nameOrCrn', 'Value4').should('contain.text', 'X808126') page.getRowData('myCases', 'dob', 'Value4').should('contain.text', 'Restricted') page.getPagination().should('contain.text', 'Showing 1 to 10 of 33 cases.') + + page.getNavigationLink(1).should('contain.text', 'Home') + page.getNavigationLink(1).should('not.have.attr', 'aria-current', 'home') + page.getNavigationLink(2).should('contain.text', 'Cases') + page.getNavigationLink(2).should('have.attr', 'aria-current', 'cases') + page.getNavigationLink(3).should('contain.text', 'Search') + page.getNavigationLink(3).should('not.have.attr', 'aria-current', 'search') }) }) diff --git a/integration_tests/e2e/search.cy.ts b/integration_tests/e2e/search.cy.ts new file mode 100644 index 00000000..2f933e7c --- /dev/null +++ b/integration_tests/e2e/search.cy.ts @@ -0,0 +1,15 @@ +import Page from '../pages/page' +import SearchPage from '../pages/search' + +context('Search', () => { + it('Search page is rendered', () => { + cy.visit('/search') + const page = Page.verifyOnPage(SearchPage) + page.getNavigationLink(1).should('contain.text', 'Home') + page.getNavigationLink(1).should('not.have.attr', 'aria-current', 'home') + page.getNavigationLink(2).should('contain.text', 'Cases') + page.getNavigationLink(2).should('not.have.attr', 'aria-current', 'cases') + page.getNavigationLink(3).should('contain.text', 'Search') + page.getNavigationLink(3).should('have.attr', 'aria-current', 'search') + }) +}) diff --git a/integration_tests/pages/page.ts b/integration_tests/pages/page.ts index c1900a80..5c5b01bd 100644 --- a/integration_tests/pages/page.ts +++ b/integration_tests/pages/page.ts @@ -23,6 +23,8 @@ export default abstract class Page { pageHeading = (): PageElement => cy.get('[data-qa=pageHeading]') + getNavigationLink = (index: number): PageElement => cy.get(`.moj-primary-navigation__list li:nth-of-type(${index}) a`) + getTab = (tabName: string): PageElement => cy.get(`[data-qa=${tabName}Tab]`) getCardHeader = (cardName: string): PageElement => diff --git a/integration_tests/pages/search.ts b/integration_tests/pages/search.ts new file mode 100644 index 00000000..71e55a0a --- /dev/null +++ b/integration_tests/pages/search.ts @@ -0,0 +1,7 @@ +import Page from './page' + +export default class SearchPage extends Page { + constructor() { + super('Find a person on probation') + } +} diff --git a/server/baseController.ts b/server/baseController.ts index f76de2eb..876a9468 100644 --- a/server/baseController.ts +++ b/server/baseController.ts @@ -3,9 +3,13 @@ import config from './config' import { defaultName } from './utils/azureAppInsights' const baseController = () => { - return (_req: Request, res: Response, next: NextFunction): void => { + return (req: Request, res: Response, next: NextFunction): void => { res.locals.applicationInsightsConnectionString = config.apis.appInsights.connectionString res.locals.applicationInsightsRoleName = defaultName() + const url = req.url.split('/').filter(dir => dir) + res.locals.home = url.length === 0 + res.locals.cases = url[0] === 'case' + res.locals.search = url[0] === 'search' return next() } } diff --git a/server/views/pages/search.njk b/server/views/pages/search.njk index 1d6bde60..ce831236 100644 --- a/server/views/pages/search.njk +++ b/server/views/pages/search.njk @@ -6,5 +6,12 @@ {% set mainClasses = "app-container govuk-body" %} {% block content %} - {{ caseSearch({ id: "search", results: searchResults }) }} + {{ caseSearch({ + id: "search", + results: searchResults, + label: { + html: '
' + } + }) }} {% endblock %} + diff --git a/server/views/partials/header.njk b/server/views/partials/header.njk index 35edb559..7cbd2cea 100644 --- a/server/views/partials/header.njk +++ b/server/views/partials/header.njk @@ -52,10 +52,13 @@