Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b8bcec4
perf: defer the split-save API.write behind the destination layout
Abdukhamid000 Aug 6, 2026
baec29b
perf: stop subscribing SplitExpensePage to three forward-only collect…
Abdukhamid000 Aug 6, 2026
de81e2e
perf: scan allTransactionsList once in the split-save flow
Abdukhamid000 Aug 6, 2026
19b8274
test: cover the split-save deferred write
Abdukhamid000 Aug 6, 2026
7cd2edd
perf: use API.writeWhenReady instead of deferOrExecuteWrite
Abdukhamid000 Aug 7, 2026
9a5e511
merge main into fix/97802-defer-split-save
Abdukhamid000 Aug 11, 2026
4f9b1bd
Address review: shared writeWhenReady mock, tighter tests, simpler wr…
Abdukhamid000 Aug 14, 2026
30c9fbb
fix: type the shared writeWhenReady mock without a namespace import
Abdukhamid000 Aug 15, 2026
06825e8
Address review: complete mock surface, correct barrier doc comment, n…
Abdukhamid000 Aug 15, 2026
e17365c
Merge remote-tracking branch 'origin/main' into fix/97802-defer-split…
Abdukhamid000 Aug 18, 2026
1053bd0
test: supply formatPhoneNumber and getCurrencySymbol to split flow pa…
Abdukhamid000 Aug 18, 2026
ad21c9d
Address review: read split-flow Onyx data with useOnyx instead of Ony…
Abdukhamid000 Aug 19, 2026
337eef9
Drop the SplitExpensePage subscription change; keep this PR to the de…
Abdukhamid000 Aug 19, 2026
3bd0b0c
Merge branch 'main' of https://github.com/Expensify/App into fix/9780…
Abdukhamid000 Aug 19, 2026
3f3b68d
Simplify the deferred-write comment
Abdukhamid000 Aug 24, 2026
9b60ac6
Address review: trim mock comments, assert the immediate write
Abdukhamid000 Aug 25, 2026
1b919f4
Remove tsbuildinfo files committed by mistake
Abdukhamid000 Aug 25, 2026
a9c6f84
Make the selfDM split tests exercise the branch the mock selects
Abdukhamid000 Aug 27, 2026
e41f9db
Assert the deferred write by argument, not exact call arity
Abdukhamid000 Aug 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/libs/API/__mocks__/writeWhenReady.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {ApiRequestCommandParameters, WriteCommand} from '@libs/API/types';
import type baseWrite from '@libs/API/write';
import type {WriteReadyBarrier} from '@libs/API/writeWhenReady';

import type {OnyxData} from '@src/types/onyx/Request';

import type {OnyxKey} from 'react-native-onyx';

const write = jest.requireActual<{default: typeof baseWrite}>('@libs/API/write').default;

/**
* Runs the write inline instead of holding it until its barrier resolves, so a suite sees the Onyx state the flow
* settles on. In a test that barrier usually never resolves - a transition barrier has no transition to wait on, and
* the `SAFETY_TIMEOUT_MS` fallback does not fire under the globally enabled fake timers - so deferred optimistic data
* would otherwise read back as `undefined`. Stays a `jest.fn`, so suites can still assert the command and barrier.
*/
const writeWhenReady = jest.fn(
<TCommand extends WriteCommand, TKey extends OnyxKey>(command: TCommand, apiCommandParameters: ApiRequestCommandParameters[TCommand], onyxData?: OnyxData<TKey>) =>
write(command, apiCommandParameters, onyxData),
);

/** Never settles - the `writeWhenReady` above writes inline and ignores it. A `jest.fn` so suites can assert the barrier kind. */
const createTransitionBarrier = jest.fn((): WriteReadyBarrier => () => new Promise(() => {}));

/** Re-exported from the real module so suites that feed it into timer control still read a number. */
const {SAFETY_TIMEOUT_MS} = jest.requireActual<{SAFETY_TIMEOUT_MS: number}>('@libs/API/writeWhenReady');

