diff --git a/packages/client/src/utils/draftUtils.test.ts b/packages/client/src/utils/draftUtils.test.ts index b7be4734d51..0f3012f4201 100644 --- a/packages/client/src/utils/draftUtils.test.ts +++ b/packages/client/src/utils/draftUtils.test.ts @@ -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( { @@ -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( { @@ -95,9 +118,9 @@ describe('draftUtils tests', () => { savedOn: 1558037863335, modifiedOn: 1558037867987 }, - 'bn' + intlEngish ) - ).toBe('মুশ্রাফুল হক') + ).toBe('Hoque Mushraful') }) }) }) diff --git a/packages/client/src/utils/draftUtils.ts b/packages/client/src/utils/draftUtils.ts index 481c7c59564..10058046659 100644 --- a/packages/client/src/utils/draftUtils.ts +++ b/packages/client/src/utils/draftUtils.ts @@ -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: diff --git a/packages/client/src/views/OfficeHome/inProgress/inProgress.test.tsx b/packages/client/src/views/OfficeHome/inProgress/inProgress.test.tsx index 33b8b91e638..1032651d0a4 100644 --- a/packages/client/src/views/OfficeHome/inProgress/inProgress.test.tsx +++ b/packages/client/src/views/OfficeHome/inProgress/inProgress.test.tsx @@ -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() diff --git a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx index c5b909a69b7..866a5b9cf85 100644 --- a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx +++ b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx @@ -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 diff --git a/packages/client/src/views/RecordAudit/RecordAudit.test.tsx b/packages/client/src/views/RecordAudit/RecordAudit.test.tsx index 78eff975f4f..c3c88638a07 100644 --- a/packages/client/src/views/RecordAudit/RecordAudit.test.tsx +++ b/packages/client/src/views/RecordAudit/RecordAudit.test.tsx @@ -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 diff --git a/packages/client/src/views/RecordAudit/RecordAudit.tsx b/packages/client/src/views/RecordAudit/RecordAudit.tsx index 3b19ab2d0ae..560b773455e 100644 --- a/packages/client/src/views/RecordAudit/RecordAudit.tsx +++ b/packages/client/src/views/RecordAudit/RecordAudit.tsx @@ -555,7 +555,7 @@ const BodyContent = ({ assignment: data.fetchRegistration?.registration?.assignment } } else { - declaration = getGQLDeclaration(data.fetchRegistration, language) + declaration = getGQLDeclaration(data.fetchRegistration, intl) } return ( @@ -592,7 +592,7 @@ const BodyContent = ({ } : getWQDeclarationData( workqueueDeclaration as NonNullable, - language, + intl, trackingId ) const wqStatus = workqueueDeclaration?.registration diff --git a/packages/client/src/views/RecordAudit/utils.ts b/packages/client/src/views/RecordAudit/utils.ts index 3fcff98f333..1ca6e32a83d 100644 --- a/packages/client/src/views/RecordAudit/utils.ts +++ b/packages/client/src/views/RecordAudit/utils.ts @@ -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 { formatLongDate } from '@client/utils/date-formatting' import { IDynamicValues } from '@client/navigation' import { countryMessages } from '@client/i18n/messages/constants' @@ -374,7 +374,7 @@ export const getDraftDeclarationData = ( export const getWQDeclarationData = ( workqueueDeclaration: GQLEventSearchSet, - language: string, + intl: IntlShape, trackingId: string ) => { let name = EMPTY_STRING @@ -382,19 +382,35 @@ export const getWQDeclarationData = ( 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 @@ -417,25 +433,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 } diff --git a/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx b/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx index 08ccebc578e..902f30d036b 100644 --- a/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx +++ b/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx @@ -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 () => { diff --git a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx index c2406b6b80d..467a90dff6c 100644 --- a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx +++ b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx @@ -1699,11 +1699,7 @@ class ReviewSectionComp extends React.Component { '') 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(