Skip to content

Commit

Permalink
Add test case for bed details page when nullable details are null
Browse files Browse the repository at this point in the history
Some of the fields can be undefined. In order to test that our template
is flexible enough to handle these undefined fields we should write a
test that proves it.
  • Loading branch information
rich committed Jul 8, 2024
1 parent 21f9e8b commit b446ccd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export class OutOfServiceBedShowPage extends Page {

shouldShowOutOfServiceBedDetail(): void {
const latestRevision = this.outOfServiceBed.revisionHistory[0]
this.assertDefinition('Start date', DateFormats.isoDateToUIDate(latestRevision.startDate, { format: 'long' }))
this.assertDefinition('End date', DateFormats.isoDateToUIDate(latestRevision.endDate, { format: 'long' }))
this.assertDefinition('Reason', latestRevision.reason.name)
this.assertDefinition('Reference number', latestRevision.referenceNumber)
this.assertDefinition('Additional information', latestRevision.notes)

if (latestRevision.startDate) {
this.assertDefinition('Start date', DateFormats.isoDateToUIDate(latestRevision.startDate, { format: 'long' }))
}
if (latestRevision.endDate) {
this.assertDefinition('End date', DateFormats.isoDateToUIDate(latestRevision.endDate, { format: 'long' }))
}
if (latestRevision.reason) this.assertDefinition('Reason', latestRevision.reason.name)
if (latestRevision.referenceNumber) this.assertDefinition('Reference number', latestRevision.referenceNumber)
if (latestRevision.notes) this.assertDefinition('Additional information', latestRevision.notes)
}

shouldShowCharacteristics(bed: BedDetail): void {
Expand Down
81 changes: 60 additions & 21 deletions integration_tests/tests/v2Manage/outOfServiceBeds.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
bookingFactory,
extendedPremisesSummaryFactory,
outOfServiceBedFactory,
outOfServiceBedRevisionFactory,
premisesFactory,
} from '../../../server/testutils/factories'
import { sortOutOfServiceBedRevisionsByUpdatedAt } from '../../../server/utils/outOfServiceBedUtils'
Expand Down Expand Up @@ -113,34 +114,72 @@ context('OutOfServiceBeds', () => {
page.shouldShowDateConflictErrorMessages(conflictingBooking, 'booking')
})

it('should show a out of service bed', () => {
// Given I am signed in as a future manager
signIn(['future_manager'])
describe('for a new out of service bed with all nullable fields present in the initial OoS bed revision', () => {
it('should show a out of service bed', () => {
// Given I am signed in as a future manager
signIn(['future_manager'])

// And I have created a out of service bed
const bed = { name: 'abc', id: '123' }
const premises = premisesFactory.build()
const outOfServiceBed = outOfServiceBedFactory.build({ bed })
outOfServiceBed.revisionHistory = sortOutOfServiceBedRevisionsByUpdatedAt(outOfServiceBed.revisionHistory)
const bedDetail = bedDetailFactory.build({ id: bed.id })
// And I have created a out of service bed
const bed = { name: 'abc', id: '123' }
const premises = premisesFactory.build()
const outOfServiceBed = outOfServiceBedFactory.build({ bed })
outOfServiceBed.revisionHistory = sortOutOfServiceBedRevisionsByUpdatedAt(outOfServiceBed.revisionHistory)
const bedDetail = bedDetailFactory.build({ id: bed.id })

cy.task('stubOutOfServiceBed', { premisesId: premises.id, outOfServiceBed })
cy.task('stubBed', { premisesId: premises.id, bedDetail })
cy.task('stubOutOfServiceBed', { premisesId: premises.id, outOfServiceBed })
cy.task('stubBed', { premisesId: premises.id, bedDetail })

// And I visit that out of service bed's show page
const page = OutOfServiceBedShowPage.visit(premises.id, outOfServiceBed)
// And I visit that out of service bed's show page
const page = OutOfServiceBedShowPage.visit(premises.id, outOfServiceBed)

// Then I should see the latest details of that out of service bed
page.shouldShowOutOfServiceBedDetail()
// Then I should see the latest details of that out of service bed
page.shouldShowOutOfServiceBedDetail()

// And I should see the bed characteristics
page.shouldShowCharacteristics(bedDetail)
// And I should see the bed characteristics
page.shouldShowCharacteristics(bedDetail)

// When I click the 'Timeline' tab
page.clickTab('Timeline')
// When I click the 'Timeline' tab
page.clickTab('Timeline')

// Then I should see the timeline of that out of service bed's revision
page.shouldShowTimeline()
// Then I should see the timeline of that out of service bed's revision
page.shouldShowTimeline()
})
})

describe('for a legacy "lost bed" records migrated with all nullable fields not present in the initial OoS bed revision', () => {
it('should show a out of service bed', () => {
// Given I am signed in as a future manager
signIn(['future_manager'])

// And I have created a out of service bed
const bed = { name: 'abc', id: '123' }
const premises = premisesFactory.build()
const outOfServiceBedRevision = outOfServiceBedRevisionFactory.build({
updatedBy: undefined,
startDate: undefined,
endDate: undefined,
reason: undefined,
referenceNumber: undefined,
notes: undefined,
})
const outOfServiceBed = outOfServiceBedFactory.build({
bed,
revisionHistory: [outOfServiceBedRevision],
})
const bedDetail = bedDetailFactory.build({ id: bed.id })

cy.task('stubOutOfServiceBed', { premisesId: premises.id, outOfServiceBed })
cy.task('stubBed', { premisesId: premises.id, bedDetail })

// And I visit that out of service bed's show page
const page = OutOfServiceBedShowPage.visit(premises.id, outOfServiceBed)

// When I click the 'Timeline' tab
page.clickTab('Timeline')

// Then I should see the timeline of that out of service bed's revision
page.shouldShowTimeline()
})
})

describe('CRU Member lists all OOS beds', () => {
Expand Down
13 changes: 8 additions & 5 deletions server/views/v2Manage/outOfServiceBeds/partials/_bedDetails.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
{% endfor %}
</ul>
{%endset%}

{% set latestRevision = outOfServiceBed.revisionHistory[0] %}

{{
govukSummaryList({
rows: [
Expand All @@ -16,39 +19,39 @@
text: "Start date"
},
value: {
text: formatDate(outOfServiceBed.revisionHistory[0].startDate, {format: 'long'})
text: formatDate(latestRevision.startDate, {format: 'long'}) if latestRevision.startDate else "None supplied"
}
},
{
key: {
text: "End date"
},
value: {
text: formatDate(outOfServiceBed.revisionHistory[0].endDate, {format: 'long'})
text: formatDate(latestRevision.endDate, {format: 'long'}) if latestRevision.startDate else "None supplied"
}
},
{
key: {
text: "Reason"
},
value: {
text: outOfServiceBed.revisionHistory[0].reason.name
text: latestRevision.reason.name if latestRevision.reason.name else "None supplied"
}
},
{
key: {
text: "Reference number"
},
value: {
text: outOfServiceBed.revisionHistory[0].referenceNumber
text: latestRevision.referenceNumber if latestRevision.referenceNumber else "None supplied"
}
},
{
key: {
text: "Additional information"
},
value: {
text: outOfServiceBed.revisionHistory[0].notes
text: latestRevision.notes if latestRevision.notes else "None supplied"
}
},
{
Expand Down

0 comments on commit b446ccd

Please sign in to comment.