Skip to content

Commit

Permalink
fix chat doesn't scroll when split bill in dm
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Feb 21, 2025
1 parent 14c5b21 commit 9b0547d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import {
isInvoiceReport as isInvoiceReportReportUtils,
isInvoiceRoom,
isMoneyRequestReport as isMoneyRequestReportReportUtils,
isOneOnOneChat,
isOpenExpenseReport as isOpenExpenseReportReportUtils,
isOpenInvoiceReport as isOpenInvoiceReportReportUtils,
isOptimisticPersonalDetail,
Expand Down Expand Up @@ -5280,7 +5281,7 @@ function createSplitsAndOnyxData(
// or, if the split is being made from the workspace chat, then the oneOnOneChatReport is the same as the splitChatReport
// in this case existingSplitChatReport will belong to the policy expense chat and we won't be
// entering code that creates optimistic personal details
if ((!hasMultipleParticipants && !existingSplitChatReportID) || isOwnPolicyExpenseChat) {
if ((!hasMultipleParticipants && !existingSplitChatReportID) || isOwnPolicyExpenseChat || isOneOnOneChat(splitChatReport)) {
oneOnOneChatReport = splitChatReport;
shouldCreateOptimisticPersonalDetails = !existingSplitChatReport && !personalDetailExists;
} else {
Expand Down
61 changes: 61 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,67 @@ describe('actions/IOU', () => {
});
});
});

it('should update split chat report lastVisibleActionCreated to the latest IOU action when split bill in a DM', async () => {
// Given a DM chat with no expenses
const reportID = '1';
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
reportID,
type: CONST.REPORT.TYPE.CHAT,
participants: {[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT},
});

// When the user split bill twice on the DM
splitBill({
participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}],
currentUserLogin: RORY_EMAIL,
currentUserAccountID: RORY_ACCOUNT_ID,
comment: '',
amount: 100,
currency: CONST.CURRENCY.USD,
merchant: 'test',
created: '',
existingSplitChatReportID: reportID,
});

await waitForBatchedUpdates();

splitBill({
participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}],
currentUserLogin: RORY_EMAIL,
currentUserAccountID: RORY_ACCOUNT_ID,
comment: '',
amount: 200,
currency: CONST.CURRENCY.USD,
merchant: 'test',
created: '',
existingSplitChatReportID: reportID,
});

await waitForBatchedUpdates();

// Then the DM lastVisibleActionCreated should be updated to the second IOU action created
const iouAction = await new Promise<OnyxEntry<ReportAction>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
callback: (reportActions) => {
Onyx.disconnect(connection);
resolve(Object.values(reportActions ?? {}).find((action) => isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.IOU) && getOriginalMessage(action)?.amount === 200));
},
});
});

const report = await new Promise<OnyxEntry<Report>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
callback: (report) => {

Check failure on line 1830 in tests/actions/IOUTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

'report' is already declared in the upper scope on line 1827 column 19

Check failure on line 1830 in tests/actions/IOUTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'report' is already declared in the upper scope on line 1827 column 19
Onyx.disconnect(connection);
resolve(report);
},
});
});
expect(report?.lastVisibleActionCreated).toBe(iouAction?.created);
});
});

describe('payMoneyRequestElsewhere', () => {
Expand Down

0 comments on commit 9b0547d

Please sign in to comment.