Skip to content

Commit

Permalink
Occupancy View - add license expiry date to matching details section
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkhawkins committed Dec 30, 2024
1 parent 589a4c0 commit fc9382d
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 60 deletions.
3 changes: 1 addition & 2 deletions integration_tests/pages/match/occupancyViewPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Cas1PremiseCapacity,
Cas1PremisesSummary,
Cas1SpaceBookingCharacteristic,
PlacementRequest,
PlacementRequestDetail,
} from '@approved-premises/api'
import Page from '../page'
Expand Down Expand Up @@ -32,7 +31,7 @@ export default class OccupancyViewPage extends Page {
totalCapacity: number,
startDate: string,
durationDays: number,
placementRequest: PlacementRequest,
placementRequest: PlacementRequestDetail,
managerDetails: string,
) {
cy.get('.govuk-details').within(() => {
Expand Down
25 changes: 21 additions & 4 deletions integration_tests/tests/match/match.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ListPage from '../../pages/admin/placementApplications/listPage'
import { filterOutAPTypes, placementDates } from '../../../server/utils/match'
import BookASpacePage from '../../pages/match/bookASpacePage'
import OccupancyViewPage from '../../pages/match/occupancyViewPage'
import applicationFactory from '../../../server/testutils/factories/application'

context('Placement Requests', () => {
beforeEach(() => {
Expand All @@ -29,6 +30,7 @@ context('Placement Requests', () => {
cy.task('stubAuthUser')
cy.task('stubCruManagementAreaReferenceData')
})
const defaultLicenceExpiryDate = '2030-06-05'

it('allows me to search for an available space', () => {
// Given I am signed in as a cru_member
Expand Down Expand Up @@ -110,7 +112,18 @@ context('Placement Requests', () => {
})

it('allows me to view spaces and occupancy capacity', () => {
const { occupancyViewPage, premiseCapacity } = shouldVisitOccupancyViewPageAndShowMatchingDetails()
const { occupancyViewPage, premiseCapacity } =
shouldVisitOccupancyViewPageAndShowMatchingDetails(defaultLicenceExpiryDate)

// And I should see a summary of occupancy
occupancyViewPage.shouldShowOccupancySummary(premiseCapacity)

// And I should see an occupancy calendar
occupancyViewPage.shouldShowOccupancyCalendar(premiseCapacity)
})

it('allows me to view spaces and occupancy capacity with blank licence expiry date', () => {
const { occupancyViewPage, premiseCapacity } = shouldVisitOccupancyViewPageAndShowMatchingDetails(undefined)

// And I should see a summary of occupancy
occupancyViewPage.shouldShowOccupancySummary(premiseCapacity)
Expand All @@ -120,7 +133,7 @@ context('Placement Requests', () => {
})

it('allows me to submit invalid dates in the book your placement form on occupancy view page and displays appropriate validation messages', () => {
const { occupancyViewPage } = shouldVisitOccupancyViewPageAndShowMatchingDetails()
const { occupancyViewPage } = shouldVisitOccupancyViewPageAndShowMatchingDetails(defaultLicenceExpiryDate)

// When I submit invalid dates
occupancyViewPage.shouldFillBookYourPlacementFormDates('2024-11-25', '2024-11-24')
Expand All @@ -131,7 +144,8 @@ context('Placement Requests', () => {
})

it('allows me to submit valid dates in the book your placement form on occupancy view page and redirects to book a space', () => {
const { occupancyViewPage, placementRequest, premises } = shouldVisitOccupancyViewPageAndShowMatchingDetails()
const { occupancyViewPage, placementRequest, premises } =
shouldVisitOccupancyViewPageAndShowMatchingDetails(defaultLicenceExpiryDate)

// When I submit valid dates
const arrivalDate = '2024-11-25'
Expand All @@ -143,7 +157,7 @@ context('Placement Requests', () => {
bookASpacePage.shouldShowBookingDetails(placementRequest, arrivalDate, 1, 'normal')
})

const shouldVisitOccupancyViewPageAndShowMatchingDetails = () => {
const shouldVisitOccupancyViewPageAndShowMatchingDetails = (licenceExpiryDate: string | undefined) => {
const apType = 'normal'
const durationDays = 15
const startDate = '2024-07-23'
Expand All @@ -161,6 +175,9 @@ context('Placement Requests', () => {
person,
expectedArrival: startDate,
duration: durationDays,
application: applicationFactory.build({
licenceExpiryDate,
}),
})
const premiseCapacity = cas1PremiseCapacityFactory.build({
premise: { id: premises.id, bedCount: totalCapacity, managerDetails },
Expand Down
1 change: 1 addition & 0 deletions server/testutils/factories/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,6 @@ export default ApplicationFactory.define(() => ({
caseManagerIsNotApplicant: faker.datatype.boolean(),
caseManagerUserDetails: applicationUserDetailsFactory.build(),
applicantUserDetails: applicationUserDetailsFactory.build(),
licenceExpiryDate: DateFormats.dateObjToIsoDateTime(faker.date.future()),
...apTypeField(),
}))
140 changes: 87 additions & 53 deletions server/utils/match/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
PlacementCriteria,
} from '@approved-premises/api'
import { when } from 'jest-when'
import type { SummaryListItem } from '@approved-premises/ui'
import paths from '../../paths/match'
import {
personFactory,
Expand Down Expand Up @@ -39,6 +40,7 @@ import {
groupedCriteria,
keyDetails,
lengthOfStayRow,
licenceExpiryDateRow,
mapUiParamsForApi,
occupancyViewLink,
occupancyViewSummaryListForMatchingDetails,
Expand Down Expand Up @@ -67,6 +69,7 @@ import { apTypeLabels } from '../apTypeLabels'
import { textValue } from '../applications/helpers'
import { preferredApsRow } from '../placementRequests/preferredApsRow'
import { placementRequirementsRow } from '../placementRequests/placementRequirementsRow'
import applicationFactory from '../../testutils/factories/application'

jest.mock('../retrieveQuestionResponseFromFormArtifact')

Expand Down Expand Up @@ -388,11 +391,15 @@ describe('matchUtils', () => {
})

describe('occupancyViewSummaryListForMatchingDetails', () => {
const application = applicationFactory.build({
licenceExpiryDate: '2030-11-23',
})
const placementRequest = placementRequestDetailFactory.build({
releaseType: 'hdc',
expectedArrival: '2025-10-02',
duration: 52,
essentialCriteria: ['hasTactileFlooring'],
application,
})
const dates = placementDates(placementRequest.expectedArrival, placementRequest.duration)
const totalCapacity = 120
Expand All @@ -404,73 +411,100 @@ describe('matchUtils', () => {
departureDateRow(dates.endDate),
placementLengthRow(dates.placementLength),
releaseTypeRow(placementRequest),
licenceExpiryDateRow(placementRequest.application as ApprovedPremisesApplication),
totalCapacityRow(totalCapacity),
apManagerDetailsRow(managerDetails),
spaceRequirementsRow(filterOutAPTypes(placementRequest.essentialCriteria)),
])
})

it('should generate the expected matching details', () => {
expect(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest, managerDetails)).toEqual([
{
key: {
text: 'Expected arrival date',
},
value: {
text: 'Thu 2 Oct 2025',
},
expect(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest, managerDetails)).toEqual(
expectedMatchingDetailsSummaryListItems(application.licenceExpiryDate),
)
})

it(`should generate the expected matching details with blank licence expiry date when application's license-expiry date is not set`, () => {
const placementRequestWithoutLicenceExpiry = {
...placementRequest,
application: applicationFactory.build({
licenceExpiryDate: undefined,
}),
}
expect(
occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequestWithoutLicenceExpiry, managerDetails),
).toEqual(expectedMatchingDetailsSummaryListItems(''))
})
})

const expectedMatchingDetailsSummaryListItems = (expectedLicenceExpiryDate: string): Array<SummaryListItem> => {
return [
{
key: {
text: 'Expected arrival date',
},
{
key: {
text: 'Expected departure date',
},
value: {
text: 'Sun 23 Nov 2025',
},
value: {
text: 'Thu 2 Oct 2025',
},
{
key: {
text: 'Placement length',
},
value: {
text: '7 weeks, 3 days',
},
},
{
key: {
text: 'Expected departure date',
},
{
key: {
text: 'Release type',
},
value: {
text: 'Home detention curfew (HDC)',
},
value: {
text: 'Sun 23 Nov 2025',
},
{
key: {
text: 'Total capacity',
},
value: {
text: '120 spaces',
},
},
{
key: {
text: 'Placement length',
},
{
key: {
text: 'AP manager details',
},
value: {
text: 'John Doe',
},
value: {
text: '7 weeks, 3 days',
},
{
key: {
text: 'Space requirements',
},
value: {
html: '<ul class="govuk-list"><li>Tactile flooring</li></ul>',
},
},
{
key: {
text: 'Release type',
},
])
})
})
value: {
text: 'Home detention curfew (HDC)',
},
},
{
key: {
text: 'Licence expiry date',
},
value: {
text: expectedLicenceExpiryDate ? DateFormats.isoDateToUIDate(expectedLicenceExpiryDate) : '',
},
},
{
key: {
text: 'Total capacity',
},
value: {
text: '120 spaces',
},
},
{
key: {
text: 'AP manager details',
},
value: {
text: 'John Doe',
},
},
{
key: {
text: 'Space requirements',
},
value: {
html: '<ul class="govuk-list"><li>Tactile flooring</li></ul>',
},
},
]
}

describe('spaceBookingPremisesSummaryCardRows', () => {
it('should call the correct row functions', () => {
Expand Down
14 changes: 13 additions & 1 deletion server/utils/match/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { addDays } from 'date-fns'
import type {
ApType,
ApprovedPremisesApplication,
Cas1SpaceCharacteristic,
Gender,
PlacementCriteria,
Expand Down Expand Up @@ -174,17 +175,19 @@ export const spaceBookingPersonNeedsSummaryCardRows = (

export const occupancyViewSummaryListForMatchingDetails = (
totalCapacity: number,
placementRequest: PlacementRequest,
placementRequest: PlacementRequestDetail,
managerDetails: string,
): Array<SummaryListItem> => {
const placementRequestDates = placementDates(placementRequest.expectedArrival, placementRequest.duration)
const essentialCharacteristics = filterOutAPTypes(placementRequest.essentialCriteria)
const application = placementRequest.application as ApprovedPremisesApplication

return [
arrivalDateRow(placementRequestDates.startDate),
departureDateRow(placementRequestDates.endDate),
placementLengthRow(placementRequestDates.placementLength),
releaseTypeRow(placementRequest),
licenceExpiryDateRow(application),
totalCapacityRow(totalCapacity),
apManagerDetailsRow(managerDetails),
spaceRequirementsRow(essentialCharacteristics),
Expand Down Expand Up @@ -363,6 +366,15 @@ export const releaseTypeRow = (placementRequest: PlacementRequest) => ({
},
})

export const licenceExpiryDateRow = (application: ApprovedPremisesApplication) => ({
key: {
text: 'Licence expiry date',
},
value: {
text: application.licenceExpiryDate ? DateFormats.isoDateToUIDate(application.licenceExpiryDate) : '',
},
})

export const startDateObjFromParams = (params: { startDate: string } | ObjectWithDateParts<'startDate'>) => {
if (params['startDate-day'] && params['startDate-month'] && params['startDate-year']) {
return {
Expand Down

0 comments on commit fc9382d

Please sign in to comment.