export {writeWhenReady, createTransitionBarrier, SAFETY_TIMEOUT_MS};
28 changes: 16 additions & 12 deletions src/libs/actions/IOU/SplitTransactionUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type {SearchActionsContextValue, SearchStateContextValue} from '@componen

import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList';

import {write as apiWrite} from '@libs/API';
import {createTransitionBarrier, write as apiWrite, writeWhenReady} from '@libs/API';
import type {RevertSplitTransactionParams, SplitTransactionParams, SplitTransactionSplitsParam} from '@libs/API/parameters';
import type {ApiRequestCommandParameters, WriteCommand} from '@libs/API/types';
import {WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
Expand Down Expand Up @@ -1981,14 +1982,24 @@ function updateSplitTransactions({
}
}

// optimisticData is applied synchronously, re-rendering the destination screen mid-transition.
// Defer the write until the transition ends, unless there is none to wait on.
const writeSplit = <TCommand extends WriteCommand>(command: TCommand, parameters: ApiRequestCommandParameters[TCommand]) => {
if (!isFromSplitExpensesFlow) {
apiWrite(command, parameters, onyxData);
return;
}
writeWhenReady(command, parameters, onyxData, createTransitionBarrier('navigation'));
};

if (isReverseSplitOperation) {
const parameters = {
...splits.at(0),
comment: splits.at(0)?.comment?.comment,
waypoints: splits.at(0)?.waypoints ? JSON.stringify(splits.at(0)?.waypoints) : undefined,
copiedComments: splits.at(0)?.copiedComments ? JSON.stringify(splits.at(0)?.copiedComments) : undefined,
} as RevertSplitTransactionParams;
apiWrite(WRITE_COMMANDS.REVERT_SPLIT_TRANSACTION, parameters, onyxData);
writeSplit(WRITE_COMMANDS.REVERT_SPLIT_TRANSACTION, parameters);
} else {
// Prepare splitApiParams for the Transaction_Split API call which requires a specific format for the splits
// The format is: splits[0][amount], splits[0][category], splits[0][tag] etc.
Expand All @@ -2004,11 +2015,7 @@ function updateSplitTransactions({
transactionID: originalTransactionID,
};

if (isCreationOfSplits) {
apiWrite(WRITE_COMMANDS.SPLIT_TRANSACTION, splitParameters, onyxData);
} else {
apiWrite(WRITE_COMMANDS.UPDATE_SPLIT_TRANSACTION, splitParameters, onyxData);
}
writeSplit(isCreationOfSplits ? WRITE_COMMANDS.SPLIT_TRANSACTION : WRITE_COMMANDS.UPDATE_SPLIT_TRANSACTION, splitParameters);
}
TransitionTracker.runAfterTransitions({callback: () => removeDraftSplitTransaction(originalTransactionID), waitForUpcomingTransition: true});
}
Expand Down Expand Up @@ -2047,11 +2054,7 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
const reverseSplitKeepsOriginalInExpenseReport = isReverseSplitOperation && splitExpenses.at(0)?.reportID === expenseReportID;
const willExpenseReportBecomeEmpty =
!!expenseReportID && areAllExpenseReportTransactionsSplitChildren && !anyRemainingSplitStaysInExpenseReport && !reverseSplitKeepsOriginalInExpenseReport;
const isLastTransactionInReport =
willExpenseReportBecomeEmpty ||
(isReverseSplitOperation &&
!reverseSplitKeepsOriginalInExpenseReport &&
Object.values(params.allTransactionsList ?? {}).filter((itemTransaction) => itemTransaction?.reportID === expenseReportID).length === 1);
const isLastTransactionInReport = willExpenseReportBecomeEmpty || (isReverseSplitOperation && !reverseSplitKeepsOriginalInExpenseReport && expenseReportTransactions.length === 1);
const fallbackReportID = params.expenseReport?.chatReportID ?? params.expenseReport?.parentReportID;

if (isLastTransactionInReport && fallbackReportID) {
Expand Down Expand Up @@ -2181,3 +2184,4 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
}

export {updateSplitTransactions, updateSplitTransactionsFromSplitExpensesFlow};
export type {UpdateSplitTransactionsParams};
1 change: 1 addition & 0 deletions tests/actions/IOU/SplitReportTotalsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jest.mock('@libs/actions/IOU/PendingNewTransactions', () => ({
deletePendingNewTransactionIDs: jest.fn(),
isOneToTwoTransactionTransition: jest.fn(() => false),
}));
jest.mock('@libs/API/writeWhenReady');
Comment thread
Abdukhamid000 marked this conversation as resolved.
Resolved
// In production, requestMoney defers its API.write() call until the target screen's
// content lays out (or a safety timeout fires). In tests there is no target component
// to flush the deferred write, so we bypass the deferral by executing the callback immediately.
Expand Down
1 change: 1 addition & 0 deletions tests/actions/IOUTest/SplitSelfDMTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jest.mock('@src/libs/actions/Report', () => {

jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn());

jest.mock('@libs/API/writeWhenReady');
Comment thread
rlinoz marked this conversation as resolved.
Resolved
jest.mock('@src/libs/SearchQueryUtils', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const actual = jest.requireActual('@src/libs/SearchQueryUtils');
Expand Down
220 changes: 220 additions & 0 deletions tests/actions/IOUTest/SplitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import {createWorkspace, generatePolicyID, setWorkspaceApprovalMode} from '@libs
import {addComment, notifyNewAction} from '@libs/actions/Report';
import initSplitExpense from '@libs/actions/SplitExpenses';
import type * as API from '@libs/API';
import type {WriteCommand} from '@libs/API/types';
import {WRITE_COMMANDS} from '@libs/API/types';
import {createTransitionBarrier, writeWhenReady} from '@libs/API/writeWhenReady';
import {getCurrencyDecimals, getCurrencySymbol} from '@libs/CurrencyUtils';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import {rand64} from '@libs/NumberUtils';
import {getIOUActionForReportID, getIOUActionForTransactionID, getOriginalMessage, isActionOfType, isAddCommentAction, isDeletedAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {buildOptimisticIOUReportAction, getAncestors, getReportOrDraftReport} from '@libs/ReportUtils';
Expand All @@ -35,6 +38,7 @@ import {
updateSplitExpenseAmountField,
updateSplitExpenseField,
} from '@userActions/IOU/SplitExpenseItems';
import type {UpdateSplitTransactionsParams} from '@userActions/IOU/SplitTransactionUpdate';
import {updateSplitTransactions, updateSplitTransactionsFromSplitExpensesFlow} from '@userActions/IOU/SplitTransactionUpdate';

import CONST from '@src/CONST';
Expand Down Expand Up @@ -121,6 +125,7 @@ jest.mock('@src/libs/actions/Report', () => {

jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn());
jest.mock('@libs/Navigation/helpers/isReportTopmostSplitNavigator', () => jest.fn());
jest.mock('@libs/API/writeWhenReady');
jest.mock('@libs/deferredLayoutWrite', () => ({
registerDeferredWrite: (_key: string, callback: () => void) => callback(),
flushDeferredWrite: jest.fn(),
Expand Down Expand Up @@ -10299,6 +10304,221 @@ describe('startSplitBill delegateAccountID forwarding', () => {
});
});

/**
* Fixture for the save tests below: an expense report with a single transaction, plus a draft that splits that
* transaction into two.
*
* `withExistingSplitChildren` also seeds those two split transactions in Onyx. That is what makes a one-item
* `splitExpenses` mean "collapse an existing split back into one expense" (a reverse split) rather than "split
* this expense into one".
*/
const buildSplitFlowParams = async ({withExistingSplitChildren = false, asSelfDMThread = false} = {}) => {
const expenseReport: Report = {
...createRandomReport(9001, undefined),
type: CONST.REPORT.TYPE.EXPENSE,
};
const transaction: Transaction = {
amount: 100,
currency: 'USD',
transactionID: '9001',
reportID: expenseReport.reportID,
created: DateUtils.getDBTime(),
merchant: 'test',
};
// `asSelfDMThread` makes the thread a selfDM child of the expense report, which is the only shape that
// reaches the navigate-first branch in `updateSplitTransactionsFromSplitExpensesFlow`.
const transactionThread: Report = {
...createRandomReport(9002, undefined),
type: CONST.REPORT.TYPE.CHAT,
...(asSelfDMThread ? {chatType: CONST.REPORT.CHAT_TYPE.SELF_DM, parentReportID: expenseReport.reportID} : {}),
};
const iouAction: ReportAction = {
...buildOptimisticIOUReportAction({
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
amount: transaction.amount,
currency: transaction.currency,
comment: '',
participants: [],
transactionID: transaction.transactionID,
iouReportID: expenseReport.reportID,
getCurrencyDecimals: getCurrencyDecimalsLocal,
}),
childReportID: transactionThread.reportID,
};

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThread.reportID}`, transactionThread);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, {[iouAction.reportActionID]: iouAction});
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction);
if (withExistingSplitChildren) {
for (const childTransactionID of ['9003', '9004']) {
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${childTransactionID}`, {
...transaction,
transactionID: childTransactionID,
amount: 50,
comment: {originalTransactionID: transaction.transactionID, source: CONST.IOU.TYPE.SPLIT},
});
}
}
await waitForBatchedUpdates();

let allTransactions: OnyxCollection<Transaction>;
let allReports: OnyxCollection<Report>;
await getOnyxData({
key: ONYXKEYS.COLLECTION.TRANSACTION,
callback: (value) => {
allTransactions = value;
},
});
await getOnyxData({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (value) => {
allReports = value;
},
});

const reports = getTransactionAndExpenseReports(asSelfDMThread ? transactionThread.reportID : expenseReport.reportID);
const params: UpdateSplitTransactionsParams = {
allTransactionsList: allTransactions,
allReportsList: allReports,
allReportActionsList: undefined,
allReportNameValuePairsList: undefined,
transactionData: {
reportID: expenseReport.reportID,
originalTransactionID: transaction.transactionID,
splitExpenses: [
{transactionID: '9003', amount: 50, description: '', category: '', tags: [''], created: transaction.created, reportID: expenseReport.reportID},
{transactionID: '9004', amount: 50, description: '', category: '', tags: [''], created: transaction.created, reportID: expenseReport.reportID},
],
splitExpensesTotal: 100,
},
searchContext: {currentSearchHash: -2},
policyCategories: undefined,
policy: undefined,
policyRecentlyUsedCategories: [],
iouReport: expenseReport,
firstIOU: iouAction,
isASAPSubmitBetaEnabled: false,
currentUserPersonalDetails,
transactionViolations: {},
policyRecentlyUsedCurrencies: [],
quickAction: undefined,
betas: [CONST.BETAS.ALL],
allPolicyTags: undefined,
personalDetails: {[RORY_ACCOUNT_ID]: {accountID: RORY_ACCOUNT_ID, login: RORY_EMAIL}},
transactionReport: reports.transactionReport,
expenseReport: reports.expenseReport,
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
getCurrencyDecimals: getCurrencyDecimalsLocal,
formatPhoneNumber,
getCurrencySymbol: getCurrencySymbolLocal,
};

return {expenseReport, iouAction, params};
};

/**
* `@libs/API` re-declares `writeWhenReady` rather than re-exporting it, and its wrapper always forwards the
* optional 5th argument. So the arity the mock records is the wrapper's, not the call site's, and asserting
* with `toHaveBeenCalledWith` breaks whenever that wrapper's signature grows. Assert the arguments this flow
* actually chooses - the command and the barrier - and ignore the rest.
*/
function expectDeferredWriteFor(command: WriteCommand) {
const deferredCall = jest.mocked(writeWhenReady).mock.calls.find(([calledCommand]) => calledCommand === command);
expect(deferredCall).toBeDefined();
expect(deferredCall?.at(3)).toEqual(expect.any(Function));
}

describe('split save deferred write', () => {
beforeEach(() => {
jest.mocked(isSearchTopmostFullScreenRoute).mockReturnValue(false);
});

it('defers the write behind a navigation barrier when saving from the split-expenses flow', async () => {
// Given a split saved through the split-expenses flow
const {params} = await buildSplitFlowParams();

// When the split is saved
updateSplitTransactionsFromSplitExpensesFlow(params);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Only one of four exit branches was measured, and two of them register the barrier after navigation has already started

updateSplitTransactionsFromSplitExpensesFlow has four exits, and the relationship between barrier registration and navigation differs across them:

  • Search / no parentReportID (line ~2113): updateSplitTransactions runs before navigateBackToLastSuperWideRHPScreen(), so the barrier registers first and waits for the upcoming transition. This is the branch you measured.
  • Last transaction in report (line ~2140): same ordering, unmeasured.
  • selfDM (line ~2064): popReportsSplitNavigatorToReport() and Navigation.dismissModal() run first, then requestAnimationFrame(() => updateSplitTransactions(...)).
  • Default (line ~2160): Navigation.dismissModalWithReport() first, then requestAnimationFrame(() => updateSplitTransactions(...)).

For the last two, by the time the barrier registers the transition may already be active, in which case runAfterTransitions takes the activeNavigationCount > 0 path and waits for it to end (fine), or it registered as 'other' with no navigation-kind transition active, in which case we eat the full 1000ms start-wait.

These are the common paths, a normal report-to-report split and the selfDM split, not edge cases.
Please post the same two-line log timing for both 🙌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not addressed yet — this needs numbers rather than a code change, and you're right that selfDM and default are common paths.

I confirmed the ordering you describe: popReportsSplitNavigatorToReport() + Navigation.dismissModal() then requestAnimationFrame(() => updateSplitTransactions(...)) around :2060, and Navigation.dismissModalWithReport() then requestAnimationFrame(...) around :2155 — versus the branch I measured, where updateSplitTransactions runs first and the barrier registers ahead of the transition.

I'll post the same two-line timing for both exits before asking for another pass. If they do register as 'other' with no navigation transition active and eat the full 1000 ms start-wait, the fix is registering the barrier before the navigation call rather than inside the requestAnimationFrame — I'll bring that here as a follow-up rather than change it silently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my reply above: on reflection I'd rather not block this PR on measuring the other two exits.

The ordering difference you identified is real and I'm not disputing it — I'd just rather land the perf win that is measured than hold the PR for the two branches that aren't.

Happy to treat it as a follow-up if you agree, or to measure now if you'd rather it land here. Your call.

await waitForBatchedUpdates();

// Then the write goes through writeWhenReady gated on a screen transition specifically, so its
// optimistic data does not land while the press is still trying to paint, and a stray modal or
// keyboard blip cannot release it early
expect(createTransitionBarrier).toHaveBeenCalledWith('navigation');
expectDeferredWriteFor(WRITE_COMMANDS.SPLIT_TRANSACTION);
});

it('navigates back to the selfDM before deferring the write when Search is not topmost', async () => {
const Navigation = jest.requireMock('@src/libs/Navigation/Navigation');

// Given a split whose transaction thread is a selfDM, the one shape that reaches the navigate-first branch
const {params} = await buildSplitFlowParams({asSelfDMThread: true});

// When it is saved while Search is not the topmost full screen route
updateSplitTransactionsFromSplitExpensesFlow(params);
await waitForBatchedUpdates();

// Then the flow navigates back to the selfDM first, so the transaction thread is off screen before the
// data changes under it. The write is still deferred, it just happens after that navigation.
expect(Navigation.dismissModal).toHaveBeenCalled();
expectDeferredWriteFor(WRITE_COMMANDS.SPLIT_TRANSACTION);
});

it('defers the write for the same selfDM split when the Search page is topmost', async () => {
const Navigation = jest.requireMock('@src/libs/Navigation/Navigation');

// Given the identical selfDM fixture, changed only by Search being the topmost full screen route
jest.mocked(isSearchTopmostFullScreenRoute).mockReturnValue(true);
Comment thread
rlinoz marked this conversation as resolved.
Resolved
const {params} = await buildSplitFlowParams({asSelfDMThread: true});

// When the split is saved
updateSplitTransactionsFromSplitExpensesFlow(params);
await waitForBatchedUpdates();

// Then the navigate-first branch is skipped and the write goes through the barrier instead
expect(Navigation.dismissModal).not.toHaveBeenCalled();
expect(createTransitionBarrier).toHaveBeenCalledWith('navigation');
expectDeferredWriteFor(WRITE_COMMANDS.SPLIT_TRANSACTION);
});

it('defers the reverse-split write behind the same barrier', async () => {
// Given an existing two-way split being collapsed back to a single expense
const {params} = await buildSplitFlowParams({withExistingSplitChildren: true});
const remainingSplit = params.transactionData.splitExpenses.at(0);

// When the reverse split is saved from the split-expenses flow
updateSplitTransactions({
...params,
transactionData: {...params.transactionData, splitExpenses: remainingSplit ? [remainingSplit] : []},
isFromSplitExpensesFlow: true,
});
await waitForBatchedUpdates();

// Then REVERT_SPLIT_TRANSACTION goes through the same fork as the creation path
expect(createTransitionBarrier).toHaveBeenCalledWith('navigation');
expectDeferredWriteFor(WRITE_COMMANDS.REVERT_SPLIT_TRANSACTION);
});

it('writes immediately when the caller is not the split-expenses flow', async () => {
// Given a direct updateSplitTransactions call, as useDeleteTransactions makes
const {params} = await buildSplitFlowParams();
const writeSpy = jest.spyOn(APIlib, 'write');

// When it runs outside the split-expenses flow
updateSplitTransactions({...params, isFromSplitExpensesFlow: false});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The reverse-split test bypasses the flow function, leaving that exit uncovered

updateSplitTransactions({...params, transactionData: {...}, isFromSplitExpensesFlow: true});

Calling updateSplitTransactions directly pins the fork, which is what the comment thread asked for, so this is fine as far as it goes. But it means the isLastTransactionInReport && fallbackReportID exit in updateSplitTransactionsFromSplitExpensesFlow (:2138) is now the only exit with no coverage at all, and it is the one where the deferred write lands after setDeleteTransactionNavigateBackUrl and navigateBackOnDeleteTransaction have already moved the user.

Routing this same case through updateSplitTransactionsFromSplitExpensesFlow instead would cover the fork and that exit in one test.

await waitForBatchedUpdates();

// Then the write still happens, it is just not deferred behind a barrier
expect(writeSpy).toHaveBeenCalledWith(WRITE_COMMANDS.SPLIT_TRANSACTION, expect.anything(), expect.anything());
expect(writeWhenReady).not.toHaveBeenCalled();
expect(createTransitionBarrier).not.toHaveBeenCalled();
Comment thread
rlinoz marked this conversation as resolved.
Resolved
writeSpy.mockRestore();
});
});

describe('resolveOptimisticSplitChatReportID', () => {
it('returns the existing chat and no optimistic ID when the participants already share one', async () => {
const reportID = 'existing-split-chat';
Expand Down
1 change: 1 addition & 0 deletions tests/actions/TransactionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jest.mock('@src/libs/actions/Report', () => {
});
jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn());
jest.mock('@libs/Navigation/helpers/isReportTopmostSplitNavigator', () => jest.fn());
jest.mock('@libs/API/writeWhenReady');
// In production, requestMoney defers its API.write() call until the target screen's
// content lays out (or a safety timeout fires). In tests there is no target component
// to flush the deferred write, so we bypass the deferral by executing the callback immediately.
Expand Down
Loading