diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index 2fabc9b924fa2..643018de9e105 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -4,6 +4,7 @@ import {Str} from 'expensify-common'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import type {LocaleContextProps} from '@components/LocaleContextProvider'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type { @@ -21,7 +22,6 @@ import type { import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {convertToDisplayString} from './CurrencyUtils'; -import {formatPhoneNumber} from './LocalePhoneNumber'; // eslint-disable-next-line @typescript-eslint/no-deprecated import {translateLocal} from './Localize'; import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage'; @@ -137,7 +137,15 @@ function generateArchivedReportName(reportName: string): string { * This function is useful in contexts such as 1:1 direct messages (DMs) or other group chats. * It limits to a maximum of 5 participants for the title and uses short names unless there is only one participant. */ -const buildReportNameFromParticipantNames = ({report, personalDetailsList: personalDetailsData}: {report: OnyxEntry; personalDetailsList?: Partial}) => +const buildReportNameFromParticipantNames = ({ + report, + personalDetailsList: personalDetailsData, + formatPhoneNumber, +}: { + report: OnyxEntry; + personalDetailsList?: Partial; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; +}) => Object.keys(report?.participants ?? {}) .map(Number) .filter((id) => id !== currentUserAccountID) @@ -175,7 +183,13 @@ const customCollator = new Intl.Collator('en', {usage: 'sort', sensitivity: 'var /** * Returns the report name if the report is a group chat */ -function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry, reportMetadataParam?: OnyxEntry): string | undefined { +function getGroupChatName( + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + participants?: SelectedParticipant[], + shouldApplyLimit = false, + report?: OnyxEntry, + reportMetadataParam?: OnyxEntry, +): string | undefined { // If we have a report always try to get the name from the report. if (report?.reportName) { return report.reportName; @@ -217,7 +231,15 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit /** * Get the title for a policy expense chat */ -function getPolicyExpenseChatName({report, personalDetailsList}: {report: OnyxEntry; personalDetailsList?: Partial}): string | undefined { +function getPolicyExpenseChatName({ + report, + personalDetailsList, + formatPhoneNumber, +}: { + report: OnyxEntry; + personalDetailsList?: Partial; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; +}): string | undefined { const ownerAccountID = report?.ownerAccountID; const personalDetails = ownerAccountID ? personalDetailsList?.[ownerAccountID] : undefined; const login = personalDetails ? personalDetails.login : null; @@ -240,11 +262,13 @@ function getInvoicesChatName({ receiverPolicy, personalDetails, policies, + formatPhoneNumber, }: { report: OnyxEntry; receiverPolicy: OnyxEntry; personalDetails?: Partial; policies?: Policy[]; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; @@ -266,8 +290,13 @@ function getInvoicesChatName({ return getPolicyName({report, policy: receiverPolicyResolved, policies}); } -function getInvoiceReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry): string { - const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}); +function getInvoiceReportName( + report: OnyxEntry, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + policy?: OnyxEntry, + invoiceReceiverPolicy?: OnyxEntry, +): string { + const moneyRequestReportName = getMoneyRequestReportName({report, formatPhoneNumber, policy, invoiceReceiverPolicy}); const oldDotInvoiceName = report?.reportName ?? moneyRequestReportName; return isNewDotInvoice(report?.chatReportID) ? moneyRequestReportName : oldDotInvoiceName; } @@ -277,7 +306,12 @@ function getInvoiceReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry, invoiceReceiverPersonalDetail?: PersonalDetails | null): string { +function getInvoicePayerName( + report: OnyxEntry, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + invoiceReceiverPolicy?: OnyxEntry, + invoiceReceiverPersonalDetail?: PersonalDetails | null, +): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; @@ -292,7 +326,17 @@ function getInvoicePayerName(report: OnyxEntry, invoiceReceiverPolicy?: /** * Get the title for an IOU or expense chat which will be showing the payer and the amount */ -function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {report: OnyxEntry; policy?: OnyxEntry; invoiceReceiverPolicy?: OnyxEntry}): string { +function getMoneyRequestReportName({ + report, + formatPhoneNumber, + policy, + invoiceReceiverPolicy, +}: { + report: OnyxEntry; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + policy?: OnyxEntry; + invoiceReceiverPolicy?: OnyxEntry; +}): string { if (report?.reportName && isExpenseReport(report)) { return report.reportName; } @@ -306,7 +350,7 @@ function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {rep payerOrApproverName = getPolicyName({report: parentReport ?? report, policy}); } else if (isInvoiceReport(report)) { const chatReport = getReportOrDraftReport(report?.chatReportID); - payerOrApproverName = getInvoicePayerName(chatReport, invoiceReceiverPolicy); + payerOrApproverName = getInvoicePayerName(chatReport, formatPhoneNumber, invoiceReceiverPolicy); } else { payerOrApproverName = getDisplayNameForParticipant({accountID: report?.managerID, formatPhoneNumber}) ?? ''; } @@ -601,6 +645,7 @@ function computeChatThreadReportName(report: Report, reportNameValuePairs: Repor } function computeReportName( + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], report?: Report, reports?: OnyxCollection, policies?: OnyxCollection, @@ -643,7 +688,7 @@ function computeReportName( } if (isGroupChat(report)) { - return getGroupChatName(undefined, true, report) ?? ''; + return getGroupChatName(formatPhoneNumber, undefined, true, report) ?? ''; } let formattedName: string | undefined; @@ -653,12 +698,12 @@ function computeReportName( } if (isPolicyExpenseChat(report)) { - formattedName = getPolicyExpenseChatName({report, personalDetailsList}); + formattedName = getPolicyExpenseChatName({report, personalDetailsList, formatPhoneNumber}); } const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; if (isMoneyRequestReport(report)) { - formattedName = getMoneyRequestReportName({report, policy}); + formattedName = getMoneyRequestReportName({report, formatPhoneNumber, policy}); } if (isInvoiceReport(report)) { @@ -669,7 +714,7 @@ function computeReportName( chatReceiverPolicyID = (chatReceiver as {policyID: string}).policyID; } const invoiceReceiverPolicy = chatReceiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${chatReceiverPolicyID}`] : undefined; - formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy); + formattedName = getInvoiceReportName(report, formatPhoneNumber, policy, invoiceReceiverPolicy); } if (isInvoiceRoom(report)) { @@ -679,7 +724,7 @@ function computeReportName( receiverPolicyID = (receiver as {policyID: string}).policyID; } const invoiceReceiverPolicy = receiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${receiverPolicyID}`] : undefined; - formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList}); + formattedName = getInvoicesChatName({report, formatPhoneNumber, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList}); } if (isSelfDM(report)) { @@ -695,7 +740,7 @@ function computeReportName( } // Not a room or PolicyExpenseChat, generate title from first 5 other participants - formattedName = buildReportNameFromParticipantNames({report, personalDetailsList}); + formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, formatPhoneNumber}); const finalName = formattedName ?? report?.reportName ?? ''; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8e02c7c78831a..72ae7a6949f2c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3392,7 +3392,13 @@ const customCollator = new Intl.Collator('en', {usage: 'sort', sensitivity: 'var * @deprecated Moved to src/libs/ReportNameUtils.ts. * Use ReportNameUtils.getGroupChatName instead. */ -function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry, reportMetadataParam?: OnyxEntry): string | undefined { +function getGroupChatName( + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + participants?: SelectedParticipant[], + shouldApplyLimit = false, + report?: OnyxEntry, + reportMetadataParam?: OnyxEntry, +): string | undefined { // If we have a report always try to get the name from the report. if (report?.reportName) { return report.reportName; @@ -3418,8 +3424,8 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit return participantAccountIDs .map( (participantAccountID, index) => - getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber: formatPhoneNumberPhoneUtils}) || - formatPhoneNumberPhoneUtils(participants?.[index]?.login ?? ''), + getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber}) || + formatPhoneNumber(participants?.[index]?.login ?? ''), ) .sort((first, second) => customCollator.compare(first ?? '', second ?? '')) .filter(Boolean) @@ -3429,7 +3435,7 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit } // eslint-disable-next-line @typescript-eslint/no-deprecated return translateLocal('groupChat.defaultReportName', { - displayName: getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils}), + displayName: getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber}), }); } @@ -3654,7 +3660,7 @@ function getIconsForGroupChat(report: OnyxInputOrEntry): Icon[] { type: CONST.ICON_TYPE_AVATAR, // This will be fixed as follow up https://github.com/Expensify/App/pull/75357 // eslint-disable-next-line @typescript-eslint/no-deprecated - name: getGroupChatName(undefined, true, report), + name: getGroupChatName(formatPhoneNumberPhoneUtils, undefined, true, report), }; return [groupChatIcon]; } @@ -5997,7 +6003,7 @@ function getReportName( if (isGroupChat(report)) { // This will be fixed as follow up https://github.com/Expensify/App/pull/75357 // eslint-disable-next-line @typescript-eslint/no-deprecated - return getGroupChatName(undefined, true, report) ?? ''; + return getGroupChatName(formatPhoneNumberPhoneUtils, undefined, true, report) ?? ''; } if (isChatRoom(report)) { diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 9dfc6262c7c8a..be921f5a07710 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -1,4 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; +import {formatPhoneNumberWithCountryCode} from '@libs/LocalePhoneNumber'; import {computeReportName} from '@libs/ReportNameUtils'; import {generateIsEmptyReport, generateReportAttributes, isArchivedReport, isValidReport} from '@libs/ReportUtils'; import SidebarUtils from '@libs/SidebarUtils'; @@ -63,6 +64,7 @@ export default createOnyxDerivedValueConfig({ dependencies: [ ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.NVP_PREFERRED_LOCALE, + ONYXKEYS.COUNTRY_CODE, ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ONYXKEYS.COLLECTION.REPORT_ACTIONS, ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, @@ -72,7 +74,7 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.COLLECTION.REPORT_METADATA, ], compute: ( - [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies], + [reports, preferredLocale, countryCode, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies], {currentValue, sourceValues, areAllConnectionsSet}, ) => { if (!areAllConnectionsSet) { @@ -82,6 +84,8 @@ export default createOnyxDerivedValueConfig({ }; } + const formatPhoneNumber = (phoneNumber: string) => formatPhoneNumberWithCountryCode(phoneNumber, countryCode ?? 1); + // Check if display names changed when personal details are updated let displayNamesChanged = false; if (hasKeyTriggeredCompute(ONYXKEYS.PERSONAL_DETAILS_LIST, sourceValues)) { @@ -204,7 +208,7 @@ export default createOnyxDerivedValueConfig({ } acc[report.reportID] = { - reportName: report ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions) : '', + reportName: report ? computeReportName(formatPhoneNumber, report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions) : '', isEmpty: generateIsEmptyReport(report, isReportArchived), brickRoadStatus, requiresAttention, diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 1b686f3562c74..457325bfd3c15 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -12,7 +12,8 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; -import {getGroupChatDraft, getGroupChatName} from '@libs/ReportUtils'; +import {getGroupChatName} from '@libs/ReportNameUtils'; +import {getGroupChatDraft} from '@libs/ReportUtils'; import StringUtils from '@libs/StringUtils'; import {setGroupDraft, updateChatName} from '@userActions/Report'; import CONST from '@src/CONST'; @@ -35,10 +36,13 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { const [groupChatDraft = getGroupChatDraft()] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true}); const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); - const existingReportName = useMemo(() => (report ? getGroupChatName(undefined, false, report) : getGroupChatName(groupChatDraft?.participants)), [groupChatDraft?.participants, report]); + const existingReportName = useMemo( + () => (report ? getGroupChatName(formatPhoneNumber, undefined, false, report) : getGroupChatName(formatPhoneNumber, groupChatDraft?.participants)), + [formatPhoneNumber, groupChatDraft?.participants, report], + ); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName; diff --git a/src/pages/InviteReportParticipantsPage.tsx b/src/pages/InviteReportParticipantsPage.tsx index 3816b07784462..04a105ee916b9 100644 --- a/src/pages/InviteReportParticipantsPage.tsx +++ b/src/pages/InviteReportParticipantsPage.tsx @@ -23,8 +23,9 @@ import type {ParticipantsNavigatorParamList} from '@libs/Navigation/types'; import {getHeaderMessage} from '@libs/OptionsListUtils'; import {getLoginsByAccountIDs} from '@libs/PersonalDetailsUtils'; import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from '@libs/PhoneNumber'; +import {getGroupChatName} from '@libs/ReportNameUtils'; import type {OptionData} from '@libs/ReportUtils'; -import {getGroupChatName, getParticipantsAccountIDsForDisplay} from '@libs/ReportUtils'; +import {getParticipantsAccountIDsForDisplay} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -123,7 +124,7 @@ function InviteReportParticipantsPage({report}: InviteReportParticipantsPageProp const validate = useCallback(() => selectedOptions.length > 0, [selectedOptions.length]); const reportID = report.reportID; - const reportName = useMemo(() => getGroupChatName(undefined, true, report), [report]); + const reportName = useMemo(() => getGroupChatName(formatPhoneNumber, undefined, true, report), [formatPhoneNumber, report]); const goBack = useCallback(() => { Navigation.goBack(ROUTES.REPORT_PARTICIPANTS.getRoute(reportID, route.params.backTo)); diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index cfb95bb5f8cba..dfb820b338306 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -18,7 +18,8 @@ import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types import {readFileAsync} from '@libs/fileDownload/FileUtils'; import Navigation from '@libs/Navigation/Navigation'; import {getParticipantsOption} from '@libs/OptionsListUtils'; -import {generateReportID, getDefaultGroupAvatar, getGroupChatName} from '@libs/ReportUtils'; +import {getGroupChatName} from '@libs/ReportNameUtils'; +import {generateReportID, getDefaultGroupAvatar} from '@libs/ReportUtils'; import {navigateToAndOpenReport, setGroupDraft} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -37,7 +38,7 @@ function navigateToEditChatName() { function NewChatConfirmPage() { const optimisticReportID = useRef(generateReportID()); const [avatarFile, setAvatarFile] = useState(); - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const styles = useThemeStyles(); const personalData = useCurrentUserPersonalDetails(); const [newGroupDraft, newGroupDraftMetaData] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true}); @@ -54,7 +55,7 @@ function NewChatConfirmPage() { return options; }, [allPersonalDetails, newGroupDraft?.participants]); - const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(newGroupDraft?.participants); + const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(formatPhoneNumber, newGroupDraft?.participants); const selectedParticipants: ListItem[] = useMemo( () => selectedOptions diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index a7b948e999d2f..28db98115185f 100644 --- a/tests/unit/OnyxDerivedTest.tsx +++ b/tests/unit/OnyxDerivedTest.tsx @@ -129,8 +129,8 @@ describe('OnyxDerived', () => { const transaction = createRandomTransaction(1); // When the report attributes are recomputed with both report and transaction updates - reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {areAllConnectionsSet: true}); - const reportAttributesComputedValue = reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], { + reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {areAllConnectionsSet: true}); + const reportAttributesComputedValue = reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], { sourceValues: { [ONYXKEYS.COLLECTION.REPORT]: { [`${ONYXKEYS.COLLECTION.REPORT}${reportID1}`]: reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID1}`], diff --git a/tests/unit/ReportNameUtilsTest.ts b/tests/unit/ReportNameUtilsTest.ts index ec43d40c2bd6c..855d6d6f8c91a 100644 --- a/tests/unit/ReportNameUtilsTest.ts +++ b/tests/unit/ReportNameUtilsTest.ts @@ -7,6 +7,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs} from '@src/types/onyx'; import {createAdminRoom, createPolicyExpenseChat, createRegularChat, createRegularTaskReport, createSelfDM, createWorkspaceThread} from '../utils/collections/reports'; import {fakePersonalDetails} from '../utils/LHNTestUtils'; +import {formatPhoneNumber} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; describe('ReportNameUtils', () => { @@ -73,7 +74,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('Ragnar Lothbrok'); }); @@ -83,7 +93,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('floki@vikings.net'); }); @@ -93,7 +112,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('(833) 240-3627'); }); @@ -105,7 +133,16 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('Ragnar, floki@vikings.net, Lagertha, (833) 240-3627'); }); }); @@ -113,7 +150,16 @@ describe('ReportNameUtils', () => { describe('computeReportName - Admin room', () => { test('Active admin room', () => { const report = createAdminRoom(10); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('#admins'); }); @@ -124,6 +170,7 @@ describe('ReportNameUtils', () => { } as Record; const nameEn = computeReportName( + formatPhoneNumber, report, emptyCollections.reports, emptyCollections.policies, @@ -136,6 +183,7 @@ describe('ReportNameUtils', () => { await IntlStore.load(CONST.LOCALES.ES); const nameEs = computeReportName( + formatPhoneNumber, report, emptyCollections.reports, emptyCollections.policies, @@ -158,7 +206,16 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe("Ragnar Lothbrok's expenses"); }); }); @@ -171,7 +228,16 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID, email: 'lagertha2@vikings.net', authTokenType: CONST.AUTH_TOKEN_TYPES.SUPPORT}); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('Lagertha Lothbrok (you)'); }); }); @@ -184,7 +250,16 @@ describe('ReportNameUtils', () => { reportName: htmlTaskTitle, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('heading with link'); }); }); @@ -217,7 +292,16 @@ describe('ReportNameUtils', () => { }; const expected = translate(CONST.LOCALES.EN, 'iou.submitted', {memo: 'via workflow'}); - const name = computeReportName(thread, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, reportActionsCollection); + const name = computeReportName( + formatPhoneNumber, + thread, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + reportActionsCollection, + ); expect(name).toBe(expected); }); @@ -245,7 +329,16 @@ describe('ReportNameUtils', () => { }; const expected = translate(CONST.LOCALES.EN, 'iou.rejectedThisReport'); - const name = computeReportName(thread, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, reportActionsCollection); + const name = computeReportName( + formatPhoneNumber, + thread, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + reportActionsCollection, + ); expect(name).toBe(expected); }); }); @@ -307,6 +400,7 @@ describe('ReportNameUtils', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); const name = computeReportName( + formatPhoneNumber, report, emptyCollections.reports, emptyCollections.policies, @@ -326,7 +420,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({formatPhoneNumber, report, personalDetailsList: participantsPersonalDetails}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'Ragnar Lothbrok'})); }); @@ -336,7 +430,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({formatPhoneNumber, report, personalDetailsList: participantsPersonalDetails}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'floki'})); }); @@ -346,7 +440,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: {}}); + const name = getPolicyExpenseChatName({formatPhoneNumber, report, personalDetailsList: {}}); expect(name).toBe('Fallback Report Name'); }); }); @@ -375,27 +469,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(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, 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(fourParticipants, true)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, 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(eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, 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(eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, 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(fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -408,7 +502,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('uses report name when available (limit true)', async () => { @@ -419,7 +513,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('uses report name when >5 participants and limit true', async () => { @@ -430,7 +524,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('uses report name when >5 participants and limit false', async () => { @@ -441,7 +535,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('falls back to participant names when report name is empty', async () => { @@ -452,7 +546,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 4aa5b3a45f592..223eb68f73ebd 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3934,27 +3934,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(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, 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(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, 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(eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, 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(eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, 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(fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -3968,7 +3968,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('Should show report name if count <= 5 and shouldApplyLimit is true', async () => { @@ -3980,7 +3980,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is true', async () => { @@ -3992,7 +3992,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is false', async () => { @@ -4004,7 +4004,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('Should show participant names if report name is not available', async () => { @@ -4016,7 +4016,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); });