Skip to content

Commit

Permalink
Replace booking link with a link to referral
Browse files Browse the repository at this point in the history
This is because users will find it more useful to view the referral and understand who the overlapping offender is. Not all overlaps will have a referral as when making a booking Assessor users can decide not to link to a referral depending on how their booking system works locally
  • Loading branch information
aliuk2012 committed Dec 4, 2024
1 parent 224f405 commit 93c5d99
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 38 deletions.
14 changes: 3 additions & 11 deletions cypress_shared/components/bedspaceSearchResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,15 @@ export default class BedspaceSearchResult extends Component {
cy.root().contains(`CRN: ${overlap.crn}`)
cy.root().contains(overlap.days === 1 ? '1 day overlap' : `${overlap.days} days overlap`)
cy.get('a')
.contains('View booking')
.should(
'have.attr',
'href',
paths.bookings.show({
premisesId: this.result.premises.id,
roomId: overlap.roomId,
bookingId: overlap.bookingId,
}),
)
.contains(`View referral for ${overlap.name}`)
.should('have.attr', 'href', paths.assessments.summary({ id: overlap.assessmentId }))
})
})
})
}

clickOverlapLink(crn: string) {
cy.get('summary').contains('Other people staying').click()
cy.get('ul[data-cy-overlaps] > li').find('dd.overlap-details__value').contains(crn).parents('li').find('a').click()
cy.get('ul[data-cy-overlaps]').find('dd.overlap-details__value').contains(crn).parents('li').find('a').click()
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Page from '../../../../cypress_shared/pages/page'
import DashboardPage from '../../../../cypress_shared/pages/temporary-accommodation/dashboardPage'
import AssessmentSummaryPage from '../../../../cypress_shared/pages/assess/summary'
import BedspaceSearchPage from '../../../../cypress_shared/pages/temporary-accommodation/manage/bedspaceSearch'
import BedspaceShowPage from '../../../../cypress_shared/pages/temporary-accommodation/manage/bedspaceShow'
import BookingShowPage from '../../../../cypress_shared/pages/temporary-accommodation/manage/bookingShow'
import { setupTestUser } from '../../../../cypress_shared/utils/setupTestUser'
import {
assessmentFactory,
bedSearchParametersFactory,
bedSearchResultFactory,
bedSearchResultsFactory,
bookingFactory,
overlapFactory,
personFactory,
placeContextFactory,
Expand Down Expand Up @@ -148,7 +148,7 @@ context('Bedspace Search', () => {
Page.verifyOnPage(BedspaceShowPage, premises, room)
})

it('allows me to view an overlapping booking', () => {
it('allows me to view an overlapping offenders referral', () => {
// Given I am signed in
cy.signIn()

Expand All @@ -163,9 +163,7 @@ context('Bedspace Search', () => {
const premises = premisesFactory.build()
const room = roomFactory.build()

const booking = bookingFactory.build({
person,
})
const assessment = assessmentFactory.build({ status: 'closed' })

const results = bedSearchResultsFactory.build({
results: [
Expand All @@ -176,7 +174,7 @@ context('Bedspace Search', () => {
crn: person.crn,
personType: person.type,
roomId: room.id,
bookingId: booking.id,
assessmentId: assessment.id,
days: 5,
sex: person.sex,
}),
Expand All @@ -188,7 +186,7 @@ context('Bedspace Search', () => {
cy.task('stubBedSearch', results)
cy.task('stubSinglePremises', premises)
cy.task('stubSingleRoom', { premisesId: premises.id, room })
cy.task('stubBooking', { premisesId: premises.id, booking })
cy.task('stubFindAssessment', { ...assessment, status: 'closed' })

// And when I fill out the form
const searchParameters = bedSearchParametersFactory.build()
Expand All @@ -199,7 +197,7 @@ context('Bedspace Search', () => {
const postSearchPage = Page.verifyOnPage(BedspaceSearchPage, results)
postSearchPage.clickOverlapLink(room, person.crn)

Page.verifyOnPage(BookingShowPage, premises, room, booking)
Page.verifyOnPage(AssessmentSummaryPage, assessment)
})

it('shows errors when the API returns an error', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import type { BedSearchResult } from './BedSearchResult';
import type { TemporaryAccommodationBedSearchResultOverlap } from './TemporaryAccommodationBedSearchResultOverlap';
export type TemporaryAccommodationBedSearchResult = (BedSearchResult & {
overlaps: Array<TemporaryAccommodationBedSearchResultOverlap>;
overlaps: Array<Omit<TemporaryAccommodationBedSearchResultOverlap, 'bookingId'>>;
});

5 changes: 3 additions & 2 deletions server/testutils/factories/overlap.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { fakerEN_GB as faker } from '@faker-js/faker'
import { Factory } from 'fishery'
import { TemporaryAccommodationBedSearchResultOverlap as Overlap } from '../../@types/shared'
import assessmentFactory from './assessment'
import { fullPersonFactory } from './person'

export default Factory.define<Overlap>(() => ({
export default Factory.define<Omit<Overlap, 'bookingId'>>(() => ({
crn: fullPersonFactory.build().crn,
name: fullPersonFactory.build().name,
sex: fullPersonFactory.build().sex,
roomId: faker.string.uuid(),
personType: fullPersonFactory.build().type,
bookingId: faker.string.uuid(),
assessmentId: assessmentFactory.build().id,
days: faker.number.int({ min: 1, max: 100 }),
}))
29 changes: 23 additions & 6 deletions server/utils/bedspaceSearchResultUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FullPerson, RestrictedPerson, TemporaryAccommodationBedSearchResultOverlap } from '@approved-premises/api'
import {
assessmentFactory,
bedSearchResultFactory,
bookingFactory,
characteristicFactory,
premisesFactory,
restrictedPersonFactory,
Expand Down Expand Up @@ -66,7 +66,8 @@ describe('BedspaceSearchResultUtils', () => {

describe('bedspaceOverlapResult', () => {
let overLapDays: TemporaryAccommodationBedSearchResultOverlap['days']
let overlapResult: Omit<TemporaryAccommodationBedSearchResultOverlap, 'assesmentId'>
let overlapResult: Omit<TemporaryAccommodationBedSearchResultOverlap, 'bookingId'>
let overLapAssessmentId: TemporaryAccommodationBedSearchResultOverlap['assessmentId']
let person: FullPerson | RestrictedPerson

const createOverLapResult = () => {
Expand All @@ -75,14 +76,15 @@ describe('BedspaceSearchResultUtils', () => {
days: overLapDays,
personType: person.type,
roomId: roomFactory.build().id,
bookingId: bookingFactory.build().id,
assessmentId: overLapAssessmentId,
name: person.type === 'FullPerson' ? (person as FullPerson).name : 'Limited access offender',
sex: person.type === 'FullPerson' ? (person as FullPerson).sex : undefined,
}
}

beforeEach(() => {
overLapDays = 8
overLapAssessmentId = assessmentFactory.build().id
person = fullPersonFactory.build()
overlapResult = createOverLapResult()
})
Expand All @@ -93,16 +95,17 @@ describe('BedspaceSearchResultUtils', () => {
overlapDays: '8 days overlap',
personType: 'FullPerson',
roomId: overlapResult.roomId,
bookingId: overlapResult.bookingId,
assessmentId: overlapResult.assessmentId,
displayName: overlapResult.name,
sex: 'Male',
referralNameOrCrn: overlapResult.name,
sex: overlapResult.sex,
})
})

describe('when overlap by 1 day', () => {
beforeEach(() => {
overLapDays = 1
overLapAssessmentId = assessmentFactory.build().id
overlapResult = createOverLapResult()
})

Expand All @@ -115,6 +118,7 @@ describe('BedspaceSearchResultUtils', () => {
beforeEach(() => {
overLapDays = 8
person = restrictedPersonFactory.build()
overLapAssessmentId = assessmentFactory.build().id
overlapResult = createOverLapResult()
})

Expand All @@ -124,10 +128,23 @@ describe('BedspaceSearchResultUtils', () => {
overlapDays: '8 days overlap',
personType: 'RestrictedPerson',
roomId: overlapResult.roomId,
bookingId: overlapResult.bookingId,
referralNameOrCrn: overlapResult.crn,
assessmentId: overlapResult.assessmentId,
displayName: 'Limited access offender',
})
})
})

describe('when no assessment is assigned', () => {
beforeEach(() => {
overLapDays = 1
overLapAssessmentId = undefined
overlapResult = createOverLapResult()
})

it('returns undefined for assessment ID', () => {
expect(bedspaceOverlapResult(overlapResult).assessmentId).toBeUndefined()
})
})
})
})
10 changes: 5 additions & 5 deletions server/utils/bedspaceSearchResultUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ export function bedspaceKeyCharacteristics(result: BedSearchResult): Array<strin
.map(characteristic => characteristic.name)
}

export function bedspaceOverlapResult(
overlapResult: Omit<TemporaryAccommodationBedSearchResultOverlap, 'assesmentId'>,
) {
const { crn, days, roomId, bookingId, personType } = overlapResult
export function bedspaceOverlapResult(overlapResult: Omit<TemporaryAccommodationBedSearchResultOverlap, 'bookingId'>) {
const { crn, days, roomId, personType, assessmentId } = overlapResult
const overlapDays = `${days} ${days === 1 ? 'day' : 'days'} overlap`

const displayName = personType === 'FullPerson' ? overlapResult.name : 'Limited access offender'
const referralNameOrCrn = personType === 'FullPerson' ? overlapResult.name : overlapResult.crn
const sex = personType === 'FullPerson' ? overlapResult.sex : undefined

return {
crn,
overlapDays,
roomId,
bookingId,
personType,
displayName,
referralNameOrCrn,
sex,
assessmentId,
}
}
14 changes: 10 additions & 4 deletions server/views/components/overlap-details/macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
<dd class="overlap-details__value">{{ params.overlap.overlapDays }}</dd>
</div>
</dl>
<a class="govuk-link"
href="{{ addPlaceContext(paths.bookings.show({premisesId: params.premisesId, roomId: params.overlap.roomId, bookingId: params.overlap.bookingId})) }}">
View booking
</a>

{% if params.overlap.assessmentId %}
<a class="govuk-link"
href="{{ addPlaceContext(paths.assessments.summary({ id: params.overlap.assessmentId })) }}">
View referral<span class="govuk-visually-hidden"> for {{ params.overlap.referralNameOrCrn }}</span>
</a>
{% else %}
<p class="govuk-body">No referral found.</p>
{% endif %}

{% endmacro %}

0 comments on commit 93c5d99

Please sign in to comment.