generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bob Meredith
committed
Jan 16, 2025
1 parent
0a74d35
commit 74ad06c
Showing
21 changed files
with
558 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.prev-next { | ||
font-weight: bold; | ||
margin-bottom: govuk-spacing(3); | ||
|
||
.prev-next--prev { | ||
margin-right: govuk-spacing(3); | ||
|
||
&::before { | ||
content: "\2190"; | ||
margin-right: govuk-spacing(2); | ||
font-size:30px; | ||
} | ||
} | ||
|
||
.prev-next--next::after { | ||
content: "\2192"; | ||
margin-left: govuk-spacing(2); | ||
|
||
font-size:30px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Cas1PremisesBasicSummary, Cas1PremisesDaySummary } from '@approved-premises/api' | ||
import Page from '../page' | ||
import { DateFormats } from '../../../server/utils/dateUtils' | ||
import paths from '../../../server/paths/manage' | ||
import { daySummaryRows, generateDaySummaryText } from '../../../server/utils/premises/occupancy' | ||
|
||
export default class OccupancyDayViewPage extends Page { | ||
constructor(private pageTitle: string) { | ||
super(pageTitle) | ||
} | ||
|
||
static visit(premises: Cas1PremisesBasicSummary, date: string): OccupancyDayViewPage { | ||
cy.visit(paths.premises.occupancy.day({ premisesId: premises.id, date })) | ||
return new OccupancyDayViewPage(DateFormats.isoDateToUIDate(date)) | ||
} | ||
|
||
shouldShowDaySummaryDetails(premisesDaySummary: Cas1PremisesDaySummary) { | ||
this.shouldContainSummaryListItems(daySummaryRows(premisesDaySummary).rows) | ||
} | ||
|
||
shouldShowDaySummaryWarningContent(premisesDaySummary: Cas1PremisesDaySummary) { | ||
const warningContent = generateDaySummaryText(premisesDaySummary.capacity.characteristicAvailability) | ||
if (warningContent) { | ||
this.shouldShowBanner(warningContent) | ||
} | ||
} | ||
|
||
shouldNavigateToDay(linkLabel: string, date: string) { | ||
cy.contains(linkLabel).click() | ||
cy.get('h1').contains(DateFormats.isoDateToUIDate(date)) | ||
} | ||
|
||
static visitUnauthorised(premises: Cas1PremisesBasicSummary, date: string): OccupancyDayViewPage { | ||
cy.visit(paths.premises.occupancy.day({ premisesId: premises.id, date }), { | ||
failOnStatusCode: false, | ||
}) | ||
return new OccupancyDayViewPage(`Authorisation Error`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { faker } from '@faker-js/faker' | ||
import { addDays } from 'date-fns' | ||
import { cas1PremisesBasicSummaryFactory, cas1PremisesDaySummaryFactory } from '../../../server/testutils/factories' | ||
|
||
import { signIn } from '../signIn' | ||
import { DateFormats } from '../../../server/utils/dateUtils' | ||
import OccupancyDayViewPage from '../../pages/manage/occupancyDayView' | ||
|
||
context('Premises day occupancy', () => { | ||
describe('day', () => { | ||
const dateObj = faker.date.soon() | ||
const date = DateFormats.dateObjToIsoDate(dateObj) | ||
|
||
const premisesDaySummary = cas1PremisesDaySummaryFactory.build({ forDate: date }) | ||
const premises = cas1PremisesBasicSummaryFactory.build() | ||
|
||
beforeEach(() => { | ||
cy.task('reset') | ||
|
||
// Given there is a premises in the database | ||
cy.task('stubSinglePremises', premises) | ||
cy.task('stubPremiseDaySummary', { premisesId: premises.id, date, premisesDaySummary }) | ||
}) | ||
|
||
describe('with premises view permission', () => { | ||
beforeEach(() => { | ||
// Given I am logged in as a future manager with premises_view permission | ||
signIn(['future_manager'], ['cas1_premises_view']) | ||
}) | ||
|
||
it('should show the day summary', () => { | ||
// When I visit premises day summary page | ||
const summaryPage = OccupancyDayViewPage.visit(premises, date) | ||
// I should see the occupancy summary for the day | ||
summaryPage.shouldShowDaySummaryDetails(premisesDaySummary) | ||
// And I should see a warning banner | ||
summaryPage.shouldShowDaySummaryWarningContent(premisesDaySummary) | ||
}) | ||
|
||
it('should allow navigation to the next day and back again', () => { | ||
const nextDate = DateFormats.dateObjToIsoDate(addDays(dateObj, 1)) | ||
const premisesNextDaySummary = cas1PremisesDaySummaryFactory.build({ forDate: nextDate }) | ||
cy.task('stubPremiseDaySummary', { | ||
premisesId: premises.id, | ||
date: nextDate, | ||
premisesDaySummary: premisesNextDaySummary, | ||
}) | ||
// Given I visit premises day summary page | ||
const summaryPage = OccupancyDayViewPage.visit(premises, date) | ||
// When I click on Next day, Then I navigate to the next day | ||
summaryPage.shouldNavigateToDay('Next day', nextDate) | ||
// When I click on Previous day, Then I navigate back to the date I started on | ||
summaryPage.shouldNavigateToDay('Previous day', date) | ||
}) | ||
}) | ||
|
||
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 | ||
OccupancyDayViewPage.visitUnauthorised(premises, date) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.