diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 989d480bbc4e..e7a78fb0a230 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -725,7 +725,10 @@ function getOptionData({ // Assign the actor account ID from the last action when it’s a REPORT_PREVIEW action. // to ensures that lastActorDetails.accountID is correctly set in case it's empty string if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && lastActorDetails) { - lastActorDetails.accountID = lastAction.actorAccountID; + lastActorDetails = { + ...lastActorDetails, + accountID: lastAction.actorAccountID, + }; } const lastActorDisplayName = getLastActorDisplayName(lastActorDetails); diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 9cb081824d9e..daa3a0251b7b 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -16,6 +16,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Report, ReportAction, ViolationName} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import {chatReportR14932} from '../../__mocks__/reportData/reports'; +import createRandomReportAction from '../utils/collections/reportActions'; +import getOnyxValue from '../utils/getOnyxValue'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -407,6 +409,45 @@ describe('SidebarLinksData', () => { // Then the report should not disappear in the sidebar because we are in the focus mode expect(getOptionRows()).toHaveLength(0); }); + + it('should not change the current user personal detail when a report with last action is REPORTPREVIEW is displayed', async () => { + // Given the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + + const report: Report = { + ...createReport(undefined, [1, 2], undefined, undefined, undefined, true), + lastActorAccountID: 1, + lastMessageText: '123456', + }; + + const lastReportAction: ReportAction = { + ...createRandomReportAction(2), + actionName: 'REPORTPREVIEW', + actorAccountID: 2, + message: [], + originalMessage: undefined, + person: [ + { + type: 'TEXT', + style: 'strong', + text: TEST_USER_LOGIN, + }, + ], + }; + + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + await waitForBatchedUpdatesWithAct(); + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {[lastReportAction.reportActionID]: lastReportAction}); + + await waitForBatchedUpdatesWithAct(); + + const personalDetail = await getOnyxValue(ONYXKEYS.PERSONAL_DETAILS_LIST); + expect(personalDetail?.[TEST_USER_ACCOUNT_ID]?.accountID).toBe(TEST_USER_ACCOUNT_ID); + }); }); describe('Report that should NOT be included in the LHN', () => {