Skip to content

Commit

Permalink
CDPS-207: Empty states for address fields (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidatmoj authored Jun 14, 2023
1 parent 89eb3fe commit 05b17a0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
23 changes: 23 additions & 0 deletions server/data/localMockData/addressSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { GovSummaryItem } from '../../interfaces/govSummaryItem'

// eslint-disable-next-line import/prefer-default-export
export const addressSummaryMock: GovSummaryItem[] = [
{
key: { text: 'Address' },
value: { html: 'Flat 7, premises address, street field<br/>Leeds<br/>West Yorkshire<br/>LS1 AAA<br/>England' },
},
{
key: { text: 'Type of address' },
value: { html: 'Discharge - Permanent Housing<br/>HDC Address<br/>Other' },
},
{
key: { text: 'Phone' },
value: { html: '4444555566<br/>0113444444<br/>0113 333444<br/>0800 222333' },
},
{
key: { text: 'Comment' },
value: {
text: 'comment field goes here. comment field goes here. comment field goes here. comment field goes here. comment field goes here. comment field goes here. comment field goes here. comment field goes here. comment field goes here.',
},
},
]
2 changes: 1 addition & 1 deletion server/interfaces/govSummaryItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface GovSummaryItem {
key: { text: string }
value: { text: string }
value: { text?: string; html?: string }
}

export interface GovSummaryGroup {
Expand Down
2 changes: 2 additions & 0 deletions server/interfaces/pages/personalPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Address } from '../address'
import { GovSummaryItem } from '../govSummaryItem'

export interface PersonalDetails {
age: string
Expand Down Expand Up @@ -124,6 +125,7 @@ export interface PersonalPage {
identityNumbers: IdentityNumbers
property: PropertyItem[]
addresses: Addresses
addressSummary: GovSummaryItem[]
nextOfKin: NextOfKin[]
physicalCharacteristics: PhysicalCharacteristics
security: Security
Expand Down
5 changes: 4 additions & 1 deletion server/services/personalPageService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { mockReasonableAdjustments } from '../data/localMockData/reasonableAdjus
import { personalCareNeedsMock } from '../data/localMockData/personalCareNeedsMock'
import { formatDate } from '../utils/dateHelpers'
import { identifiersMock } from '../data/localMockData/identifiersMock'
import { addressSummaryMock } from '../data/localMockData/addressSummary'

describe('PersonalPageService', () => {
let prisonApiClient: PrisonApiClient
Expand Down Expand Up @@ -231,7 +232,7 @@ describe('PersonalPageService', () => {

describe('Addresses', () => {
it('Maps the data from the API for the primary address', async () => {
const { addresses } = await new PersonalPageService(prisonApiClient).get(PrisonerMockDataA)
const { addresses, addressSummary } = await new PersonalPageService(prisonApiClient).get(PrisonerMockDataA)
const expectedAddress = mockAddresses[0]
const expectedPhones = ['4444555566', '0113444444', '0113 333444', '0800 222333']
const expectedTypes = ['Discharge - Permanent Housing', 'HDC Address', 'Other']
Expand All @@ -251,6 +252,8 @@ describe('PersonalPageService', () => {
expect(premise).toEqual(expectedAddress.premise)
expect(street).toEqual(expectedAddress.street)
expect(town).toEqual(expectedAddress.town)

expect(addressSummary).toEqual(addressSummaryMock)
})
})

Expand Down
39 changes: 35 additions & 4 deletions server/services/personalPageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PropertyItem,
} from '../interfaces/pages/personalPage'
import { Prisoner } from '../interfaces/prisoner'
import { formatName, yearsBetweenDateStrings } from '../utils/utils'
import { addressToLines, formatName, yearsBetweenDateStrings } from '../utils/utils'
import { getProfileInformationValue, ProfileInformationType } from '../interfaces/prisonApi/profileInformation'
import {
getOffenderIdentifierValue,
Expand All @@ -26,6 +26,7 @@ import { PropertyContainer } from '../interfaces/prisonApi/propertyContainer'
import { ReferenceCode, ReferenceCodeDomain } from '../interfaces/prisonApi/referenceCode'
import { formatDate } from '../utils/dateHelpers'
import { getMostRecentAddress } from '../utils/getMostRecentAddress'
import { GovSummaryItem } from '../interfaces/govSummaryItem'

export default class PersonalPageService {
private prisonApiClient: PrisonApiClient
Expand All @@ -42,7 +43,7 @@ export default class PersonalPageService {
prisonerDetail,
secondaryLanguages,
property,
addresses,
addressList,
contacts,
healthReferenceCodes,
healthTreatmentReferenceCodes,
Expand All @@ -59,11 +60,14 @@ export default class PersonalPageService {
this.prisonApiClient.getIdentifiers(bookingId),
])

const addresses: Addresses = this.addresses(addressList)

return {
personalDetails: this.personalDetails(prisonerData, inmateDetail, prisonerDetail, secondaryLanguages),
identityNumbers: this.identityNumbers(prisonerData, identifiers),
property: this.property(property),
addresses: this.addresses(addresses),
addresses,
addressSummary: this.addressSummary(addresses),
nextOfKin: await this.nextOfKin(contacts),
physicalCharacteristics: this.physicalCharacteristics(prisonerData, inmateDetail),
security: {
Expand All @@ -80,6 +84,33 @@ export default class PersonalPageService {
}
}

private addressSummary(addresses: Addresses): GovSummaryItem[] {
const addressSummary: GovSummaryItem[] = []

if (addresses) {
addressSummary.push({
key: { text: 'Address' },
value: { html: addressToLines(addresses.address).join('<br/>') },
})
addressSummary.push({
key: { text: 'Type of address' },
value: { html: addresses.addressTypes.join('<br/>') },
})
addressSummary.push({
key: { text: 'Phone' },
value: { html: addresses.phones?.length ? addresses.phones.join('<br/>') : 'Not entered' },
})
if (addresses.comment) {
addressSummary.push({
key: { text: 'Comment' },
value: { text: addresses.comment },
})
}
}

return addressSummary
}

private personalDetails(
prisonerData: Prisoner,
inmateDetail: InmateDetail,
Expand Down Expand Up @@ -183,7 +214,7 @@ export default class PersonalPageService {
return {
isPrimaryAddress: !!mostRecentAddress,
noFixedAddress: mostRecentAddress?.noFixedAddress,
comment: mostRecentAddress?.comment || '',
comment: mostRecentAddress?.comment,
phones: mostRecentAddress?.phones.map(phone => phone.number) || [],
addressTypes:
mostRecentAddress?.addressUsages
Expand Down
24 changes: 1 addition & 23 deletions server/views/partials/personalPage/addresses.njk
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
{% from "../../macros/summaryCardMacro.njk" import summaryCard %}
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}
{% if addresses %}
{% set addressHtml %}
{% for line in addresses.address | addressToLines %}
{{ line }}<br />
{% endfor %}
{% endset %}
{% set phoneHtml %}
{% for number in addresses.phones %}
{{ number }}<br />
{% endfor %}
{% endset %}
{% set addressTypesHtml %}
{% for type in addresses.addressTypes %}
{{ type }}<br />
{% endfor %}
{% endset %}
{% endif %}
{%- call summaryCard({title: "Addresses", id: "addresses"}) -%}
<div class="govuk-grid-row" data-qa="addresses">
<div class="govuk-grid-column-full">
Expand All @@ -25,12 +8,7 @@
{% elseif addresses and addresses.isPrimaryAddress %}
<p class="govuk-body">Primary</p>
{{ govukSummaryList({
rows: [
{ key: { text: "Address"}, value: { html: addressHtml } },
{ key: { text: "Type of address"}, value: { html: addressTypesHtml } },
{ key: { text: "Phone"}, value: { html: phoneHtml } },
{ key: { text: "Comments"}, value: { text: addresses.comment } }
]
rows: addressSummary
}) }}
<p class="govuk-body">Added on <span data-qa="address-added-on">{{ addresses.addedOn | formatDate }}</span></p>
{% elseif addresses and not addresses.isPrimaryAddress %}
Expand Down

0 comments on commit 05b17a0

Please sign in to comment.