diff --git a/packages/client/src/utils/draftUtils.test.ts b/packages/client/src/utils/draftUtils.test.ts index d924be70e3..2f0839a41b 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: EventType.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: EventType.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 0fca96481e..e9b06379a4 100644 --- a/packages/client/src/utils/draftUtils.ts +++ b/packages/client/src/utils/draftUtils.ts @@ -36,7 +36,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 EventType.Death: diff --git a/packages/client/src/views/OfficeHome/inProgress/inProgress.test.tsx b/packages/client/src/views/OfficeHome/inProgress/inProgress.test.tsx index 2cdab6581c..9d016006ad 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 c5b909a69b..866a5b9cf8 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 8d902d0d8d..c76b53f0bc 100644 --- a/packages/client/src/views/RecordAudit/RecordAudit.test.tsx +++ b/packages/client/src/views/RecordAudit/RecordAudit.test.tsx @@ -275,7 +275,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 4b607aef18..7b59b6f896 100644 --- a/packages/client/src/views/RecordAudit/RecordAudit.tsx +++ b/packages/client/src/views/RecordAudit/RecordAudit.tsx @@ -547,7 +547,7 @@ const BodyContent = ({ assignment: data.fetchRegistration?.registration?.assignment } } else { - declaration = getGQLDeclaration(data.fetchRegistration, language) + declaration = getGQLDeclaration(data.fetchRegistration, intl) } return ( @@ -583,7 +583,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 8060aad1d6..ace7031936 100644 --- a/packages/client/src/views/RecordAudit/utils.ts +++ b/packages/client/src/views/RecordAudit/utils.ts @@ -23,7 +23,7 @@ import { FIELD_AGENT_ROLES, LANG_EN } from '@client/utils/constants' -import { createNamesMap } from '@client/utils/data-formatting' +import { createNamesMap, getLocalisedName } from '@client/utils/data-formatting' import { getDeclarationFullName } from '@client/utils/draftUtils' import { EventType, @@ -365,7 +365,7 @@ export const getDraftDeclarationData = ( export const getWQDeclarationData = ( workqueueDeclaration: GQLEventSearchSet, - language: string, + intl: IntlShape, trackingId: string ) => { let name = EMPTY_STRING @@ -373,19 +373,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 @@ -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 } diff --git a/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx b/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx index b83268ee1f..d4e033b370 100644 --- a/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx +++ b/packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx @@ -189,7 +189,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 7db662cfe3..fe6e3f6a6e 100644 --- a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx +++ b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx @@ -1708,11 +1708,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(