From 9f21d1e80c804d0be4f9de32dc7247e4d172ac62 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 16 May 2026 18:19:02 +0530 Subject: [PATCH 1/7] Update `buildOnyxDataForTestDriveIOU` to pass currentUserAccountID --- src/libs/actions/IOU/MoneyRequestBuilder.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/IOU/MoneyRequestBuilder.ts b/src/libs/actions/IOU/MoneyRequestBuilder.ts index 9e1fec7a447f..c92d3e61698e 100644 --- a/src/libs/actions/IOU/MoneyRequestBuilder.ts +++ b/src/libs/actions/IOU/MoneyRequestBuilder.ts @@ -64,7 +64,7 @@ import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; import type {Receipt, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import {getAllPersonalDetails, getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllReports, getCurrentUserPersonalDetails, getUserAccountID} from './index'; +import {getAllPersonalDetails, getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllReports, getCurrentUserPersonalDetails} from './index'; import type {ReplaceReceipt, StartSplitBilActionParams} from './index'; import {getSearchOnyxUpdate} from './SearchUpdate'; import type BasePolicyParams from './types/BasePolicyParams'; @@ -255,6 +255,7 @@ type BuildOnyxDataForTestDriveIOUParams = { iouOptimisticParams: MoneyRequestOptimisticParams['iou']; chatOptimisticParams: MoneyRequestOptimisticParams['chat']; testDriveCommentReportActionID?: string; + currentUserAccountIDParam: number; }; function buildMinimalTransactionForFormula( @@ -317,8 +318,6 @@ function getReceiptError( function buildOnyxDataForTestDriveIOU( testDriveIOUParams: BuildOnyxDataForTestDriveIOUParams, ): OnyxData { - const deprecatedUserAccountID = getUserAccountID(); - const deprecatedCurrentUserPersonalDetails = getCurrentUserPersonalDetails(); const optimisticData: Array> = []; const successData: Array> = []; const failureData: Array> = []; @@ -334,11 +333,11 @@ function buildOnyxDataForTestDriveIOU( transactionID: testDriveIOUParams.transaction.transactionID, reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID, }); - const text = translateLocal('testDrive.employeeInviteMessage', getAllPersonalDetails()?.[deprecatedUserAccountID]?.firstName ?? ''); + const text = translateLocal('testDrive.employeeInviteMessage', getAllPersonalDetails()?.[testDriveIOUParams.currentUserAccountIDParam]?.firstName ?? ''); // delegateAccountIDParam: will be threaded in PR 15; buildOptimisticAddCommentReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) const textComment = buildOptimisticAddCommentReportAction({ text, - actorAccountID: deprecatedUserAccountID, + actorAccountID: testDriveIOUParams.currentUserAccountIDParam, reportActionID: testDriveIOUParams.testDriveCommentReportActionID, delegateAccountIDParam: undefined, }); @@ -358,7 +357,7 @@ function buildOnyxDataForTestDriveIOU( value: { ...{lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED}, hasOutstandingChildRequest: false, - lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID, + lastActorAccountID: testDriveIOUParams.currentUserAccountIDParam, }, }, { @@ -611,6 +610,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR iouOptimisticParams: iou, chatOptimisticParams: chat, testDriveCommentReportActionID, + currentUserAccountIDParam, }); onyxData.optimisticData?.push(...testDriveOptimisticData); onyxData.successData?.push(...testDriveSuccessData); From 5b96bfa356f72abe7c9da6e605c80592407be775 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 16 May 2026 18:46:47 +0530 Subject: [PATCH 2/7] Remove more usages for to pass getUserAccountID --- src/libs/DebugUtils.ts | 6 +++ src/libs/OptionsListUtils/index.ts | 4 ++ src/libs/OptionsListUtils/types.ts | 1 + src/libs/ReportUtils.ts | 18 ++++++-- src/libs/SidebarUtils.ts | 2 + src/libs/UnreadIndicatorUpdater/index.ts | 14 +++++- src/libs/actions/IOU/SearchUpdate.ts | 7 +-- src/pages/Debug/Report/DebugReportPage.tsx | 2 + tests/actions/IOUTest.ts | 16 +++---- tests/unit/ReportUtilsTest.ts | 54 +++++++++++----------- 10 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 2640250c9aae..87a5762c3c87 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -1415,6 +1415,8 @@ function getReasonForShowingRowInLHN({ isInFocusMode = false, betas = undefined, draftComment, + currentUserLogin, + currentUserAccountID, }: { report: OnyxEntry; chatReport: OnyxEntry; @@ -1424,6 +1426,8 @@ function getReasonForShowingRowInLHN({ isInFocusMode?: boolean; betas?: OnyxEntry; draftComment: string | undefined; + currentUserLogin?: string; + currentUserAccountID?: number; }): TranslationPaths | null { if (!report) { return null; @@ -1441,6 +1445,8 @@ function getReasonForShowingRowInLHN({ includeSelfDM: true, isReportArchived, draftComment, + currentUserLogin, + currentUserAccountID, }); if (!([CONST.REPORT_IN_LHN_REASONS.HAS_ADD_WORKSPACE_ROOM_ERRORS, CONST.REPORT_IN_LHN_REASONS.HAS_IOU_VIOLATIONS] as Array).includes(reason) && hasRBR) { diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 99b9600ab149..9d1efcfa1c4f 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2130,6 +2130,7 @@ function isValidReport(option: SearchOption, policy: OnyxEntry, isRestrictedToPreferredPolicy, preferredPolicyID, currentUserAccountID, + currentUserLogin, shouldAlwaysIncludeDM, isTimeRequest = false, } = config; @@ -2149,6 +2150,8 @@ function isValidReport(option: SearchOption, policy: OnyxEntry, includeDomainEmail, isReportArchived: option.private_isArchived, draftComment, + currentUserLogin, + currentUserAccountID, }); if (!shouldBeInOptionList) { @@ -2532,6 +2535,7 @@ function getValidOptions( includeDomainEmail, loginsToExclude: loginsToExcludeFromSuggestions, currentUserAccountID, + currentUserLogin: currentUserEmail, }, draftComment, chatReport, diff --git a/src/libs/OptionsListUtils/types.ts b/src/libs/OptionsListUtils/types.ts index 0c251c9d2e55..d0b8ae1a5bff 100644 --- a/src/libs/OptionsListUtils/types.ts +++ b/src/libs/OptionsListUtils/types.ts @@ -193,6 +193,7 @@ type IsValidReportsConfig = Pick< | 'isTimeRequest' > & { currentUserAccountID: number; + currentUserLogin: string; }; type GetOptionsConfig = { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8f689fa18919..094b370626e2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -86,7 +86,7 @@ import type {FileObject} from '@src/types/utils/Attachment'; import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; import {getBankAccountFromID} from './actions/BankAccounts'; -import {getUserAccountID, setMoneyRequestReportID} from './actions/IOU'; +import {setMoneyRequestReportID} from './actions/IOU'; import type {IOURequestType} from './actions/IOU'; import {unholdRequest} from './actions/IOU/Hold'; import {createDraftTransaction, setMoneyRequestParticipants, setMoneyRequestParticipantsFromReport, startDistanceRequest, startMoneyRequest} from './actions/IOU/MoneyRequest'; @@ -4309,8 +4309,14 @@ function getReasonAndReportActionThatRequiresAttention( * @param option (report or optionItem) * @param parentReportAction (the report action the current report is a thread of) */ -function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | OptionData, parentReportAction?: OnyxEntry, isReportArchived = false) { - return !!getReasonAndReportActionThatRequiresAttention(optionOrReport, getCurrentUserEmail() ?? '', getUserAccountID(), parentReportAction, isReportArchived); +function requiresAttentionFromCurrentUser( + optionOrReport: OnyxEntry | OptionData, + currentUserLogin: string, + currentUserAccountID: number, + parentReportAction?: OnyxEntry, + isReportArchived = false, +) { + return !!getReasonAndReportActionThatRequiresAttention(optionOrReport, currentUserLogin, currentUserAccountID, parentReportAction, isReportArchived); } /** @@ -9488,6 +9494,8 @@ type ShouldReportBeInOptionListParams = { doesReportHaveViolations: boolean; includeSelfDM?: boolean; login?: string; + currentUserLogin?: string; + currentUserAccountID?: number; includeDomainEmail?: boolean; isReportArchived: boolean | undefined; draftComment: string | undefined; @@ -9506,6 +9514,8 @@ function reasonForReportToBeInOptionList({ draftComment, includeSelfDM = false, login, + currentUserLogin, + currentUserAccountID, includeDomainEmail = false, isReportArchived, requiresAttention, @@ -9589,7 +9599,7 @@ function reasonForReportToBeInOptionList({ return CONST.REPORT_IN_LHN_REASONS.HAS_DRAFT_COMMENT; } - if (requiresAttention ?? requiresAttentionFromCurrentUser(report, undefined, isReportArchived)) { + if (requiresAttention ?? requiresAttentionFromCurrentUser(report, currentUserLogin ?? '', currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, undefined, isReportArchived)) { return CONST.REPORT_IN_LHN_REASONS.HAS_GBR; } diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 5e00255c36b4..ecb30050271b 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -345,6 +345,8 @@ function shouldDisplayReportInLHN({ includeSelfDM: true, isReportArchived, requiresAttention, + currentUserLogin, + currentUserAccountID, }); return {shouldDisplay}; diff --git a/src/libs/UnreadIndicatorUpdater/index.ts b/src/libs/UnreadIndicatorUpdater/index.ts index 272620e70b58..e701e0d2cc41 100644 --- a/src/libs/UnreadIndicatorUpdater/index.ts +++ b/src/libs/UnreadIndicatorUpdater/index.ts @@ -8,10 +8,20 @@ import * as ReportUtils from '@libs/ReportUtils'; import Navigation, {navigationRef} from '@navigation/Navigation'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Report, ReportActions, ReportNameValuePairs} from '@src/types/onyx'; +import type {Report, ReportActions, ReportNameValuePairs, Session} from '@src/types/onyx'; import updateUnread from './updateUnread'; let allReports: OnyxCollection = {}; +let currentUserAccountID = CONST.DEFAULT_NUMBER_ID; +let currentUserLogin = ''; + +Onyx.connectWithoutView({ + key: ONYXKEYS.SESSION, + callback: (value: Session | undefined) => { + currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID; + currentUserLogin = value?.email ?? ''; + }, +}); let allReportNameValuePairs: OnyxCollection = {}; // This subscription is used to update the unread indicators count which is not linked to UI and it does not update any UI state. @@ -62,6 +72,8 @@ function getUnreadReportsForUnreadIndicator(reports: OnyxCollection, cur excludeEmptyChats: false, isReportArchived, draftComment, + currentUserLogin, + currentUserAccountID, }) && /** * Chats with hidden preference remain invisible in the LHN and are not considered "unread." diff --git a/src/libs/actions/IOU/SearchUpdate.ts b/src/libs/actions/IOU/SearchUpdate.ts index 74154397a217..cf9d238ba918 100644 --- a/src/libs/actions/IOU/SearchUpdate.ts +++ b/src/libs/actions/IOU/SearchUpdate.ts @@ -11,7 +11,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import type {OnyxData} from '@src/types/onyx/Request'; import type {SearchResultDataType} from '@src/types/onyx/SearchResults'; -import {getCurrentUserPersonalDetails, getUserAccountID} from './index'; +import {getCurrentUserPersonalDetails} from './index'; type ExpenseReportStatusPredicate = (expenseReport: OnyxEntry, transactionReportID?: string) => boolean; @@ -44,6 +44,7 @@ function shouldOptimisticallyUpdateSearch( currentSearchQueryJSON: Readonly, iouReport: OnyxEntry, isInvoice: boolean | undefined, + currentUserAccountID: number, transaction?: OnyxEntry, ) { if ( @@ -76,7 +77,7 @@ function shouldOptimisticallyUpdateSearch( return false; } - const suggestedSearches = getSuggestedSearches(getUserAccountID()); + const suggestedSearches = getSuggestedSearches(currentUserAccountID); const submitQueryJSON = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.SUBMIT].searchQueryJSON; const approveQueryJSON = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.APPROVE].searchQueryJSON; const unapprovedCashSimilarSearchHash = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CASH].similarSearchHash; @@ -125,7 +126,7 @@ function getSearchOnyxUpdate({ return; } - if (shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, isInvoice, transaction)) { + if (shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, isInvoice, fromAccountID, transaction)) { const isOptimisticToAccountData = isOptimisticPersonalDetail(toAccountID); const successData = []; if (isOptimisticToAccountData) { diff --git a/src/pages/Debug/Report/DebugReportPage.tsx b/src/pages/Debug/Report/DebugReportPage.tsx index be2516a2b0bc..d849722eea8a 100644 --- a/src/pages/Debug/Report/DebugReportPage.tsx +++ b/src/pages/Debug/Report/DebugReportPage.tsx @@ -112,6 +112,8 @@ function DebugReportPage({ isReportArchived, isInFocusMode: priorityMode === CONST.PRIORITY_MODE.GSD, draftComment, + currentUserLogin: currentUserLogin ?? '', + currentUserAccountID, }); return [ diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index bb859343effb..43e17f5205aa 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -293,12 +293,12 @@ describe('actions/IOU', () => { const iouReport: Report = {...createRandomReport(2, undefined), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN}; // When the report is in draft status it should return true - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeTruthy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeTruthy(); // If the report is not in draft state it should return false iouReport.stateNum = CONST.REPORT.STATE_NUM.SUBMITTED; iouReport.statusNum = CONST.REPORT.STATUS_NUM.SUBMITTED; - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeFalsy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeFalsy(); }); it('when the current hash is approve action query it should only return true if the iou report is in outstanding state', () => { @@ -352,12 +352,12 @@ describe('actions/IOU', () => { const iouReport: Report = {...createRandomReport(2, undefined), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN}; // When the report is in draft status it should return false - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeFalsy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeFalsy(); // If the report is in outstanding state it should return true iouReport.stateNum = CONST.REPORT.STATE_NUM.SUBMITTED; iouReport.statusNum = CONST.REPORT.STATUS_NUM.SUBMITTED; - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeTruthy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeTruthy(); }); it('when the current hash is unapproved cash action query it should only return true if the iou report is in either draft or outstanding state', () => { @@ -396,12 +396,12 @@ describe('actions/IOU', () => { const iouReport: Report = {...createRandomReport(2, undefined), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN}; // When the report is in draft status it should return true - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeTruthy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeTruthy(); // If the report is in approved state it should return false iouReport.stateNum = CONST.REPORT.STATE_NUM.APPROVED; iouReport.statusNum = CONST.REPORT.STATUS_NUM.APPROVED; - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeFalsy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeFalsy(); }); it('when the current hash includes a policyID filter it should only return true if the iou report matches the policyID filter', () => { @@ -439,7 +439,7 @@ describe('actions/IOU', () => { stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN, }; - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, matchingIOUReport, false, transaction)).toBeTruthy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, matchingIOUReport, false, RORY_ACCOUNT_ID, transaction)).toBeTruthy(); // When the IOU report has a different policyID, it should return false const nonMatchingIOUReport: Report = { @@ -449,7 +449,7 @@ describe('actions/IOU', () => { stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN, }; - expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, nonMatchingIOUReport, false, transaction)).toBeFalsy(); + expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, nonMatchingIOUReport, false, RORY_ACCOUNT_ID, transaction)).toBeFalsy(); }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 6478f908203a..adae2eee5307 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3281,7 +3281,7 @@ describe('ReportUtils', () => { }); it('returns false when there is no report', () => { - expect(requiresAttentionFromCurrentUser(undefined)).toBe(false); + expect(requiresAttentionFromCurrentUser(undefined, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns false when the matched IOU report does not have an owner accountID', () => { @@ -3289,7 +3289,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), ownerAccountID: undefined, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns false when the linked iou report has an outstanding IOU', () => { @@ -3301,7 +3301,7 @@ describe('ReportUtils', () => { reportID: '1', ownerAccountID: 99, }).then(() => { - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); }); @@ -3311,7 +3311,7 @@ describe('ReportUtils', () => { ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: true, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns false when the report has outstanding IOU and is not waiting for a bank account and the logged user is the report owner', () => { @@ -3320,7 +3320,7 @@ describe('ReportUtils', () => { ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: false, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns false when the report has no outstanding IOU but is waiting for a bank account and the logged user is not the report owner', () => { @@ -3329,7 +3329,7 @@ describe('ReportUtils', () => { ownerAccountID: 97, isWaitingOnBankAccount: true, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns true when the report has an unread mention', () => { @@ -3337,7 +3337,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), isUnreadWithMention: true, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns true for @here mention in an admin room', () => { @@ -3347,7 +3347,7 @@ describe('ReportUtils', () => { lastReadTime: '2024-03-01 12:00:00.000', lastMentionedTime: '2024-03-01 12:00:01.000', }; - expect(requiresAttentionFromCurrentUser(report)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns false for @here in an admin room when user already read after mention', () => { @@ -3357,7 +3357,7 @@ describe('ReportUtils', () => { lastReadTime: '2024-03-01 12:00:02.000', lastMentionedTime: '2024-03-01 12:00:01.000', }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns true when the report is an outstanding task', () => { @@ -3370,7 +3370,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.OPEN, hasParentAccess: false, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns true when the report has outstanding child expense', () => { @@ -3380,7 +3380,7 @@ describe('ReportUtils', () => { hasOutstandingChildRequest: true, isWaitingOnBankAccount: false, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns false if the user is not on free trial', async () => { @@ -3394,7 +3394,7 @@ describe('ReportUtils', () => { chatType: CONST.REPORT.CHAT_TYPE.SYSTEM, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it("returns false if the user free trial hasn't ended yet", async () => { @@ -3408,7 +3408,7 @@ describe('ReportUtils', () => { chatType: CONST.REPORT.CHAT_TYPE.SYSTEM, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns true when expense report is awaiting current user approval without parent access', () => { @@ -3421,7 +3421,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - expect(requiresAttentionFromCurrentUser(report)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns false when awaiting approval but parent accessible or user is not approver', () => { @@ -3434,7 +3434,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - expect(requiresAttentionFromCurrentUser(reportWithParentAccess)).toBe(false); + expect(requiresAttentionFromCurrentUser(reportWithParentAccess, currentUserEmail, currentUserAccountID)).toBe(false); const reportWithDifferentManager = { ...LHNTestUtils.getFakeReport(), @@ -3445,7 +3445,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - expect(requiresAttentionFromCurrentUser(reportWithDifferentManager)).toBe(false); + expect(requiresAttentionFromCurrentUser(reportWithDifferentManager, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns false when expense report is awaiting user submission, delayed submission on > daily', async () => { @@ -3457,7 +3457,7 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}1`, {reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL}); - expect(requiresAttentionFromCurrentUser(report)).toBe(false); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); }); it('returns false when expense report is awaiting user submission, delayed submission on > manually', async () => { @@ -3469,7 +3469,7 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}1`, {reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL}); - expect(requiresAttentionFromCurrentUser(report)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns true for expense report awaiting submission with manual submit', async () => { @@ -3492,8 +3492,8 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}1`, {reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL}); // The GBR should appear on the policy expense chat but not on the report itself - expect(requiresAttentionFromCurrentUser(report)).toBe(false); - expect(requiresAttentionFromCurrentUser(policyExpenseChat)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); + expect(requiresAttentionFromCurrentUser(policyExpenseChat, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns true for expense report awaiting user payment/reimbursement', async () => { @@ -3514,8 +3514,8 @@ describe('ReportUtils', () => { }; // The GBR should appear on the policy expense chat but not on the report itself - expect(requiresAttentionFromCurrentUser(report)).toBe(false); - expect(requiresAttentionFromCurrentUser(policyExpenseChat)).toBe(true); + expect(requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID)).toBe(false); + expect(requiresAttentionFromCurrentUser(policyExpenseChat, currentUserEmail, currentUserAccountID)).toBe(true); }); it('returns false and does not surface GBR when expense report is approved and reimbursement is enabled', async () => { @@ -3539,7 +3539,7 @@ describe('ReportUtils', () => { await waitForBatchedUpdates(); // When we evaluate if the report requires attention from the current user - const requiresAttention = requiresAttentionFromCurrentUser(report); + const requiresAttention = requiresAttentionFromCurrentUser(report, currentUserEmail, currentUserAccountID); // Then it should return false because the report is already approved and reimbursement is enabled expect(requiresAttention).toBe(false); @@ -12772,7 +12772,7 @@ describe('ReportUtils', () => { const reasonForAttention = getReasonAndReportActionThatRequiresAttention(expenseReport, currentUserEmail, currentUserAccountID, undefined, false); expect(reasonForAttention?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.HAS_CHILD_REPORT_AWAITING_ACTION); - const requiresAttention = requiresAttentionFromCurrentUser(expenseReport, undefined, false); + const requiresAttention = requiresAttentionFromCurrentUser(expenseReport, currentUserEmail, currentUserAccountID, undefined, false); expect(requiresAttention).toBe(true); const reasonForOptionList = reasonForReportToBeInOptionList({ @@ -12815,7 +12815,7 @@ describe('ReportUtils', () => { const reasonForAttention = getReasonAndReportActionThatRequiresAttention(expenseReport, currentUserEmail, currentUserAccountID, undefined, false); expect(reasonForAttention?.reason).toBe(undefined); - const requiresAttention = requiresAttentionFromCurrentUser(expenseReport, undefined, false); + const requiresAttention = requiresAttentionFromCurrentUser(expenseReport, currentUserEmail, currentUserAccountID, undefined, false); expect(requiresAttention).toBe(false); const reasonForOptionList = reasonForReportToBeInOptionList({ @@ -16330,7 +16330,7 @@ describe('ReportUtils', () => { expect(getOutstandingChildRequest(expenseReport).hasOutstandingChildRequest).toBe(true); // GBR shows on the workspace chat - expect(requiresAttentionFromCurrentUser(policyExpenseChat)).toBe(true); + expect(requiresAttentionFromCurrentUser(policyExpenseChat, currentUserEmail, currentUserAccountID)).toBe(true); const reason = reasonForReportToBeInOptionList({ report: policyExpenseChat, @@ -16399,7 +16399,7 @@ describe('ReportUtils', () => { expect(getOutstandingChildRequest(expenseReport)).toEqual({}); // The workspace chat still has hasOutstandingChildRequest: true, so GBR persists - expect(requiresAttentionFromCurrentUser(policyExpenseChat)).toBe(true); + expect(requiresAttentionFromCurrentUser(policyExpenseChat, currentUserEmail, currentUserAccountID)).toBe(true); const reason = reasonForReportToBeInOptionList({ report: policyExpenseChat, From a691b9da1a113def6b3beaa03a5ec4f641d17175 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 16 May 2026 18:48:51 +0530 Subject: [PATCH 3/7] Remove unused function --- src/libs/actions/IOU/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 6b698de706a8..5c71d050a3ce 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -199,10 +199,6 @@ function getAllTransactionDrafts(): NonNullable { return deprecatedCurrentUserPersonalDetails; } From a7d6a53f916292b6403561124b4ef51f6eee00d5 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 20 May 2026 17:17:53 +0530 Subject: [PATCH 4/7] Fixes for sidebarutils --- src/hooks/useSidebarOrderedReports.tsx | 8 +++++++- src/libs/SidebarUtils.ts | 14 ++++++++++++++ src/libs/UnreadIndicatorUpdater/index.ts | 2 +- src/libs/actions/IOU/index.ts | 1 - 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/hooks/useSidebarOrderedReports.tsx b/src/hooks/useSidebarOrderedReports.tsx index d38ea040deeb..c07dfa8924c6 100644 --- a/src/hooks/useSidebarOrderedReports.tsx +++ b/src/hooks/useSidebarOrderedReports.tsx @@ -86,7 +86,7 @@ function SidebarOrderedReportsContextProvider({ const [currentReportsToDisplay, setCurrentReportsToDisplay] = useState({}); const {shouldUseNarrowLayout} = useResponsiveLayout(); const {isOffline} = useNetwork(); - const {accountID} = useCurrentUserPersonalDetails(); + const {accountID, login: currentUserLogin} = useCurrentUserPersonalDetails(); const {currentReportID: currentReportIDValue} = useCurrentReportIDState(); const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue; const prevDerivedCurrentReportID = usePrevious(derivedCurrentReportID); @@ -213,6 +213,8 @@ function SidebarOrderedReportsContextProvider({ draftComments: reportsDrafts, transactions, isOffline, + currentUserLogin: currentUserLogin ?? '', + currentUserAccountID: accountID, }); } else { Log.info('[useSidebarOrderedReports] building reportsToDisplay from scratch'); @@ -225,6 +227,8 @@ function SidebarOrderedReportsContextProvider({ transactionViolations, transactions, isOffline, + currentUserLogin ?? '', + accountID, reportNameValuePairs, reportAttributes, ); @@ -245,6 +249,8 @@ function SidebarOrderedReportsContextProvider({ reportsDrafts, isOffline, clearCacheDummyCounter, + currentUserLogin, + accountID, ]); // Derive a stable boolean map indicating which reports have drafts. diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 0b1db06cbdc9..e2fa3bdd254b 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -274,6 +274,8 @@ type ShouldDisplayReportInLHNParams = { isOffline: boolean; isReportArchived?: boolean; reportAttributes?: ReportAttributesDerivedValue['reports']; + currentUserLogin: string; + currentUserAccountID: number; }; function shouldDisplayReportInLHN({ @@ -288,6 +290,8 @@ function shouldDisplayReportInLHN({ isOffline, isReportArchived, reportAttributes, + currentUserAccountID, + currentUserLogin, }: ShouldDisplayReportInLHNParams) { if (!report) { return {shouldDisplay: false}; @@ -361,6 +365,8 @@ function getReportsToDisplayInLHN( transactionViolations: OnyxCollection, transactions: OnyxCollection, isOffline: boolean, + currentUserLogin: string, + currentUserAccountID: number, reportNameValuePairs?: OnyxCollection, reportAttributes?: ReportAttributesDerivedValue['reports'], ) { @@ -387,6 +393,8 @@ function getReportsToDisplayInLHN( isOffline, isReportArchived: isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]), reportAttributes, + currentUserLogin, + currentUserAccountID, }); if (shouldDisplay) { @@ -412,6 +420,8 @@ type UpdateReportsToDisplayInLHNProps = { draftComments: OnyxCollection; transactions: OnyxCollection; isOffline: boolean; + currentUserLogin: string; + currentUserAccountID: number; }; function updateReportsToDisplayInLHN({ @@ -427,6 +437,8 @@ function updateReportsToDisplayInLHN({ draftComments, transactions, isOffline, + currentUserLogin, + currentUserAccountID, }: UpdateReportsToDisplayInLHNProps) { // Use a lazy copy to avoid creating a new object reference when no entries actually change. let displayedReportsCopy: ReportsToDisplayInLHN | undefined; @@ -462,6 +474,8 @@ function updateReportsToDisplayInLHN({ isOffline, isReportArchived: isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`] ?? {}), reportAttributes, + currentUserLogin, + currentUserAccountID, }); if (shouldDisplay) { diff --git a/src/libs/UnreadIndicatorUpdater/index.ts b/src/libs/UnreadIndicatorUpdater/index.ts index e701e0d2cc41..548cea2d76e1 100644 --- a/src/libs/UnreadIndicatorUpdater/index.ts +++ b/src/libs/UnreadIndicatorUpdater/index.ts @@ -12,7 +12,7 @@ import type {Report, ReportActions, ReportNameValuePairs, Session} from '@src/ty import updateUnread from './updateUnread'; let allReports: OnyxCollection = {}; -let currentUserAccountID = CONST.DEFAULT_NUMBER_ID; +let currentUserAccountID: number = CONST.DEFAULT_NUMBER_ID; let currentUserLogin = ''; Onyx.connectWithoutView({ diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index ec4754c1b900..7addf1cea3df 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -219,7 +219,6 @@ export { getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllTransactionDrafts, - getUserAccountID, getCurrentUserPersonalDetails, getRecentAttendees, // eslint-disable-next-line @typescript-eslint/no-deprecated From d129febec5801c8ddfcda86e06280f0aa3860d88 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 20 May 2026 17:22:32 +0530 Subject: [PATCH 5/7] Refactor function --- src/hooks/useSidebarOrderedReports.tsx | 14 ++++----- src/libs/SidebarUtils.ts | 41 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/hooks/useSidebarOrderedReports.tsx b/src/hooks/useSidebarOrderedReports.tsx index c07dfa8924c6..93c3bb71aadf 100644 --- a/src/hooks/useSidebarOrderedReports.tsx +++ b/src/hooks/useSidebarOrderedReports.tsx @@ -218,20 +218,20 @@ function SidebarOrderedReportsContextProvider({ }); } else { Log.info('[useSidebarOrderedReports] building reportsToDisplay from scratch'); - reportsToDisplay = SidebarUtils.getReportsToDisplayInLHN( - derivedCurrentReportID, - chatReports, + reportsToDisplay = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: derivedCurrentReportID, + reports: chatReports, betas, priorityMode, - reportsDrafts, + draftComments: reportsDrafts, transactionViolations, transactions, isOffline, - currentUserLogin ?? '', - accountID, + currentUserLogin: currentUserLogin ?? '', + currentUserAccountID: accountID, reportNameValuePairs, reportAttributes, - ); + }); } return reportsToDisplay; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index e2fa3bdd254b..9db647aaef81 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -356,20 +356,33 @@ function shouldDisplayReportInLHN({ return {shouldDisplay}; } -function getReportsToDisplayInLHN( - currentReportId: string | undefined, - reports: OnyxCollection, - betas: OnyxEntry, - priorityMode: OnyxEntry, - draftComments: OnyxCollection, - transactionViolations: OnyxCollection, - transactions: OnyxCollection, - isOffline: boolean, - currentUserLogin: string, - currentUserAccountID: number, - reportNameValuePairs?: OnyxCollection, - reportAttributes?: ReportAttributesDerivedValue['reports'], -) { +function getReportsToDisplayInLHN({ + currentReportId, + reports, + betas, + priorityMode, + draftComments, + transactionViolations, + transactions, + isOffline, + currentUserLogin, + currentUserAccountID, + reportNameValuePairs, + reportAttributes, +}: { + currentReportId: string | undefined; + reports: OnyxCollection; + betas: OnyxEntry; + priorityMode: OnyxEntry; + draftComments: OnyxCollection; + transactionViolations: OnyxCollection; + transactions: OnyxCollection; + isOffline: boolean; + currentUserLogin: string; + currentUserAccountID: number; + reportNameValuePairs?: OnyxCollection; + reportAttributes?: ReportAttributesDerivedValue['reports']; +}) { const isInFocusMode = priorityMode === CONST.PRIORITY_MODE.GSD; const allReportsDictValues = reports ?? {}; const reportsToDisplay: ReportsToDisplayInLHN = {}; From 77138089df9edd879dbec09a587f0bb8638b41ae Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Thu, 21 May 2026 21:29:46 +0530 Subject: [PATCH 6/7] Fix tests --- tests/unit/SidebarUtilsTest.ts | 151 ++++++++++++++++++++++++++------- 1 file changed, 122 insertions(+), 29 deletions(-) diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index b042ebcd5e95..8c392deaf74b 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -899,6 +899,8 @@ describe('SidebarUtils', () => { draftComment: undefined, transactions: MOCK_TRANSACTIONS, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toStrictEqual({shouldDisplay: true, hasErrorsOtherThanFailedReceipt: true}); @@ -1008,6 +1010,8 @@ describe('SidebarUtils', () => { draftComment: undefined, transactions: MOCK_TRANSACTIONS, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toStrictEqual({shouldDisplay: true, hasErrorsOtherThanFailedReceipt: true}); @@ -1024,6 +1028,8 @@ describe('SidebarUtils', () => { draftComment: undefined, transactions: {}, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toStrictEqual({shouldDisplay: false}); @@ -1043,6 +1049,8 @@ describe('SidebarUtils', () => { draftComment: undefined, transactions: {}, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toStrictEqual({shouldDisplay: false}); @@ -1064,6 +1072,8 @@ describe('SidebarUtils', () => { draftComment: undefined, transactions: {}, isOffline: true, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toBeDefined(); @@ -1086,6 +1096,8 @@ describe('SidebarUtils', () => { draftComment: undefined, transactions: {}, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toBeDefined(); @@ -3824,6 +3836,8 @@ describe('SidebarUtils', () => { reportAttributes: undefined, draftComments: {}, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).toBe(displayedReports); @@ -3846,6 +3860,8 @@ describe('SidebarUtils', () => { reportAttributes: undefined, draftComments: {}, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).not.toBe(displayedReports); @@ -3855,35 +3871,39 @@ describe('SidebarUtils', () => { describe('getReportsToDisplayInLHN', () => { it('should return an empty object when reports is undefined', () => { - const result = SidebarUtils.getReportsToDisplayInLHN( - '1', // currentReportId - undefined, // reports - [], // betas - CONST.PRIORITY_MODE.DEFAULT, // priorityMode - {}, // draftComments - {}, // transactionViolations - {}, // transactions - false, // isOffline - {}, // reportNameValuePairs - undefined, // reportAttributes - ); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: '1', + reports: undefined as unknown as OnyxCollection, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations: {}, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); expect(result).toEqual({}); }); it('should return an empty object when reports is empty', () => { - const result = SidebarUtils.getReportsToDisplayInLHN( - '1', // currentReportId - {}, // reports - [], // betas - CONST.PRIORITY_MODE.DEFAULT, // priorityMode - {}, // draftComments - {}, // transactionViolations - {}, // transactions - false, // isOffline - {}, // reportNameValuePairs - undefined, // reportAttributes - ); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: '1', + reports: {}, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations: {}, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); expect(result).toEqual({}); }); @@ -3893,7 +3913,20 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT}1`]: undefined, }; - const result = SidebarUtils.getReportsToDisplayInLHN('1', reports, [], CONST.PRIORITY_MODE.DEFAULT, {}, {}, {}, false, {}, undefined); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: '1', + reports, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations: {}, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); expect(result).toEqual({}); }); @@ -3907,7 +3940,20 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT}1`]: report, }; - const result = SidebarUtils.getReportsToDisplayInLHN('1', reports, [], CONST.PRIORITY_MODE.DEFAULT, {}, {}, {}, false, {}, undefined); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: '1', + reports, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations: {}, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); // The function should run without errors with isOffline=false expect(result).toBeDefined(); @@ -3922,7 +3968,20 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT}1`]: report, }; - const result = SidebarUtils.getReportsToDisplayInLHN('1', reports, [], CONST.PRIORITY_MODE.DEFAULT, {}, {}, {}, true, {}, undefined); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: '1', + reports, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations: {}, + transactions: {}, + isOffline: true, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); // The function should run without errors with isOffline=true expect(result).toBeDefined(); @@ -3937,7 +3996,20 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT}1`]: report, }; - const result = SidebarUtils.getReportsToDisplayInLHN('1', reports, [], CONST.PRIORITY_MODE.DEFAULT, {}, {}, {}, false, {}, undefined); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: '1', + reports, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations: {}, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); expect(result[`${ONYXKEYS.COLLECTION.REPORT}1`]).toBeUndefined(); }); @@ -3962,7 +4034,20 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}1`]: 'draft for report 1', }; - const result = SidebarUtils.getReportsToDisplayInLHN(undefined, reports, [], CONST.PRIORITY_MODE.DEFAULT, draftComments, {}, {}, false, {}, undefined); + const result = SidebarUtils.getReportsToDisplayInLHN({ + currentReportId: undefined, + reports, + betas: [], + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments, + transactionViolations: {}, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + reportNameValuePairs: {}, + reportAttributes: undefined, + }); // Should not throw and should return a valid result expect(result).toBeDefined(); @@ -3989,6 +4074,8 @@ describe('SidebarUtils', () => { reportAttributes: undefined, draftComments: {}, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); // No changes expected since the updated key doesn't exist in reports @@ -4014,6 +4101,8 @@ describe('SidebarUtils', () => { reportAttributes: undefined, draftComments: {}, isOffline: true, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); // No changes expected since the updated key doesn't exist in reports @@ -4037,6 +4126,8 @@ describe('SidebarUtils', () => { reportAttributes: undefined, draftComments: {}, isOffline: true, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); expect(result).not.toBe(displayedReports); @@ -4071,6 +4162,8 @@ describe('SidebarUtils', () => { reportAttributes: undefined, draftComments, isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, }); // Should not throw and should return a valid result From 5b4455f6998445fbcf5da0698cfff23fe08889e4 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 22 May 2026 22:13:18 +0530 Subject: [PATCH 7/7] fixes --- tests/perf-test/SidebarUtils.perf-test.ts | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 8efb20580602..78061e67af3e 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -94,11 +94,39 @@ describe('SidebarUtils', () => { test('[SidebarUtils] getReportsToDisplayInLHN on 15k reports for default priorityMode', async () => { await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getReportsToDisplayInLHN(currentReportId, allReports, mockedBetas, CONST.PRIORITY_MODE.DEFAULT, {}, transactionViolations, {}, false)); + await measureFunction(() => + SidebarUtils.getReportsToDisplayInLHN({ + currentReportId, + reports: allReports, + betas: mockedBetas, + priorityMode: CONST.PRIORITY_MODE.DEFAULT, + draftComments: {}, + transactionViolations, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: 1, + reportNameValuePairs: {}, + }), + ); }); test('[SidebarUtils] getReportsToDisplayInLHN on 15k reports for GSD priorityMode', async () => { await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getReportsToDisplayInLHN(currentReportId, allReports, mockedBetas, CONST.PRIORITY_MODE.GSD, {}, transactionViolations, {}, false)); + await measureFunction(() => + SidebarUtils.getReportsToDisplayInLHN({ + currentReportId, + reports: allReports, + betas: mockedBetas, + priorityMode: CONST.PRIORITY_MODE.GSD, + draftComments: {}, + transactionViolations, + transactions: {}, + isOffline: false, + currentUserLogin: CURRENT_USER_LOGIN, + currentUserAccountID: 1, + reportNameValuePairs: {}, + }), + ); }); });