From f873621b07925ac1780c6f248a4929b1b4e7df00 Mon Sep 17 00:00:00 2001 From: Linh Date: Thu, 26 Feb 2026 17:00:01 +0700 Subject: [PATCH 1/8] refactor: make getLastMessageTextForReport pure function receive currentUserLogin --- src/libs/ModifiedExpenseMessage.ts | 2 +- src/libs/OptionsListUtils/index.ts | 5 ++++- src/libs/SidebarUtils.ts | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 6fb2bd04d88a..3093e29a1eda 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -526,7 +526,7 @@ function getForReportAction({ if (policyRulesModifiedFields && rulePolicyID) { // eslint-disable-next-line @typescript-eslint/no-deprecated const rulePolicy = getPolicy(rulePolicyID); - const hasPolicyRuleAccess = !!rulePolicy?.areRulesEnabled && isPolicyAdmin(rulePolicy, storedCurrentUserLogin); + const hasPolicyRuleAccess = !!rulePolicy?.areRulesEnabled && isPolicyAdmin(rulePolicy, currentUserLogin); // eslint-disable-next-line @typescript-eslint/no-deprecated return getPolicyRulesModifiedMessage(translateLocal, policyRulesModifiedFields, rulePolicyID, hasPolicyRuleAccess); } diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index d21afff5e9e3..d51c76b4656e 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -620,7 +620,7 @@ function getLastMessageTextForReport({ lastAction?: OnyxEntry; reportAttributesDerived?: ReportAttributesDerivedValue['reports']; policyTags?: OnyxEntry; - currentUserLogin?: string; + currentUserLogin: string; }): string { const reportID = report?.reportID; const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived); @@ -747,6 +747,7 @@ function getLastMessageTextForReport({ movedFromReport, movedToReport, policyForMovingExpensesID, + currentUserLogin, }); lastMessageTextFromReport = formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true); } else if (isMovedTransactionAction(lastReportAction)) { @@ -1034,6 +1035,7 @@ function createOption( // If displaying chat preview line is needed, let's overwrite the default alternate text const lastActorDetails = personalDetails?.[report?.lastActorAccountID ?? String(CONST.DEFAULT_NUMBER_ID)] ?? {}; + const currentUserLogin = personalDetails?.[currentUserAccountID]?.login ?? ''; // eslint-disable-next-line @typescript-eslint/no-deprecated const translateFn = translate ?? translateLocal; result.lastMessageText = getLastMessageTextForReport({ @@ -1044,6 +1046,7 @@ function createOption( chatReport, visibleReportActionsDataParam: visibleReportActionsData, reportAttributesDerived, + currentUserLogin, }); result.alternateText = showPersonalDetails && personalDetail?.login diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index ac22d4c53e58..df5e697899f5 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -841,6 +841,7 @@ function getOptionData({ const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, currentUserAccountID); let lastMessageTextFromReport = lastMessageTextFromReportProp; if (!lastMessageTextFromReport) { + const currentUserLogin = personalDetails[currentUserAccountID]?.login ?? ''; lastMessageTextFromReport = getLastMessageTextForReport({ translate, report, @@ -852,6 +853,7 @@ function getOptionData({ reportMetadata, reportAttributesDerived, lastAction, + currentUserLogin, }); } From 18e505c5780cd1ccfa8972969b9ca48774280358 Mon Sep 17 00:00:00 2001 From: Linh Date: Thu, 26 Feb 2026 18:10:24 +0700 Subject: [PATCH 2/8] refactor: make getLastMessageTextForReport pure function receive currentUserLogin --- .../Search/SearchFiltersChatsSelector.tsx | 2 +- src/libs/OptionsListUtils/index.ts | 16 ++++++++-------- tests/unit/OptionsListUtilsTest.tsx | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/components/Search/SearchFiltersChatsSelector.tsx b/src/components/Search/SearchFiltersChatsSelector.tsx index 9f2cea9fae5b..29bf62ba0ab4 100644 --- a/src/components/Search/SearchFiltersChatsSelector.tsx +++ b/src/components/Search/SearchFiltersChatsSelector.tsx @@ -73,7 +73,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, chatReport, privateIsArchived, reportAttributesDerived), ); const isReportArchived = !!privateIsArchived; - const alternateText = getAlternateText(report, {}, isReportArchived, currentUserAccountID, {}, undefined, undefined, reportAttributesDerived); + const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, {}, undefined, undefined, reportAttributesDerived); return {...report, alternateText}; }); diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index d51c76b4656e..b2419ba17fec 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -429,7 +429,7 @@ function getAlternateText( option: OptionData, {showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig, isReportArchived: boolean | undefined, - currentUserAccountID: number, + currentUserLogin: string, lastActorDetails: Partial | null = {}, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, translate?: LocalizedTranslate, @@ -454,6 +454,7 @@ function getAlternateText( chatReport, visibleReportActionsDataParam: visibleReportActionsData, reportAttributesDerived, + currentUserLogin, }); const reportPrefix = getReportSubtitlePrefix(report); const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText; @@ -1055,7 +1056,7 @@ function createOption( result, {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, - currentUserAccountID, + currentUserLogin, lastActorDetails, visibleReportActionsData, translateFn, @@ -2216,7 +2217,7 @@ function isValidReport(option: SearchOption, policy: OnyxEntry, function prepareReportOptionsForDisplay( options: Array>, policiesCollection: OnyxCollection, - currentUserAccountID: number, + currentUserLogin: string, config: GetValidReportsConfig, visibleReportActionsData: VisibleReportActionsDerivedValue = {}, reportAttributesDerived?: ReportAttributesDerivedValue['reports'], @@ -2245,7 +2246,6 @@ function prepareReportOptionsForDisplay( continue; } const report = option.item; - /** * By default, generated options does not have the chat preview line enabled. * If showChatPreviewLine or forcePolicyNamePreview are true, let's generate and overwrite the alternate text. @@ -2254,7 +2254,7 @@ function prepareReportOptionsForDisplay( option, {showChatPreviewLine, forcePolicyNamePreview}, !!option.private_isArchived, - currentUserAccountID, + currentUserLogin, null, visibleReportActionsData, undefined, @@ -2492,7 +2492,7 @@ function getValidOptions( selfDMChat = prepareReportOptionsForDisplay( selfDMChats, policiesCollection, - currentUserAccountID, + currentUserEmail, { ...getValidReportsConfig, selectedOptions, @@ -2513,7 +2513,7 @@ function getValidOptions( recentReportOptions = prepareReportOptionsForDisplay( recentReportOptions, policiesCollection, - currentUserAccountID, + currentUserEmail, { ...getValidReportsConfig, selectedOptions, @@ -2530,7 +2530,7 @@ function getValidOptions( workspaceChats = prepareReportOptionsForDisplay( workspaceChats, policiesCollection, - currentUserAccountID, + currentUserEmail, { ...getValidReportsConfig, selectedOptions, diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 655153408f9f..31b82bbab00a 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -4325,6 +4325,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(getMovedTransactionMessage(translateLocal, movedTransactionAction))); }); @@ -4349,6 +4350,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(translate(CONST.LOCALES.EN, 'iou.automaticallySubmitted'))); }); @@ -4374,6 +4376,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(translate(CONST.LOCALES.EN, 'iou.automaticallyApproved'))); }); @@ -4399,6 +4402,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(translate(CONST.LOCALES.EN, 'iou.automaticallyForwarded'))); }); @@ -4421,6 +4425,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(translate(CONST.LOCALES.EN, 'workspaceActions.forcedCorporateUpgrade'))); }); @@ -4442,6 +4447,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(getCustomTaxNameUpdateMessage(translateLocal, action)); }); @@ -4462,6 +4468,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(getCurrencyDefaultTaxUpdateMessage(translateLocal, action)); }); @@ -4482,6 +4489,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(getForeignCurrencyDefaultTaxUpdateMessage(translateLocal, action)); }); @@ -4502,6 +4510,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(getChangedApproverActionMessage(translateLocal, takeControlAction))); }); @@ -4522,6 +4531,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(getChangedApproverActionMessage(translateLocal, rerouteAction))); }); @@ -4542,6 +4552,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(Parser.htmlToText(getMovedActionMessage(translateLocal, movedAction, report))); }); @@ -4566,6 +4577,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); // Then it should return the DYNAMIC_EXTERNAL_WORKFLOW_ROUTED message @@ -4592,6 +4604,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(result).toBe(expectedVisibleText); }); @@ -4609,6 +4622,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(translateLocal('report.noActivityYet')); }); @@ -4638,6 +4652,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); const transactions = getReportTransactions(report.reportID); const scanningTransactions = transactions.filter((transaction) => isScanning(transaction)); @@ -4676,6 +4691,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(result).toBe(''); }); @@ -4727,6 +4743,7 @@ describe('OptionsListUtils', () => { policy, reportMetadata, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(translate(CONST.LOCALES.EN, 'iou.queuedToSubmitViaDEW')); }); @@ -4759,6 +4776,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(customErrorMessage); }); @@ -4788,6 +4806,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(lastMessage).toBe(translate(CONST.LOCALES.EN, 'iou.error.genericCreateFailureMessage')); }); From f9707b13335fbda4857b68e6cec77bc90ae8afb7 Mon Sep 17 00:00:00 2001 From: Linh Date: Thu, 26 Feb 2026 18:23:51 +0700 Subject: [PATCH 3/8] refactor: make getMovedFromOrToReportMessage pure function receive currentUserLogin --- src/libs/ModifiedExpenseMessage.ts | 17 +++++++++++------ tests/unit/ModifiedExpenseMessageTest.ts | 16 ++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 3093e29a1eda..b1473e8a9412 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -160,7 +160,7 @@ function getForDistanceRequest(translate: LocalizedTranslate, newMerchant: strin }); } -function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destinationReport: OnyxEntry) { +function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destinationReport: OnyxEntry, currentUserLogin: string): string { const rootParentReport = getRootParentReport({report: destinationReport}); // In OldDot, expenses could be moved to a self-DM. Return the corresponding message for this case. if (isSelfDM(rootParentReport)) { @@ -169,7 +169,7 @@ function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destination // In NewDot, the "Move report" flow only supports moving expenses from self-DM to: // - A policy expense chat // - A 1:1 DM - const currentUserAccountID = getPersonalDetailByEmail(storedCurrentUserLogin)?.accountID; + const currentUserAccountID = getPersonalDetailByEmail(currentUserLogin)?.accountID; const reportName = isPolicyExpenseChat(rootParentReport) ? getPolicyExpenseChatName({report: rootParentReport}) : buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID}); @@ -190,9 +190,14 @@ function getMovedReportID(reportAction: OnyxEntry, type: ValueOf | undefined, movedToReport: OnyxEntry | undefined): string | undefined { +function getMovedFromOrToReportMessage( + translate: LocalizedTranslate, + movedFromReport: OnyxEntry | undefined, + movedToReport: OnyxEntry | undefined, + currentUserLogin: string, +): string | undefined { if (movedToReport) { - return getForExpenseMovedFromSelfDM(translate, movedToReport); + return getForExpenseMovedFromSelfDM(translate, movedToReport, currentUserLogin); } if (movedFromReport) { @@ -273,7 +278,7 @@ function getForReportAction({ } // eslint-disable-next-line @typescript-eslint/no-deprecated - const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translateLocal, movedFromReport, movedToReport); + const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translateLocal, movedFromReport, movedToReport, currentUserLogin); if (movedFromOrToReportMessage) { return movedFromOrToReportMessage; } @@ -585,7 +590,7 @@ function getForReportActionTemp({ return ''; } - const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport); + const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport, currentUserLogin); if (movedFromOrToReportMessage) { return movedFromOrToReportMessage; } diff --git a/tests/unit/ModifiedExpenseMessageTest.ts b/tests/unit/ModifiedExpenseMessageTest.ts index 32bddfe237fd..5ece2480122d 100644 --- a/tests/unit/ModifiedExpenseMessageTest.ts +++ b/tests/unit/ModifiedExpenseMessageTest.ts @@ -24,7 +24,7 @@ jest.mock('@libs/PolicyUtils', () => ({ const MOVED_TO_REPORT_ID = '1'; const MOVED_FROM_REPORT_ID = '2'; - +const CURRENT_USER_LOGIN = 'test@example.com'; describe('ModifiedExpenseMessage', () => { beforeAll(() => { IntlStore.load(CONST.LOCALES.EN); @@ -104,13 +104,13 @@ describe('ModifiedExpenseMessage', () => { describe('when moving to a report', () => { it('returns "moved expense to personal space" message when moving an expense to selfDM', () => { const selfDMReport = createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM); - const result = getMovedFromOrToReportMessage(translateLocal, undefined, selfDMReport); + const result = getMovedFromOrToReportMessage(translateLocal, undefined, selfDMReport, CURRENT_USER_LOGIN); const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedToPersonalSpace'); expect(result).toEqual(expectedResult); }); it('returns "moved expense from personal space to chat with reportName" message when moving an expense to policy expense chat with only reportName', () => { const policyExpenseReport = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); - const result = getMovedFromOrToReportMessage(translateLocal, undefined, policyExpenseReport); + const result = getMovedFromOrToReportMessage(translateLocal, undefined, policyExpenseReport, CURRENT_USER_LOGIN); const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromPersonalSpace', {reportName: policyExpenseReport.reportName}); expect(result).toEqual(expectedResult); }); @@ -119,7 +119,7 @@ describe('ModifiedExpenseMessage', () => { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT), policyName: 'Policy', }; - const result = getMovedFromOrToReportMessage(translateLocal, undefined, policyExpenseReport); + const result = getMovedFromOrToReportMessage(translateLocal, undefined, policyExpenseReport, CURRENT_USER_LOGIN); const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromPersonalSpace', { reportName: policyExpenseReport.reportName, workspaceName: policyExpenseReport.policyName, @@ -131,7 +131,7 @@ describe('ModifiedExpenseMessage', () => { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT), reportName: '', }; - const result = getMovedFromOrToReportMessage(translateLocal, undefined, policyExpenseReport); + const result = getMovedFromOrToReportMessage(translateLocal, undefined, policyExpenseReport, CURRENT_USER_LOGIN); const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.changedTheExpense'); expect(result).toEqual(expectedResult); }); @@ -143,7 +143,7 @@ describe('ModifiedExpenseMessage', () => { }; it('returns "moved expense from reportName" message', () => { - const result = getMovedFromOrToReportMessage(translateLocal, movedFromReport, undefined); + const result = getMovedFromOrToReportMessage(translateLocal, movedFromReport, undefined, CURRENT_USER_LOGIN); const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromReport', movedFromReport.reportName ?? ''); expect(result).toEqual(expectedResult); }); @@ -153,7 +153,7 @@ describe('ModifiedExpenseMessage', () => { ...createRandomReport(1, undefined), reportName: '', }; - const result = getMovedFromOrToReportMessage(translateLocal, reportWithoutName, undefined); + const result = getMovedFromOrToReportMessage(translateLocal, reportWithoutName, undefined, CURRENT_USER_LOGIN); const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromReport', ''); expect(result).toEqual(expectedResult); @@ -161,7 +161,7 @@ describe('ModifiedExpenseMessage', () => { }); it('returns undefined when neither movedToReport nor movedFromReport is provided', () => { - const result = getMovedFromOrToReportMessage(translateLocal, undefined, undefined); + const result = getMovedFromOrToReportMessage(translateLocal, undefined, undefined, CURRENT_USER_LOGIN); expect(result).toBeUndefined(); }); }); From 942bffa50ec57110d64a57d642e80ebc2e008d3d Mon Sep 17 00:00:00 2001 From: Linh Date: Thu, 26 Feb 2026 18:29:57 +0700 Subject: [PATCH 4/8] chore: typecheck fail --- tests/unit/OptionsListUtilsTest.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 31b82bbab00a..2f6d40170062 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -6202,6 +6202,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport, + currentUserLogin: CURRENT_USER_EMAIL, }); // The function should return a string (may be empty string) @@ -6220,6 +6221,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(typeof result).toBe('string'); From 632e2f5108ba9dc1c5fee76dbc6cd83a1ef6d6eb Mon Sep 17 00:00:00 2001 From: Linh Date: Thu, 26 Feb 2026 20:26:30 +0700 Subject: [PATCH 5/8] chore: write unit test for getMovedFromOrToReportMessage --- tests/unit/ModifiedExpenseMessageTest.ts | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit/ModifiedExpenseMessageTest.ts b/tests/unit/ModifiedExpenseMessageTest.ts index 5ece2480122d..17869c8fb44d 100644 --- a/tests/unit/ModifiedExpenseMessageTest.ts +++ b/tests/unit/ModifiedExpenseMessageTest.ts @@ -1,12 +1,16 @@ +import Onyx from 'react-native-onyx'; import {getEnvironmentURL} from '@libs/Environment/Environment'; import {getForReportAction, getForReportActionTemp, getMovedFromOrToReportMessage, getMovedReportID} from '@libs/ModifiedExpenseMessage'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as PolicyUtils from '@libs/PolicyUtils'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking +import * as ReportNameUtils from '@libs/ReportNameUtils'; +// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import {translate} from '@src/libs/Localize'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy} from '@src/types/onyx'; import type {OriginalMessageModifiedExpense} from '@src/types/onyx/OriginalMessage'; import createRandomReportAction from '../utils/collections/reportActions'; @@ -22,6 +26,12 @@ jest.mock('@libs/PolicyUtils', () => ({ isPolicyAdmin: jest.fn(), })); +// Mock ReportNameUtils so buildReportNameFromParticipantNames is controllable. +jest.mock('@libs/ReportNameUtils', () => ({ + ...jest.requireActual('@libs/ReportNameUtils'), + buildReportNameFromParticipantNames: jest.fn(), +})); + const MOVED_TO_REPORT_ID = '1'; const MOVED_FROM_REPORT_ID = '2'; const CURRENT_USER_LOGIN = 'test@example.com'; @@ -135,6 +145,26 @@ describe('ModifiedExpenseMessage', () => { const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.changedTheExpense'); expect(result).toEqual(expectedResult); }); + it('returns "moved from personal space to reportName" message when moving an expense to a 1:1 DM', async () => { + const mockAccountID = 12345; + const dmReportName = 'John Doe'; + const dmReport = createRandomReport(1, undefined); + + await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { + [mockAccountID]: {accountID: mockAccountID, login: CURRENT_USER_LOGIN}, + }); + + (ReportNameUtils.buildReportNameFromParticipantNames as jest.Mock).mockImplementation(({currentUserAccountID}) => { + if (currentUserAccountID === mockAccountID) { + return dmReportName; + } + return ''; + }); + + const result = getMovedFromOrToReportMessage(translateLocal, undefined, dmReport, CURRENT_USER_LOGIN); + const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromPersonalSpace', {reportName: dmReportName}); + expect(result).toEqual(expectedResult); + }); }); describe('when moving from a report', () => { From 64eaca8ed53c3556a3beed573199084809c41a4a Mon Sep 17 00:00:00 2001 From: Linh Date: Sun, 1 Mar 2026 12:22:01 +0700 Subject: [PATCH 6/8] chore: disable eslint for testing --- tests/unit/ModifiedExpenseMessageTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ModifiedExpenseMessageTest.ts b/tests/unit/ModifiedExpenseMessageTest.ts index 99e0cca569a3..bef7cdcfdfce 100644 --- a/tests/unit/ModifiedExpenseMessageTest.ts +++ b/tests/unit/ModifiedExpenseMessageTest.ts @@ -3,7 +3,7 @@ import {getEnvironmentURL} from '@libs/Environment/Environment'; import {getForReportAction, getForReportActionTemp, getMovedFromOrToReportMessage, getMovedReportID} from '@libs/ModifiedExpenseMessage'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as PolicyUtils from '@libs/PolicyUtils'; -// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking +// eslint-disable-next-line no-restricted-syntax, no-restricted-imports -- this is required to allow mocking import * as ReportNameUtils from '@libs/ReportNameUtils'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as ReportUtils from '@libs/ReportUtils'; From 794211bf96bd7ed50aa2492f104b795727fa064c Mon Sep 17 00:00:00 2001 From: Linh Date: Sun, 1 Mar 2026 12:51:26 +0700 Subject: [PATCH 7/8] chore: make currentUserLogin required --- .../LHNOptionsList/OptionRowLHNData.tsx | 2 +- src/libs/OptionsListUtils/index.ts | 2 +- src/libs/SidebarUtils.ts | 4 +-- tests/unit/SidebarUtilsTest.ts | 35 +++++++++++++++---- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index 3352f5769930..ae6b2f6e88ec 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -86,7 +86,7 @@ function OptionRowLHNData({ currentUserAccountID, reportAttributesDerived, policyTags, - currentUserLogin: login, + currentUserLogin: login ?? '', }); if (deepEqual(item, optionItemRef.current)) { return optionItemRef.current; diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index b2419ba17fec..ec8895c54402 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -740,7 +740,7 @@ function getLastMessageTextForReport({ movedFromReport, movedToReport, policyTags, - currentUserLogin: currentUserLogin ?? '', + currentUserLogin, }) : getForReportAction({ reportAction: lastReportAction, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index b1402a205178..db115c66a401 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -698,7 +698,7 @@ function getOptionData({ visibleReportActionsData?: VisibleReportActionsDerivedValue; reportAttributesDerived?: ReportAttributesDerivedValue['reports']; policyTags?: OnyxEntry; - currentUserLogin?: string; + currentUserLogin: string; }): OptionData | undefined { // When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for // this method to be called after the Onyx data has been cleared out. In that case, it's fine to do @@ -829,7 +829,6 @@ function getOptionData({ const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, currentUserAccountID); let lastMessageTextFromReport = lastMessageTextFromReportProp; if (!lastMessageTextFromReport) { - const currentUserLogin = personalDetails[currentUserAccountID]?.login ?? ''; lastMessageTextFromReport = getLastMessageTextForReport({ translate, report, @@ -843,7 +842,6 @@ function getOptionData({ policyTags, currentUserLogin, lastAction, - currentUserLogin, }); } diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index 773c3e2870fd..eb07678633b6 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -37,7 +37,7 @@ jest.mock('@libs/PolicyUtils', () => ({ getConnectedIntegration: jest.fn(() => true), isPolicyAdmin: jest.fn(() => true), })); - +const CURRENT_USER_LOGIN = 'test@example.com'; describe('SidebarUtils', () => { beforeAll(async () => { Onyx.init({ @@ -357,6 +357,8 @@ describe('SidebarUtils', () => { isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, + reportAttributesDerived: undefined, }); const optionDataUnpinned = SidebarUtils.getOptionData({ @@ -377,6 +379,8 @@ describe('SidebarUtils', () => { isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, + reportAttributesDerived: undefined, }); @@ -1522,7 +1526,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, - + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1588,7 +1592,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, - + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1629,7 +1633,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, - + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1669,7 +1673,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, - + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1709,7 +1713,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, - + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1777,7 +1781,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, - + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1831,6 +1835,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(optionData?.alternateText).toBe(`test message`); @@ -1874,6 +1879,7 @@ describe('SidebarUtils', () => { isReportArchived: true, lastActionReport: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, reportAttributesDerived: undefined, }); @@ -1916,6 +1922,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(optionData?.alternateText).toBe(`test message`); @@ -2056,6 +2063,8 @@ describe('SidebarUtils', () => { isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, + reportAttributesDerived: mockReportAttributesDerived, }); @@ -2102,6 +2111,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(optionData?.alternateText).toBe(`${policy.name} ${CONST.DOT_SEPARATOR} test message`); @@ -2176,6 +2186,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: session.accountID, + currentUserLogin: CURRENT_USER_LOGIN, }); // Then the alternate text should be equal to the message of the last action prepended with the last actor display name. @@ -2239,6 +2250,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: session.accountID, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(result?.alternateText).toBe(`You: moved this report to the Three's Workspace workspace`); @@ -2293,6 +2305,7 @@ describe('SidebarUtils', () => { isReportArchived: undefined, lastMessageTextFromReport: report.lastMessageText, currentUserAccountID: session.accountID, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(result?.alternateText).toBe('You: someMessage'); @@ -2381,6 +2394,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: session.accountID, + currentUserLogin: CURRENT_USER_LOGIN, visibleReportActionsData: { [iouReportR14932.reportID]: { [linkedCreateAction.reportActionID]: true, @@ -2511,6 +2525,7 @@ describe('SidebarUtils', () => { isReportArchived: undefined, lastMessageTextFromReport: 'test action', currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(result?.alternateText).toContain(`${getReportActionMessageText(lastAction)}`); @@ -2599,6 +2614,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); expect(result?.alternateText).toBe(`One: submitted`); @@ -2699,6 +2715,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: managerID, + currentUserLogin: CURRENT_USER_LOGIN, }); const reportPreviewMessage = getReportPreviewMessage(iouReport, iouAction, true, true, null, true, lastReportPreviewAction); @@ -2800,6 +2817,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: managerID, + currentUserLogin: CURRENT_USER_LOGIN, }); const reportPreviewMessage = getReportPreviewMessage(iouReport, iouAction, true, true, null, true, lastReportPreviewAction); @@ -2833,6 +2851,7 @@ describe('SidebarUtils', () => { invoiceReceiverPolicy: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); // Then isConciergeChat should be true @@ -2864,6 +2883,7 @@ describe('SidebarUtils', () => { invoiceReceiverPolicy: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); // Then isConciergeChat should be false @@ -2894,6 +2914,7 @@ describe('SidebarUtils', () => { invoiceReceiverPolicy: undefined, isReportArchived: undefined, currentUserAccountID: 0, + currentUserLogin: CURRENT_USER_LOGIN, }); // Then isConciergeChat should be false From 7346b76e75041b56064c3c06e2f000d30cbf6c9e Mon Sep 17 00:00:00 2001 From: Linh Date: Sun, 1 Mar 2026 12:57:03 +0700 Subject: [PATCH 8/8] chore: fix test fail --- tests/perf-test/SidebarUtils.perf-test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 18f45d44cd27..792adae014fa 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -19,6 +19,7 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; const REPORTS_COUNT = 15000; const REPORT_THRESHOLD = 5; const PERSONAL_DETAILS_LIST_COUNT = 1000; +const CURRENT_USER_LOGIN = 'test@example.com'; const allReports = createCollection( (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, @@ -49,7 +50,6 @@ const mockedBetas = Object.values(CONST.BETAS); const currentReportId = '1'; const transactionViolations = {} as OnyxCollection; - describe('SidebarUtils', () => { beforeAll(() => { Onyx.init({ @@ -93,6 +93,7 @@ describe('SidebarUtils', () => { lastActionReport: undefined, isReportArchived: undefined, currentUserAccountID: 1, + currentUserLogin: CURRENT_USER_LOGIN, }), ); });