Skip to content

Commit

Permalink
MAN-270 update primary nav links, add tests (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-mills authored Jan 29, 2025
1 parent 82c0d59 commit a612fd5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
7 changes: 7 additions & 0 deletions integration_tests/e2e/myCases.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
15 changes: 15 additions & 0 deletions integration_tests/e2e/search.cy.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
2 changes: 2 additions & 0 deletions integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/pages/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Page from './page'

export default class SearchPage extends Page {
constructor() {
super('Find a person on probation')
}
}
6 changes: 5 additions & 1 deletion server/baseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
9 changes: 8 additions & 1 deletion server/views/pages/search.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@
{% set mainClasses = "app-container govuk-body" %}

{% block content %}
{{ caseSearch({ id: "search", results: searchResults }) }}
{{ caseSearch({
id: "search",
results: searchResults,
label: {
html: '<h1 class="govuk-label-wrapper" data-qa="pageHeading"><label class="govuk-label moj-search__label govuk-label--l" for="search">Find a person on probation</label></h1>'
}
}) }}
{% endblock %}

7 changes: 5 additions & 2 deletions server/views/partials/header.njk
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@
<nav class="moj-primary-navigation" aria-label="Primary navigation">
<ul class="moj-primary-navigation__list">
<li class="moj-primary-navigation__item">
<a class="moj-primary-navigation__link" {% if myCases %}aria-current="cases"{% endif %} href="/case">My cases</a>
<a class="moj-primary-navigation__link" {% if home %}aria-current="home"{% endif %} href="/">Home</a>
</li>
<li class="moj-primary-navigation__item">
<a class="moj-primary-navigation__link" {% if search %}aria-current="page"{% endif %} href="/search">Search</a>
<a class="moj-primary-navigation__link" {% if cases %}aria-current="cases"{% endif %} href="/case">Cases</a>
</li>
<li class="moj-primary-navigation__item">
<a class="moj-primary-navigation__link" {% if search %}aria-current="search"{% endif %} href="/search">Search</a>
</li>
</ul>
</nav>
Expand Down

0 comments on commit a612fd5

Please sign in to comment.