diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 27e8fc9923f8..a5bd89415238 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -156,8 +156,8 @@ function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destination // - A 1:1 DM const currentUserAccountID = getPersonalDetailByEmail(currentUserLogin)?.accountID; const reportName = isPolicyExpenseChat(rootParentReport) - ? getPolicyExpenseChatName({report: rootParentReport}) - : buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID}); + ? getPolicyExpenseChatName({report: rootParentReport, translate}) + : buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID, translate}); const policyName = getPolicyName({report: rootParentReport, returnEmptyIfNotFound: true, policy}); // If we can't determine either the report name or policy name, return the default message if (isEmpty(policyName) && !reportName) { diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index 554243bc18af..0c20337862e5 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -216,10 +216,12 @@ const buildReportNameFromParticipantNames = ({ report, personalDetailsList: personalDetailsData, currentUserAccountID, + translate, }: { report: OnyxEntry; personalDetailsList?: Partial; currentUserAccountID?: number; + translate: LocalizedTranslate; }) => Object.keys(report?.participants ?? {}) .map(Number) @@ -232,6 +234,7 @@ const buildReportNameFromParticipantNames = ({ shouldUseShortForm: true, personalDetailsData, formatPhoneNumber: formatPhoneNumberPhoneUtils, + translate, }), })) .filter((participant) => participant.name) @@ -242,6 +245,7 @@ const buildReportNameFromParticipantNames = ({ accountID, personalDetailsData, formatPhoneNumber: formatPhoneNumberPhoneUtils, + translate, }); } return formattedNames ? `${formattedNames}, ${name}` : name; @@ -260,6 +264,7 @@ const customCollator = new Intl.Collator('en', {usage: 'sort', sensitivity: 'var */ function getGroupChatName( formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + translate: LocalizedTranslate, participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry, @@ -290,7 +295,7 @@ function getGroupChatName( return participantAccountIDs .map( (participantAccountID, index) => - getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber}) || + getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber, translate}) || formatPhoneNumber(participants?.[index]?.login ?? ''), ) .sort((first, second) => customCollator.compare(first ?? '', second ?? '')) @@ -299,21 +304,29 @@ function getGroupChatName( .slice(0, CONST.REPORT_NAME_LIMIT) .concat(shouldAddEllipsis ? '...' : ''); } - return translateLocal('groupChat.defaultReportName', getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber})); + return translate('groupChat.defaultReportName', getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber, translate})); } /** * Get the title for a policy expense chat */ -function getPolicyExpenseChatName({report, personalDetailsList}: {report: OnyxEntry; personalDetailsList?: Partial}): string | undefined { +function getPolicyExpenseChatName({ + report, + personalDetailsList, + translate, +}: { + report: OnyxEntry; + personalDetailsList?: Partial; + translate: LocalizedTranslate; +}): string | undefined { const ownerAccountID = report?.ownerAccountID; const personalDetails = ownerAccountID ? personalDetailsList?.[ownerAccountID] : undefined; const login = personalDetails ? personalDetails.login : null; - const reportOwnerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils}) || login; + const reportOwnerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) || login; if (reportOwnerDisplayName) { - return translateLocal('workspace.common.policyExpenseChatName', reportOwnerDisplayName); + return translate('workspace.common.policyExpenseChatName', reportOwnerDisplayName); } return report?.reportName; @@ -1033,7 +1046,7 @@ function computeReportName({ } if (isGroupChat(report)) { - return getGroupChatName(formatPhoneNumberPhoneUtils, undefined, true, report) ?? ''; + return getGroupChatName(formatPhoneNumberPhoneUtils, translate, undefined, true, report) ?? ''; } let formattedName: string | undefined; @@ -1043,7 +1056,7 @@ function computeReportName({ } if (isPolicyExpenseChat(report)) { - formattedName = getPolicyExpenseChatName({report, personalDetailsList}); + formattedName = getPolicyExpenseChatName({report, personalDetailsList, translate}); } const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; @@ -1093,7 +1106,7 @@ function computeReportName({ } // Not a room or PolicyExpenseChat, generate title from first 5 other participants - formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, currentUserAccountID}); + formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, currentUserAccountID, translate}); const finalName = formattedName ?? report?.reportName ?? ''; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f12653caf56f..688ae561273a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3941,7 +3941,7 @@ function getIconsForIOUReport(report: OnyxInputOrEntry, personalDetails: /** * Helper function to get the icons for a group chat. Only to be used in getIcons(). */ -function getIconsForGroupChat(report: OnyxInputOrEntry, formatPhoneNumber: LocaleContextProps['formatPhoneNumber']): Icon[] { +function getIconsForGroupChat(report: OnyxInputOrEntry, formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], translate: LocalizedTranslate): Icon[] { if (!report) { return []; } @@ -3950,7 +3950,7 @@ function getIconsForGroupChat(report: OnyxInputOrEntry, formatPhoneNumbe source: report.avatarUrl || getDefaultGroupAvatar(report.reportID), id: -1, type: CONST.ICON_TYPE_AVATAR, - name: getGroupChatName(formatPhoneNumber, undefined, true, report), + name: getGroupChatName(formatPhoneNumber, translate, undefined, true, report), }; return [groupChatIcon]; } @@ -4074,7 +4074,7 @@ function getIcons( return getIconsForParticipants([CONST.ACCOUNT_ID.NOTIFICATIONS ?? 0], personalDetails); } if (isGroupChat(report)) { - return getIconsForGroupChat(report, formatPhoneNumber); + return getIconsForGroupChat(report, formatPhoneNumber, translate); } if (isOneOnOneChat(report)) { const otherParticipantsAccountIDs = Object.keys(report.participants ?? {}) diff --git a/src/pages/DynamicReportParticipantsInvitePage.tsx b/src/pages/DynamicReportParticipantsInvitePage.tsx index 6660145f8127..cf934e3bb691 100644 --- a/src/pages/DynamicReportParticipantsInvitePage.tsx +++ b/src/pages/DynamicReportParticipantsInvitePage.tsx @@ -115,7 +115,7 @@ function DynamicReportParticipantsInvitePage({report}: DynamicReportParticipants toggleSelection(option); }; - const reportName = getGroupChatName(formatPhoneNumber, undefined, true, report); + const reportName = getGroupChatName(formatPhoneNumber, translate, undefined, true, report); const goBack = () => { Navigation.goBack(backPath); diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 3c8c41744965..8baf4d64e9cc 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -45,7 +45,9 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { const {translate, formatPhoneNumber} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); - const existingReportName = report ? getGroupChatName(formatPhoneNumber, undefined, false, report) : getGroupChatName(formatPhoneNumber, groupChatDraft?.participants); + const existingReportName = report + ? getGroupChatName(formatPhoneNumber, translate, undefined, false, report) + : getGroupChatName(formatPhoneNumber, translate, groupChatDraft?.participants); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName; diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 4ec12acee7cf..81ded6615015 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -56,7 +56,7 @@ function AvatarAndGroupNameSection({setAvatarFile, optimisticReportID}: AvatarAn const [newGroupDraft, newGroupDraftMetaData] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); const icons = useMemoizedLazyExpensifyIcons(['Camera']); - const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(formatPhoneNumber, newGroupDraft?.participants); + const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(formatPhoneNumber, translate, newGroupDraft?.participants); const stashedLocalAvatarImage = newGroupDraft?.avatarUri; diff --git a/tests/unit/ReportNameUtilsTest.ts b/tests/unit/ReportNameUtilsTest.ts index 49cf56e69e2c..ab80c4eec5be 100644 --- a/tests/unit/ReportNameUtilsTest.ts +++ b/tests/unit/ReportNameUtilsTest.ts @@ -25,6 +25,7 @@ import Onyx from 'react-native-onyx'; import createRandomPolicy from '../utils/collections/policies'; import {createAdminRoom, createExpenseReport, createPolicyExpenseChat, createRegularChat, createRegularTaskReport, createSelfDM, createWorkspaceThread} from '../utils/collections/reports'; import createRandomTransaction from '../utils/collections/transaction'; +import createMock from '../utils/createMock'; import {fakePersonalDetails} from '../utils/LHNTestUtils'; import {formatPhoneNumber, translateLocal} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -1051,7 +1052,7 @@ describe('ReportNameUtils', () => { ...createRegularChat(1000, [currentUserAccountID, 1, 2]), }; - const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails, currentUserAccountID}); + const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails, currentUserAccountID, translate: translateLocal}); expect(name).toBe('Ragnar, floki@vikings.net'); }); @@ -1060,9 +1061,24 @@ describe('ReportNameUtils', () => { ...createRegularChat(1001, [currentUserAccountID, 1]), }; - const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails, currentUserAccountID}); + const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails, currentUserAccountID, translate: translateLocal}); expect(name).toBe('Ragnar Lothbrok'); }); + + test('resolves a hidden participant name through the provided translate function', () => { + const hiddenAccountID = 987654; + const report = {...createRegularChat(1002, [currentUserAccountID, hiddenAccountID])}; + // The lone remaining participant has empty personal details, so its name resolves via translate('common.hidden'). + const translateWithHiddenMarker: LocalizedTranslate = (path, ...parameters) => (path === 'common.hidden' ? 'HiddenMarker' : translateLocal(path, ...parameters)); + + const name = buildReportNameFromParticipantNames({ + report, + personalDetailsList: {[hiddenAccountID]: {accountID: hiddenAccountID, login: '', displayName: ''}}, + currentUserAccountID, + translate: translateWithHiddenMarker, + }); + expect(name).toBe('HiddenMarker'); + }); }); describe('Invoice naming helpers', () => { @@ -1213,7 +1229,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, translate: translateLocal}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', 'Ragnar Lothbrok')); }); @@ -1223,7 +1239,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, translate: translateLocal}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', 'floki')); }); @@ -1233,9 +1249,19 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: {}}); + const name = getPolicyExpenseChatName({report, personalDetailsList: {}, translate: translateLocal}); expect(name).toBe('Fallback Report Name'); }); + + it('builds the policy expense chat name through the provided translate function', () => { + const report = createMock({ownerAccountID: 1, reportName: 'Fallback Report Name'}); + // The workspace.common.policyExpenseChatName label is produced by the provided translate function. + const translateWithMarker: LocalizedTranslate = (path, ...parameters) => + path === 'workspace.common.policyExpenseChatName' ? `PolicyMarker:${String(parameters.at(0))}` : translateLocal(path, ...parameters); + + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, translate: translateWithMarker}); + expect(name).toBe('PolicyMarker:Ragnar Lothbrok'); + }); }); describe('getGroupChatName', () => { @@ -1262,27 +1288,27 @@ describe('ReportNameUtils', () => { describe('When participantAccountIDs is passed to getGroupChatName', () => { it('shows all participants when count <= 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('shows all participants when count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, fourParticipants, true)).toEqual('Four, One, Three, Two'); }); it('shows 5 participants with ellipsis when count > 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); }); it('shows all participants when count > 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); it('uses correct display names for participants', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -1295,7 +1321,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, false, report)).toEqual("Let's talk"); }); it('uses report name when available (limit true)', async () => { @@ -1306,7 +1332,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, true, report)).toEqual("Let's talk"); }); it('uses report name when >5 participants and limit true', async () => { @@ -1317,7 +1343,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, true, report)).toEqual("Let's talk"); }); it('uses report name when >5 participants and limit false', async () => { @@ -1328,7 +1354,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, false, report)).toEqual("Let's talk"); }); it('falls back to participant names when report name is empty', async () => { @@ -1339,9 +1365,19 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); + + it('builds the single-participant default name through the provided translate function', async () => { + await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); + // A single participant produces the groupChat.defaultReportName label from the provided translate function. + const translateWithMarker: LocalizedTranslate = (path, ...parameters) => + path === 'groupChat.defaultReportName' ? `GroupMarker:${String(parameters.at(0))}` : translateLocal(path, ...parameters); + + const name = getGroupChatName(formatPhoneNumber, translateWithMarker, [{accountID: 1, login: 'ragnar@vikings.net'}]); + expect(name).toContain('GroupMarker:'); + }); }); describe('getMoneyRequestReportName', () => { diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index eef4a79c44c2..4fffabdc97e0 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1164,7 +1164,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', }); - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, translate: translateLocal}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', 'Ragnar Lothbrok')); }); @@ -1174,7 +1174,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', }); - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, translate: translateLocal}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', 'floki')); }); @@ -1184,7 +1184,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', }); - const name = getPolicyExpenseChatName({report, personalDetailsList: {}}); + const name = getPolicyExpenseChatName({report, personalDetailsList: {}, translate: translateLocal}); expect(name).toBe('Fallback Report Name'); }); }); @@ -6888,27 +6888,27 @@ describe('ReportUtils', () => { describe('When participantAccountIDs is passed to getGroupChatName', () => { it('Should show all participants name if count <= 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show all participants name if count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show 5 participants name with ellipsis if count > 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); }); it('Should show all participants name if count > 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); it('Should use correct display name for participants', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -6922,7 +6922,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, false, report)).toEqual("Let's talk"); }); it('Should show report name if count <= 5 and shouldApplyLimit is true', async () => { @@ -6934,7 +6934,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is true', async () => { @@ -6946,7 +6946,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is false', async () => { @@ -6958,7 +6958,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, false, report)).toEqual("Let's talk"); }); it('Should show participant names if report name is not available', async () => { @@ -6970,7 +6970,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, translateLocal, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); }); @@ -9688,26 +9688,26 @@ describe('ReportUtils', () => { it('excludes the current user from the report title', () => { const {report, personalDetails: testPersonalDetails} = generateFakeReportAndParticipantsPersonalDetails({count: currentUserAccountID + 2}); - const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID, translate: translateLocal}); expect(result).not.toContain('CURRENT'); }); it('limits to a maximum of 5 participants in the title', () => { const {report, personalDetails: testPersonalDetails} = generateFakeReportAndParticipantsPersonalDetails({count: 10}); - const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID, translate: translateLocal}); expect(result.split(',').length).toBeLessThanOrEqual(5); }); it('returns full name if only one participant is present (excluding current user)', () => { const {report, personalDetails: testPersonalDetails} = generateFakeReportAndParticipantsPersonalDetails({count: 1}); - const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID, translate: translateLocal}); const {displayName} = fakePersonalDetails[1] ?? {}; expect(result).toEqual(displayName); }); it('returns an empty string if there are no participants or all are excluded', () => { const {report, personalDetails: testPersonalDetails} = generateFakeReportAndParticipantsPersonalDetails({start: currentUserAccountID - 1, count: 1}); - const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID, translate: translateLocal}); expect(result).toEqual(''); }); @@ -9718,7 +9718,7 @@ describe('ReportUtils', () => { const fourthUser = fakePersonalDetails[4]; const incompleteDetails = {2: secondUser, 4: fourthUser}; - const result = buildReportNameFromParticipantNames({report, personalDetailsList: incompleteDetails, currentUserAccountID}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: incompleteDetails, currentUserAccountID, translate: translateLocal}); const expectedNames = [secondUser?.firstName, fourthUser?.firstName].sort(); const resultNames = result.split(', ').sort(); expect(resultNames).toEqual(expect.arrayContaining(expectedNames));