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.
Commit integration tests.
- Loading branch information
Showing
6 changed files
with
167 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Cas1PremiseCapacityForDay, Cas1SpaceBookingCharacteristic } from '@approved-premises/api' | ||
import Page from '../page' | ||
import { dayAvailabilityCount, occupancyCriteriaMap } from '../../../server/utils/match/occupancy' | ||
import { DateFormats } from '../../../server/utils/dateUtils' | ||
|
||
type Availability = 'Available' | 'Overbooked' | 'Available for your criteria' | ||
|
||
export default class DayAvailabilityPage extends Page { | ||
availability: Availability | ||
|
||
constructor( | ||
private readonly dayCapacity: Cas1PremiseCapacityForDay, | ||
private readonly criteria: Array<Cas1SpaceBookingCharacteristic> = [], | ||
) { | ||
let availability: Availability = dayAvailabilityCount(dayCapacity) > 0 ? 'Available' : 'Overbooked' | ||
|
||
if (criteria.length) { | ||
if (dayAvailabilityCount(dayCapacity, criteria) > 0 && availability === 'Overbooked') { | ||
availability = 'Available for your criteria' | ||
} | ||
} | ||
|
||
super(availability) | ||
|
||
this.availability = availability | ||
} | ||
|
||
shouldShowDayAvailability() { | ||
const uiDate = DateFormats.isoDateToUIDate(this.dayCapacity.date, { format: 'long' }) | ||
cy.get('h2').should('contain.text', uiDate) | ||
|
||
if (this.availability === 'Available') { | ||
cy.get('p').should('contain.text', 'The space you require is available.') | ||
} else if (this.availability === 'Overbooked') { | ||
cy.get('p').should('contain.text', 'This AP is full or overbooked. The space you require is not available.') | ||
} else if (this.availability === 'Available for your criteria') { | ||
cy.get('p').should( | ||
'contain.text', | ||
'This AP is full or overbooked, but the space you require is available as it is occupied by someone who does not need it.', | ||
) | ||
} | ||
|
||
const summaryList = { | ||
'AP capacity': this.dayCapacity.totalBedCount, | ||
'Booked spaces': this.dayCapacity.bookingCount, | ||
} | ||
|
||
if (this.criteria.length) { | ||
this.criteria.forEach(criteria => { | ||
const criteriaLabel = occupancyCriteriaMap[criteria] | ||
const criteriaAvailability = this.dayCapacity.characteristicAvailability.find( | ||
characteristic => characteristic.characteristic === criteria, | ||
) | ||
summaryList[`${criteriaLabel} spaces available`] = | ||
criteriaAvailability.availableBedsCount - criteriaAvailability.bookingsCount | ||
}) | ||
} else { | ||
summaryList['Available spaces'] = dayAvailabilityCount(this.dayCapacity) | ||
} | ||
this.shouldContainAvailabilitySummary(summaryList) | ||
} | ||
|
||
shouldContainAvailabilitySummary(items: Record<string, string | number>) { | ||
Object.entries(items).forEach(([key, value]) => { | ||
cy.get('.govuk-summary-list__key') | ||
.contains(key) | ||
.siblings('.govuk-summary-list__value') | ||
.should('contain.text', value) | ||
}) | ||
} | ||
} |
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
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
34 changes: 30 additions & 4 deletions
34
server/views/match/placementRequests/occupancyView/viewDay.njk
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 |
---|---|---|
@@ -1,13 +1,39 @@ | ||
{% from "govuk/components/back-link/macro.njk" import govukBackLink %} | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
|
||
{% extends "../../layout-with-details.njk" %} | ||
|
||
{% set pageTitle = applicationName + " - " + pageHeading %} | ||
|
||
{% block beforeContent %} | ||
{{ govukBackLink({ | ||
text: "Back", | ||
href: backlink | ||
}) }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1 class="govuk-heading-l">{{ pageHeading }}</h1> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l">{{ pageHeading }}</h1> | ||
|
||
{{ govukSummaryList({ | ||
rows: availabilitySummaryListItems | ||
}) }} | ||
<h2 class="govuk-heading-m">{{ formatDate(date) }}</h2> | ||
|
||
{% if status === 'available' %} | ||
<p>The space you require is available.</p> | ||
{% endif %} | ||
{% if status === 'availableForCriteria' %} | ||
<p>This AP is full or overbooked, but the space you require is available as it is occupied by someone | ||
who does not need it.</p> | ||
{% endif %} | ||
{% if status === 'overbooked' %} | ||
<p>This AP is full or overbooked. The space you require is not available.</p> | ||
{% endif %} | ||
|
||
{{ govukSummaryList({ | ||
rows: availabilitySummaryListItems | ||
}) }} | ||
|
||
</div> | ||
</div> | ||
{% endblock %} |