diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 4a6ecbdf0581..61d48e55e912 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1011,6 +1011,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR value: { ...chat.report, lastReadTime: DateUtils.getDBTime(), + ...(shouldCreateNewMoneyRequestReport ? {lastVisibleActionCreated: chat.reportPreviewAction.created} : {}), iouReportID: iou.report.reportID, ...outstandingChildRequest, ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), @@ -1278,6 +1279,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR value: { iouReportID: chat.report?.iouReportID, lastReadTime: chat.report?.lastReadTime, + lastVisibleActionCreated: chat.report?.lastVisibleActionCreated, pendingFields: null, hasOutstandingChildRequest: chat.report?.hasOutstandingChildRequest, ...(isNewChatReport diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index eebaed8a607d..0724249f606e 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1750,6 +1750,49 @@ describe('actions/IOU', () => { }), ); }); + + it('should update split chat report lastVisibleActionCreated to the report preview action', async () => { + // Given a workspace chat with no expenses + const workspaceReportID = '1'; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {reportID: workspaceReportID, isOwnPolicyExpenseChat: true}); + + // When the user split bill on the workspace + splitBill({ + participants: [{reportID: workspaceReportID}], + currentUserLogin: RORY_EMAIL, + currentUserAccountID: RORY_ACCOUNT_ID, + comment: '', + amount: 100, + currency: CONST.CURRENCY.USD, + merchant: 'test', + created: '', + existingSplitChatReportID: workspaceReportID, + }); + + await waitForBatchedUpdates(); + + // Then the workspace chat lastVisibleActionCreated should be updated to the report preview action created + const reportPreviewAction = await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceReportID}`, + callback: (reportActions) => { + Onyx.disconnect(connection); + resolve(Object.values(reportActions ?? {}).find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW)); + }, + }); + }); + + await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, + callback: (report) => { + Onyx.disconnect(connection); + expect(report?.lastVisibleActionCreated).toBe(reportPreviewAction?.created); + resolve(report); + }, + }); + }); + }); }); describe('payMoneyRequestElsewhere', () => {