Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Meredith committed Dec 24, 2024
1 parent 7c0a7ee commit db3c4fd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
13 changes: 10 additions & 3 deletions integration_tests/pages/manage/occupancyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { DateFormats, daysToWeeksAndDays } from '../../../server/utils/dateUtils
import paths from '../../../server/paths/manage'

export default class OccupancyViewPage extends Page {
constructor(private readonly premises: Cas1PremisesSummary) {
super(`View spaces in ${premises.name}`)
constructor(private pageTitle: string) {
super(pageTitle)
}

static visit(premises: Cas1PremisesSummary): OccupancyViewPage {
cy.visit(paths.premises.occupancy.view({ premisesId: premises.id }))
return new OccupancyViewPage(premises)
return new OccupancyViewPage(`View spaces in ${premises.name}`)
}

static visitUnauthorised(premises: Cas1PremisesSummary): OccupancyViewPage {
cy.visit(paths.premises.occupancy.view({ premisesId: premises.id }), {
failOnStatusCode: false,
})
return new OccupancyViewPage(`Authorisation Error`)
}

shouldShowCalendarHeading(startDate: string, durationDays: number): void {
Expand Down
11 changes: 10 additions & 1 deletion integration_tests/tests/manage/occupancyView.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ context('Premises occupancy', () => {
// And I click the action link view spaces
page.clickAction('View spaces')
// Then I should navigate to the occupancy view
const occPage = Page.verifyOnPage(OccupancyViewPage, premises)
const occPage = Page.verifyOnPage(OccupancyViewPage, `View spaces in ${premises.name}`)
occPage.shouldShowCalendarHeading(startDate, DateFormats.differenceInDays(endDateObj, startDateObj).number)
occPage.shouldShowCalendar(premisesCapacity)
})
Expand Down Expand Up @@ -148,5 +148,14 @@ context('Premises occupancy', () => {
page.actionShouldNotExist('View spaces')
})
})
describe('Without premises view permission', () => {
it('should not be availble if the user lacks premises_view permission', () => {
// Given I am logged in as a future manager without premises_view permission
signIn(['future_manager'])
// When I navigate to the view premises occupancy page
// Then I should see an error
OccupancyViewPage.visitUnauthorised(premises)
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('AP occupancyViewController', () => {
expect(response.render).toHaveBeenCalledWith(
'manage/premises/occupancy/view',
expect.objectContaining({
pageHeading: `View spaces in ${premisesSummary.name}`,
calendarHeading: 'Showing 12 weeks from 1 Jan 2024',
premises: premisesSummary,
backLink: paths.premises.show({ premisesId }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class ApOccupancyViewController {
}
const calendarHeading = `Showing ${DateFormats.formatDuration(daysToWeeksAndDays(String(durationDays)))} from ${DateFormats.isoDateToUIDate(startDate, { format: 'short' })}`
return res.render('manage/premises/occupancy/view', {
pageHeading: `View spaces in ${premises.name}`,
premises,
calendar,
backLink: paths.premises.show({ premisesId }),
Expand Down
5 changes: 4 additions & 1 deletion server/routes/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ export default function routes(controllers: Controllers, router: Router, service
})

// Occupancy
get(paths.premises.occupancy.view.pattern, apOccupancyViewController.view())
get(paths.premises.occupancy.view.pattern, apOccupancyViewController.view(), {
auditEvent: 'VIEW_OCCUPANCY',
allowedPermissions: ['cas1_premises_view'],
})

// Bookings
get(paths.bookings.show.pattern, bookingsController.show(), {
Expand Down
4 changes: 2 additions & 2 deletions server/views/manage/premises/occupancy/view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{% extends "../../../partials/layout.njk" %}

{% set pageTitle = applicationName + " - " + premises.name %}
{% set pageTitle = applicationName + " - " + pageHeading %}
{% set mainClasses = "app-container govuk-body" %}

{% block beforeContent %}
Expand All @@ -28,7 +28,7 @@
{% block content %}
{{ showErrorSummary(errorSummary) }}
<span class="govuk-caption-l">{{ premises.name }}</span>
<h1 class="govuk-heading-l">View spaces in {{ premises.name }}</h1>
<h1 class="govuk-heading-l">{{ pageHeading }}</h1>

<div class="search-and-filter">
<form action="{{ selfPath }}"
Expand Down

0 comments on commit db3c4fd

Please sign in to comment.