diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index cfd57f4dfba7..4ee8f42057ef 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2813,6 +2813,13 @@ function buildNewReportOptimisticData( key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`, value: {lastVisibleActionCreated: optimisticReportPreview.created, iouReportID: reportID, ...outstandingChildRequest}, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${parentReport?.reportID}`, + value: { + hasOnceLoadedReportActions: true, + }, + }, { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 542ff0a362d4..82d22b2cb376 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1740,6 +1740,39 @@ describe('actions/Report', () => { }); }); + it('should set hasOnceLoadedReportActions for parent report metadata when creating a new report', async () => { + const accountID = 1234; + const policyID = '5678'; + const mockFetchData = fetch as MockFetch; + const policy = { + ...createRandomPolicy(Number(policyID)), + isPolicyExpenseChatEnabled: true, + type: CONST.POLICY.TYPE.TEAM, + harvesting: { + enabled: false, + }, + }; + await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); + + mockFetchData.pause(); + Report.createNewReport({accountID}, true, false, policyID); + const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); + + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${parentReport?.reportID}`, + callback: (metadata) => { + if (!metadata?.hasOnceLoadedReportActions) { + return; + } + Onyx.disconnect(connection); + expect(metadata.hasOnceLoadedReportActions).toBe(true); + resolve(); + }, + }); + }); + }); + it('should not optimistic outstandingChildRequest when create report with harvesting is enabled', async () => { const accountID = 1234; const policyID = '5678';