diff --git a/package.json b/package.json index 0de5f2989548..f53356f29de7 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=111 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=110 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "check-lazy-loading": "ts-node scripts/checkLazyLoading.ts", "lint-watch": "npx eslint-watch --watch --changed", diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index f113b78f909a..3bd54c8cf0a2 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -278,6 +278,7 @@ function MoneyRequestConfirmationListFooter({ const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(); const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector, canBeMissing: true}); + const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true}); const isUnreported = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const isCreatingTrackExpense = action === CONST.IOU.ACTION.CREATE && iouType === CONST.IOU.TYPE.TRACK; @@ -345,13 +346,14 @@ function MoneyRequestConfirmationListFooter({ return [reportIDToUse, reportToUse]; }, [allReports, shouldUseTransactionReport, transaction?.reportID, outstandingReportID]); + const resolvedCurrentUserAccountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID; const reportName = useMemo(() => { - const name = computeReportName(selectedReport, allReports, allPolicies); + const name = computeReportName(selectedReport, allReports, allPolicies, undefined, undefined, undefined, undefined, resolvedCurrentUserAccountID); if (!name) { return isUnreported ? translate('common.none') : translate('iou.newReport'); } return name; - }, [isUnreported, selectedReport, allReports, allPolicies, translate]); + }, [isUnreported, selectedReport, allReports, allPolicies, translate, resolvedCurrentUserAccountID]); const shouldReportBeEditableFromFAB = isUnreported ? allOutstandingReports.length >= 1 : allOutstandingReports.length > 1; diff --git a/src/components/TransactionItemRow/index.tsx b/src/components/TransactionItemRow/index.tsx index 0593ce05dfa4..a7296b54daf6 100644 --- a/src/components/TransactionItemRow/index.tsx +++ b/src/components/TransactionItemRow/index.tsx @@ -18,6 +18,7 @@ import WorkspaceCell from '@components/SelectionListWithSections/Search/Workspac import Text from '@components/Text'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; +import useOnyx from '@hooks/useOnyx'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; @@ -43,6 +44,7 @@ import { } from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails, Policy, Report, TransactionViolation} from '@src/types/onyx'; import type {SearchTransactionAction} from '@src/types/onyx/SearchResults'; import CategoryCell from './DataCells/CategoryCell'; @@ -186,6 +188,7 @@ function TransactionItemRow({ const StyleUtils = useStyleUtils(); const theme = useTheme(); const {isLargeScreenWidth} = useResponsiveLayout(); + const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true}); const hasCategoryOrTag = !isCategoryMissing(transactionItem?.category) || !!transactionItem.tag; const createdAt = getTransactionCreated(transactionItem); const expensicons = useMemoizedLazyExpensifyIcons(['ArrowRight']); @@ -540,7 +543,11 @@ function TransactionItemRow({ [CONST.SEARCH.TABLE_COLUMNS.TITLE]: ( diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 2bfb5d2e1461..c1a92528f542 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -43,6 +43,7 @@ let environmentURL: string; getEnvironmentURL().then((url: string) => (environmentURL = url)); let currentUserLogin = ''; +let currentUserAccountID: number | undefined; Onyx.connectWithoutView({ key: ONYXKEYS.SESSION, callback: (value) => { @@ -51,6 +52,7 @@ Onyx.connectWithoutView({ return; } currentUserLogin = value?.email ?? ''; + currentUserAccountID = value?.accountID; }, }); @@ -168,7 +170,10 @@ function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destination // - A policy expense chat // - A 1:1 DM // eslint-disable-next-line @typescript-eslint/no-deprecated - const reportName = isPolicyExpenseChat(rootParentReport) ? getPolicyExpenseChatName({report: rootParentReport}) : buildReportNameFromParticipantNames({report: rootParentReport}); + const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID; + const reportName = isPolicyExpenseChat(rootParentReport) + ? getPolicyExpenseChatName({report: rootParentReport}) + : buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID: resolvedCurrentUserAccountID}); const policyName = getPolicyName({report: rootParentReport, returnEmptyIfNotFound: true}); // 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/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 44a93da19b5b..273c2c124f0d 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -650,7 +650,7 @@ function getLastMessageTextForReport({ : undefined; // For workspace chats, use the report title if (reportUtilsIsPolicyExpenseChat(report) && !isEmptyObject(iouReport)) { - const reportName = computeReportName(iouReport); + const reportName = computeReportName(iouReport, undefined, undefined, undefined, undefined, undefined, undefined, currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID); lastMessageTextFromReport = formatReportLastMessageText(reportName); } else { const reportPreviewMessage = getReportPreviewMessage( @@ -924,7 +924,16 @@ function createOption( : getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, lastActorDetails); const personalDetailsForCompute: PersonalDetailsList | undefined = personalDetails ?? undefined; - const computedReportName = computeReportName(report, allReports, allPolicies, undefined, allReportNameValuePairs, personalDetailsForCompute, allReportActions); + const computedReportName = computeReportName( + report, + allReports, + allPolicies, + undefined, + allReportNameValuePairs, + personalDetailsForCompute, + allReportActions, + currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, + ); reportName = showPersonalDetails ? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils}) || formatPhoneNumberPhoneUtils(personalDetail?.login ?? '') : computedReportName; @@ -986,7 +995,7 @@ function getReportOption(participant: Participant, reportAttributesDerived?: Rep // eslint-disable-next-line @typescript-eslint/no-deprecated option.alternateText = translateLocal('reportActionsView.yourSpace'); } else if (option.isInvoiceRoom) { - option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined); + option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined, currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID); // eslint-disable-next-line @typescript-eslint/no-deprecated option.alternateText = translateLocal('workspace.common.invoices'); } else { @@ -1035,7 +1044,7 @@ function getReportDisplayOption(report: OnyxEntry, unknownUserDetails: O // eslint-disable-next-line @typescript-eslint/no-deprecated option.alternateText = translateLocal('reportActionsView.yourSpace'); } else if (option.isInvoiceRoom) { - option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined); + option.text = computeReportName(report, undefined, undefined, undefined, allReportNameValuePairs, allPersonalDetails, undefined, currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID); // eslint-disable-next-line @typescript-eslint/no-deprecated option.alternateText = translateLocal('workspace.common.invoices'); } else if (unknownUserDetails) { diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index 2b5751a35d47..3e45fec477b1 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -115,16 +115,8 @@ import { isUserCreatedPolicyRoom, } from './ReportUtils'; -let currentUserAccountID: number | undefined; let allPersonalDetails: OnyxEntry; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (value) => { - currentUserAccountID = value?.accountID; - }, -}); - Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (value) => { @@ -142,7 +134,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, + currentUserAccountID, +}: { + report: OnyxEntry; + personalDetailsList?: Partial; + currentUserAccountID: number; +}) => Object.keys(report?.participants ?? {}) .map(Number) .filter((id) => id !== currentUserAccountID) @@ -251,11 +251,13 @@ function getInvoicesChatName({ receiverPolicy, personalDetails, policies, + currentUserAccountID, }: { report: OnyxEntry; receiverPolicy: OnyxEntry; personalDetails?: Partial; policies?: Policy[]; + currentUserAccountID: number; }): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; @@ -653,6 +655,7 @@ function computeReportName( allReportNameValuePairs?: OnyxCollection, personalDetailsList?: PersonalDetailsList, reportActions?: OnyxCollection, + currentUserAccountID?: number, ): string { if (!report || !report.reportID) { return ''; @@ -724,7 +727,8 @@ function computeReportName( receiverPolicyID = (receiver as {policyID: string}).policyID; } const invoiceReceiverPolicy = receiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${receiverPolicyID}`] : undefined; - formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList}); + const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID; + formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList, currentUserAccountID: resolvedCurrentUserAccountID}); } if (isSelfDM(report)) { @@ -745,7 +749,8 @@ function computeReportName( } // Not a room or PolicyExpenseChat, generate title from first 5 other participants - formattedName = buildReportNameFromParticipantNames({report, personalDetailsList}); + const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID; + formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, currentUserAccountID: resolvedCurrentUserAccountID}); const finalName = formattedName ?? report?.reportName ?? ''; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fc948cdf21c4..fb10ade40b33 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5948,7 +5948,14 @@ function getReportName( } if (isInvoiceRoom(report)) { - formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails, policies}); + const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID; + formattedName = getInvoicesChatName({ + report, + receiverPolicy: invoiceReceiverPolicy, + personalDetails, + policies, + currentUserAccountID: resolvedCurrentUserAccountID, + }); } if (isSelfDM(report)) { @@ -5969,7 +5976,8 @@ function getReportName( } // Not a room or PolicyExpenseChat, generate title from first 5 other participants - formattedName = buildReportNameFromParticipantNames({report, personalDetailsList: personalDetails}); + const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID; + formattedName = buildReportNameFromParticipantNames({report, personalDetailsList: personalDetails, currentUserAccountID: resolvedCurrentUserAccountID}); const finalName = formattedName || (report?.reportName ?? ''); diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index eb4069ce021e..e998c18507f5 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -68,11 +68,12 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, ONYXKEYS.COLLECTION.TRANSACTION, ONYXKEYS.PERSONAL_DETAILS_LIST, + ONYXKEYS.SESSION, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.COLLECTION.REPORT_METADATA, ], compute: ( - [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies], + [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, session, policies], {currentValue, sourceValues, areAllConnectionsSet}, ) => { if (!areAllConnectionsSet) { @@ -219,7 +220,9 @@ export default createOnyxDerivedValueConfig({ } acc[report.reportID] = { - reportName: report ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions) : '', + reportName: report + ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions, session?.accountID ?? CONST.DEFAULT_NUMBER_ID) + : '', isEmpty: generateIsEmptyReport(report, isReportArchived), brickRoadStatus, requiresAttention, diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 11f0638320dd..88092e4f0c02 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -527,9 +527,9 @@ function getFilterExpenseDisplayTitle(filters: Partial, _: LocaleContextProps['translate'], reports?: OnyxCollection) { +function getFilterInDisplayTitle(filters: Partial, _: LocaleContextProps['translate'], reports: OnyxCollection | undefined, currentUserAccountID: number) { return filters.in - ?.map((id) => computeReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reports)) + ?.map((id) => computeReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reports, undefined, undefined, undefined, undefined, undefined, currentUserAccountID)) ?.filter(Boolean) ?.join(', '); } @@ -548,8 +548,8 @@ function AdvancedSearchFilters() { const personalDetails = usePersonalDetails(); const [policies = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); - - const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: emailSelector}); + const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true}); + const currentUserLogin = emailSelector(session); const taxRates = getAllTaxRates(policies); @@ -609,7 +609,7 @@ function AdvancedSearchFilters() { ) { filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters[key] ?? [], personalDetails, formatPhoneNumber); } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) { - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate, reports); + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate, reports, session?.accountID ?? CONST.DEFAULT_NUMBER_ID); } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID) { const workspacesData = workspaces.flatMap((value) => value.data); filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, workspacesData); diff --git a/src/pages/iou/SplitExpenseEditPage.tsx b/src/pages/iou/SplitExpenseEditPage.tsx index 96ed74401c3d..d6cc66695c18 100644 --- a/src/pages/iou/SplitExpenseEditPage.tsx +++ b/src/pages/iou/SplitExpenseEditPage.tsx @@ -107,7 +107,8 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) { const isSplitAvailable = report && transaction && isSplitAction(currentReport, [transaction], originalTransaction, currentPolicy); const isCategoryRequired = !!currentPolicy?.requiresCategory; - const reportName = computeReportName(currentReport); + const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true}); + const reportName = computeReportName(currentReport, undefined, undefined, undefined, undefined, undefined, undefined, session?.accountID ?? CONST.DEFAULT_NUMBER_ID); const isDescriptionRequired = isCategoryDescriptionRequired(policyCategories, splitExpenseDraftTransactionDetails?.category, currentPolicy?.areRulesEnabled); const shouldShowTags = !!currentPolicy?.areTagsEnabled && !!(transactionTag || hasEnabledTags(policyTagLists)); diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index b18f1bb3d884..2ea3148a11f2 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 7790b9eb8c03..9b45063e6345 100644 --- a/tests/unit/ReportNameUtilsTest.ts +++ b/tests/unit/ReportNameUtilsTest.ts @@ -1,8 +1,9 @@ import Onyx from 'react-native-onyx'; +import type {OnyxCollection} from 'react-native-onyx'; import {translate} from '@libs/Localize'; import { buildReportNameFromParticipantNames, - computeReportName, + computeReportName as computeReportNameOriginal, getGroupChatName, getInvoicePayerName, getInvoicesChatName, @@ -12,7 +13,7 @@ import { import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs} from '@src/types/onyx'; +import type {PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs, Transaction} 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'; @@ -20,6 +21,16 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; describe('ReportNameUtils', () => { const currentUserAccountID = 5; + const computeReportName = ( + report?: Report, + reports?: OnyxCollection, + policies?: OnyxCollection, + transactions?: OnyxCollection, + allReportNameValuePairs?: OnyxCollection, + personalDetailsList?: PersonalDetailsList, + reportActions?: OnyxCollection, + currentUserID = currentUserAccountID, + ) => computeReportNameOriginal(report, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserID); const participantsPersonalDetails: PersonalDetailsList = [ { accountID: 1, @@ -82,7 +93,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('Ragnar Lothbrok'); }); @@ -92,7 +112,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('floki@vikings.net'); }); @@ -102,7 +131,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('(833) 240-3627'); }); @@ -114,7 +152,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( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('Ragnar, floki@vikings.net, Lagertha, (833) 240-3627'); }); }); @@ -122,7 +169,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( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('#admins'); }); @@ -140,6 +196,7 @@ describe('ReportNameUtils', () => { reportNameValuePairs, participantsPersonalDetails, emptyCollections.reportActions, + currentUserAccountID, ); expect(nameEn).toBe('#admins (archived)'); @@ -152,6 +209,7 @@ describe('ReportNameUtils', () => { reportNameValuePairs, participantsPersonalDetails, emptyCollections.reportActions, + currentUserAccountID, ); expect(nameEs).toBe('#admins (archivado)'); @@ -167,7 +225,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( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe("Ragnar Lothbrok's expenses"); }); }); @@ -180,7 +247,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( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('Lagertha Lothbrok (you)'); }); }); @@ -193,7 +269,16 @@ describe('ReportNameUtils', () => { reportName: htmlTaskTitle, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + currentUserAccountID, + ); expect(name).toBe('heading with link'); }); }); @@ -226,7 +311,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( + thread, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + reportActionsCollection, + currentUserAccountID, + ); expect(name).toBe(expected); }); @@ -254,7 +348,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( + thread, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + reportActionsCollection, + currentUserAccountID, + ); expect(name).toBe(expected); }); }); @@ -323,6 +426,7 @@ describe('ReportNameUtils', () => { reportNameValuePairs, participantsPersonalDetails, emptyCollections.reportActions, + currentUserAccountID, ); expect(name).toBe('Ragnar Lothbrok (archived) '); }); @@ -334,7 +438,7 @@ describe('ReportNameUtils', () => { ...createRegularChat(1000, [currentUserAccountID, 1, 2]), }; - const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails}); + const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails, currentUserAccountID}); expect(name).toBe('Ragnar, floki@vikings.net'); }); @@ -343,7 +447,7 @@ describe('ReportNameUtils', () => { ...createRegularChat(1001, [currentUserAccountID, 1]), }; - const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails}); + const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails, currentUserAccountID}); expect(name).toBe('Ragnar Lothbrok'); }); }); @@ -361,6 +465,7 @@ describe('ReportNameUtils', () => { report, receiverPolicy, personalDetails: participantsPersonalDetails, + currentUserAccountID, }); expect(name).toBe('Personal Workspace'); @@ -378,6 +483,7 @@ describe('ReportNameUtils', () => { report, receiverPolicy, personalDetails: participantsPersonalDetails, + currentUserAccountID, }); const normalizedName = name?.replaceAll('\u00A0', ' '); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 71935513d846..35f7e02881ee 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -20,7 +20,7 @@ import getReportURLForCurrentContext from '@libs/Navigation/helpers/getReportURL import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import {getOriginalMessage, getReportAction, isWhisperAction} from '@libs/ReportActionsUtils'; -import {buildReportNameFromParticipantNames, computeReportName, getGroupChatName, getPolicyExpenseChatName, getReportName} from '@libs/ReportNameUtils'; +import {buildReportNameFromParticipantNames, computeReportName as computeReportNameOriginal, getGroupChatName, getPolicyExpenseChatName, getReportName} from '@libs/ReportNameUtils'; import type {OptionData} from '@libs/ReportUtils'; import { buildOptimisticChatReport, @@ -193,6 +193,16 @@ jest.mock('@libs/Navigation/Navigation', () => ({ const testDate = DateUtils.getDBTime(); const currentUserEmail = 'bjorn@vikings.net'; const currentUserAccountID = 5; +const computeReportName = ( + report?: Report, + reports?: OnyxCollection, + policies?: OnyxCollection, + transactions?: OnyxCollection, + allReportNameValuePairs?: OnyxCollection, + personalDetailsList?: PersonalDetailsList, + reportActions?: OnyxCollection, + currentUserID = currentUserAccountID, +) => computeReportNameOriginal(report, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserID); const participantsPersonalDetails: PersonalDetailsList = { '1': { accountID: 1, @@ -5641,26 +5651,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}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); 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}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); 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}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); 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}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: testPersonalDetails, currentUserAccountID}); expect(result).toEqual(''); }); @@ -5671,7 +5681,7 @@ describe('ReportUtils', () => { const fourthUser = fakePersonalDetails[4]; const incompleteDetails = {2: secondUser, 4: fourthUser}; - const result = buildReportNameFromParticipantNames({report, personalDetailsList: incompleteDetails}); + const result = buildReportNameFromParticipantNames({report, personalDetailsList: incompleteDetails, currentUserAccountID}); const expectedNames = [secondUser?.firstName, fourthUser?.firstName].sort(); const resultNames = result.split(', ').sort(); expect(resultNames).toEqual(expect.arrayContaining(expectedNames));