Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chat doesn't scroll when splitting expense #54863

2 changes: 2 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}} : {}),
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnyxEntry<ReportAction>>((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<OnyxEntry<Report>>((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', () => {
Expand Down