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/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/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index fd736e9aedf4..a3b72f7998af 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) { @@ -294,7 +299,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; } @@ -556,7 +561,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 getRulesModifiedMessage(translateLocal, policyRulesModifiedFields, false, rulePolicyID, hasPolicyRuleAccess); } @@ -615,7 +620,7 @@ function getForReportActionTemp({ return ''; } - const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport); + const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport, currentUserLogin); if (movedFromOrToReportMessage) { return movedFromOrToReportMessage; } diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index d21afff5e9e3..ec8895c54402 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; @@ -620,7 +621,7 @@ function getLastMessageTextForReport({ lastAction?: OnyxEntry; reportAttributesDerived?: ReportAttributesDerivedValue['reports']; policyTags?: OnyxEntry; - currentUserLogin?: string; + currentUserLogin: string; }): string { const reportID = report?.reportID; const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived); @@ -739,7 +740,7 @@ function getLastMessageTextForReport({ movedFromReport, movedToReport, policyTags, - currentUserLogin: currentUserLogin ?? '', + currentUserLogin, }) : getForReportAction({ reportAction: lastReportAction, @@ -747,6 +748,7 @@ function getLastMessageTextForReport({ movedFromReport, movedToReport, policyForMovingExpensesID, + currentUserLogin, }); lastMessageTextFromReport = formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true); } else if (isMovedTransactionAction(lastReportAction)) { @@ -1034,6 +1036,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 +1047,7 @@ function createOption( chatReport, visibleReportActionsDataParam: visibleReportActionsData, reportAttributesDerived, + currentUserLogin, }); result.alternateText = showPersonalDetails && personalDetail?.login @@ -1052,7 +1056,7 @@ function createOption( result, {showChatPreviewLine, forcePolicyNamePreview}, !!result.private_isArchived, - currentUserAccountID, + currentUserLogin, lastActorDetails, visibleReportActionsData, translateFn, @@ -2213,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'], @@ -2242,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. @@ -2251,7 +2254,7 @@ function prepareReportOptionsForDisplay( option, {showChatPreviewLine, forcePolicyNamePreview}, !!option.private_isArchived, - currentUserAccountID, + currentUserLogin, null, visibleReportActionsData, undefined, @@ -2489,7 +2492,7 @@ function getValidOptions( selfDMChat = prepareReportOptionsForDisplay( selfDMChats, policiesCollection, - currentUserAccountID, + currentUserEmail, { ...getValidReportsConfig, selectedOptions, @@ -2510,7 +2513,7 @@ function getValidOptions( recentReportOptions = prepareReportOptionsForDisplay( recentReportOptions, policiesCollection, - currentUserAccountID, + currentUserEmail, { ...getValidReportsConfig, selectedOptions, @@ -2527,7 +2530,7 @@ function getValidOptions( workspaceChats = prepareReportOptionsForDisplay( workspaceChats, policiesCollection, - currentUserAccountID, + currentUserEmail, { ...getValidReportsConfig, selectedOptions, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index dc516598fdd0..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 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, }), ); }); diff --git a/tests/unit/ModifiedExpenseMessageTest.ts b/tests/unit/ModifiedExpenseMessageTest.ts index cb4df49e0459..bef7cdcfdfce 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, 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'; 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,9 +26,15 @@ 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'; describe('ModifiedExpenseMessage', () => { beforeAll(() => { IntlStore.load(CONST.LOCALES.EN); @@ -104,13 +114,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 +129,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,10 +141,30 @@ 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); }); + 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', () => { @@ -143,7 +173,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 +183,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 +191,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(); }); }); diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 655153408f9f..2f6d40170062 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')); }); @@ -6183,6 +6202,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport, + currentUserLogin: CURRENT_USER_EMAIL, }); // The function should return a string (may be empty string) @@ -6201,6 +6221,7 @@ describe('OptionsListUtils', () => { lastActorDetails: null, isReportArchived: false, chatReport: undefined, + currentUserLogin: CURRENT_USER_EMAIL, }); expect(typeof result).toBe('string'); 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