Skip to content

Commit

Permalink
Refactor the work queues to use getLocalisedName()
Browse files Browse the repository at this point in the history
We need to update all the places where a citizen's name is being referenced to show it in the format that the country chooses

#6830
  • Loading branch information
Siyasanga committed Nov 14, 2024
1 parent cec5d6a commit b2de8b9
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 59 deletions.
87 changes: 55 additions & 32 deletions packages/client/src/utils/draftUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,49 @@ import type {
GQLBirthEventSearchSet,
GQLDeathEventSearchSet
} from '@client/utils/gateway-deprecated-do-not-use'
import { createIntl, createIntlCache } from 'react-intl'

const cache = createIntlCache()
const intlEngish = createIntl(
{
locale: 'en',
messages: {}
},
cache
)
const intlBangla = createIntl(
{
locale: 'en',
messages: {}
},
cache
)

describe('draftUtils tests', () => {
describe('getDraftInformantFullName()', () => {
describe('Birth event', () => {
it('Returns child english name properly', () => {
expect(
getDeclarationFullName({
id: '7b57d8f9-4d2d-4f12-8d0a-b042fe14f3d4',
data: {
child: {
firstNames: 'মুশ্রাফুল',
familyName: 'হক',
firstNamesEng: 'Mushraful',
familyNameEng: 'Hoque'
}
getDeclarationFullName(
{
id: '7b57d8f9-4d2d-4f12-8d0a-b042fe14f3d4',
data: {
child: {
firstNames: 'মুশ্রাফুল',
familyName: 'হক',
firstNamesEng: 'Mushraful',
familyNameEng: 'Hoque'
}
},
event: Event.Birth,
savedOn: 1558037863335,
modifiedOn: 1558037867987
},
event: Event.Birth,
savedOn: 1558037863335,
modifiedOn: 1558037867987
})
).toBe('Mushraful Hoque')
intlEngish
)
).toBe('Hoque Mushraful')
})
it('Returns child bangla name properly', () => {
it('Returns child English name properly even though localed is Bangla', () => {
expect(
getDeclarationFullName(
{
Expand All @@ -55,30 +75,33 @@ describe('draftUtils tests', () => {
savedOn: 1558037863335,
modifiedOn: 1558037867987
},
'bn'
intlBangla
)
).toBe('হক')
).toBe('Hoque Mushraful')
})
})
describe('Death event', () => {
it('Returns deceased english name properly', () => {
expect(
getDeclarationFullName({
id: '7b57d8f9-4d2d-4f12-8d0a-b042fe14f3d4',
data: {
deceased: {
firstNames: 'মুশ্রাফুল',
familyName: 'হক',
familyNameEng: 'Hoque'
}
getDeclarationFullName(
{
id: '7b57d8f9-4d2d-4f12-8d0a-b042fe14f3d4',
data: {
deceased: {
firstNames: 'মুশ্রাফুল',
familyName: 'হক',
familyNameEng: 'Hoque'
}
},
event: Event.Death,
savedOn: 1558037863335,
modifiedOn: 1558037867987
},
event: Event.Death,
savedOn: 1558037863335,
modifiedOn: 1558037867987
})
intlBangla
)
).toBe('Hoque')
})
it('Returns child bangla name properly', () => {
it('Returns child English name properly even when the current locale is Bangla', () => {
expect(
getDeclarationFullName(
{
Expand All @@ -95,9 +118,9 @@ describe('draftUtils tests', () => {
savedOn: 1558037863335,
modifiedOn: 1558037867987
},
'bn'
intlEngish
)
).toBe('মুশ্রাফুল হক')
).toBe('Hoque Mushraful')
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/utils/draftUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getDeclarationFullName = (
? getLocalisedName(intl, {
firstNames: draft.data.child.firstNamesEng as string,
middleName: draft.data.child.middleNameEng as string,
familyName: draft.data.child.middleNameEng as string
familyName: draft.data.child.familyNameEng as string
})
: EMPTY_STRING
case Event.Death:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('In Progress tab', () => {
const EXPECTED_DATE_OF_REJECTION = formattedDuration(TIME_STAMP)

expect(data[0].id).toBe('e302f7c5-ad87-4117-91c1-35eaf2ea7be8')
expect(data[0].name).toBe('anik hoque')
expect(data[0].name).toBe('hoque anik')
expect(data[0].lastUpdated).toBe(EXPECTED_DATE_OF_REJECTION)
expect(data[0].event).toBe('Birth')
expect(data[0].actions).toBeDefined()
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/views/OfficeHome/outbox/Outbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function Outbox() {

function transformDeclarationsReadyToSend() {
const items = declarations.map((declaration, index) => {
const name = getDeclarationFullName(declaration)
const name = getDeclarationFullName(declaration, intl)
let dateOfEvent
if (declaration.event && declaration.event.toString() === 'birth') {
dateOfEvent = declaration.data?.child?.childBirthDate as string
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/views/RecordAudit/RecordAudit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('Record audit summary for WorkQueue declarations', () => {
component.find({ 'data-testid': 'type-value' }).hostNodes().text()
).toBe('Birth')
expect(component.find('#content-name').hostNodes().text()).toBe(
'Shakib Al Hasan'
'Al Hasan Shakib'
)
expect(
component
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/views/RecordAudit/RecordAudit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ const BodyContent = ({
assignment: data.fetchRegistration?.registration?.assignment
}
} else {
declaration = getGQLDeclaration(data.fetchRegistration, language)
declaration = getGQLDeclaration(data.fetchRegistration, intl)
}

return (
Expand Down Expand Up @@ -592,7 +592,7 @@ const BodyContent = ({
}
: getWQDeclarationData(
workqueueDeclaration as NonNullable<typeof workqueueDeclaration>,
language,
intl,
trackingId
)
const wqStatus = workqueueDeclaration?.registration
Expand Down
69 changes: 54 additions & 15 deletions packages/client/src/views/RecordAudit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
GQLAssignmentData,
GQLMarriageEventSearchSet
} from '@client/utils/gateway-deprecated-do-not-use'
import { createNamesMap } from '@client/utils/data-formatting'
import { createNamesMap, getLocalisedName } from '@client/utils/data-formatting'
import { IDynamicValues } from '@client/navigation'
import { countryMessages } from '@client/i18n/messages/constants'
import {
Expand Down Expand Up @@ -365,27 +365,43 @@ export const getDraftDeclarationData = (

export const getWQDeclarationData = (
workqueueDeclaration: GQLEventSearchSet,
language: string,
intl: IntlShape,
trackingId: string
) => {
let name = EMPTY_STRING
if (
isBirthDeclaration(workqueueDeclaration) &&
workqueueDeclaration.childName
) {
name = getName(workqueueDeclaration.childName, language)
name = getLocalisedName(intl, {
firstNames: workqueueDeclaration.childName[0]?.firstNames,
middleName: workqueueDeclaration.childName[0]?.middleName,
familyName: workqueueDeclaration.childName[0]?.familyName
})
} else if (
isDeathDeclaration(workqueueDeclaration) &&
workqueueDeclaration.deceasedName
) {
name = getName(workqueueDeclaration.deceasedName, language)
name = getLocalisedName(intl, {
firstNames: workqueueDeclaration.deceasedName[0]?.firstNames,
middleName: workqueueDeclaration.deceasedName[0]?.middleName,
familyName: workqueueDeclaration.deceasedName[0]?.familyName
})
} else if (
isMarriageDeclaration(workqueueDeclaration) &&
workqueueDeclaration.brideName &&
workqueueDeclaration.groomName
) {
const groomName = getName(workqueueDeclaration.groomName, language)
const brideName = getName(workqueueDeclaration.brideName, language)
const groomName = getLocalisedName(intl, {
firstNames: workqueueDeclaration.groomName[0]?.firstNames,
middleName: workqueueDeclaration.groomName[0]?.middleName,
familyName: workqueueDeclaration.groomName[0]?.familyName
})
const brideName = getLocalisedName(intl, {
firstNames: workqueueDeclaration.brideName[0]?.firstNames,
middleName: workqueueDeclaration.brideName[0]?.middleName,
familyName: workqueueDeclaration.brideName[0]?.familyName
})

name =
brideName && groomName
Expand All @@ -408,25 +424,48 @@ export const getWQDeclarationData = (

export const getGQLDeclaration = (
data: IGQLDeclaration,
language: string
intl: IntlShape
): IDeclarationData => {
let name = EMPTY_STRING
if (data.child) {
name = data.child.name ? getName(data.child.name, language) : EMPTY_STRING
name = data.child.name
? getLocalisedName(intl, {
firstNames: data.child.name[0]?.firstNames,
middleName: data.child.name[0]?.middleName,
familyName: data.child.name[0]?.familyName
})
: EMPTY_STRING
} else if (data.deceased) {
name = data.deceased.name
? getName(data.deceased.name, language)
? getLocalisedName(intl, {
firstNames: data.deceased.name[0]?.firstNames,
middleName: data.deceased.name[0]?.middleName,
familyName: data.deceased.name[0]?.familyName
})
: EMPTY_STRING
} else if (data.groom || data.bride) {
if (data.groom?.name && data.bride?.name) {
name = `${getName(data.groom.name, language)} & ${getName(
data.bride.name,
language
)}`
name = `${getLocalisedName(intl, {
firstNames: data.groom.name[0]?.firstNames,
middleName: data.groom.name[0]?.middleName,
familyName: data.groom.name[0]?.familyName
})} & ${getLocalisedName(intl, {
firstNames: data.bride.name[0]?.firstNames,
middleName: data.bride.name[0]?.middleName,
familyName: data.bride.name[0]?.firstNames
})}`
} else if (data.groom?.name) {
name = getName(data.groom.name, language)
name = getLocalisedName(intl, {
firstNames: data.groom.name[0]?.firstNames,
middleName: data.groom.name[0]?.middleName,
familyName: data.groom.name[0]?.familyName
})
} else if (data.bride?.name) {
name = getName(data.bride.name, language)
name = getLocalisedName(intl, {
firstNames: data.bride.name[0]?.firstNames,
middleName: data.bride.name[0]?.middleName,
familyName: data.bride.name[0]?.familyName
})
} else {
name = EMPTY_STRING
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('when in device of large viewport', () => {
).toBe('Government of the peoples republic of Bangladesh')
expect(
reviewSectionComponent.find('#review_header_subject').hostNodes().text()
).toBe('Birth Declaration for John Doe')
).toBe('Birth Declaration for Doe John')
})

it('typing additional comments input triggers onchange review form', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1699,11 +1699,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
'') as string
}

const informantName = getDeclarationFullName(
declaration,
intl.locale,
this.isLastNameFirst()
)
const informantName = getDeclarationFullName(declaration, intl)
const draft = this.isDraft()
const transformedSectionData = this.transformSectionData(
formSections.filter(
Expand Down

0 comments on commit b2de8b9

Please sign in to comment.