diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 41f9c592467f..dd7d75fcd081 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6786,7 +6786,7 @@ function getExpenseReportStateAndStatus(policy: OnyxEntry, isEmptyOptimi }; } - if (isInstantSubmitEnabledLocal) { + if (isInstantSubmitEnabledLocal && !(isSubmitAndCloseLocal && isEmptyOptimisticReport)) { return { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 3f7d5bf58faa..69d1ea5b0959 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -2074,6 +2074,42 @@ describe('actions/Report', () => { }); }); + it('should create the empty report with draft status if submission is instant with approval disabled', async () => { + const accountID = 1234; + const policyID = '5678'; + // Given a policy with instant submission and approval disabled + const policy: OnyxTypes.Policy = { + ...createRandomPolicy(Number(policyID)), + isPolicyExpenseChatEnabled: true, + type: CONST.POLICY.TYPE.TEAM, + autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT, + approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL, + }; + const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); + await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); + if (parentReport?.reportID) { + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.reportID}`, parentReport); + } + + // When create new report + const optimisticReportData = Report.createNewReport({accountID}, true, false, policy); + + await waitForBatchedUpdates(); + // Then the report's status should be draft. + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticReportData.reportID}`, + callback: (report) => { + Onyx.disconnect(connection); + expect(report?.stateNum).toBe(CONST.REPORT.STATE_NUM.OPEN); + expect(report?.statusNum).toBe(CONST.REPORT.STATUS_NUM.OPEN); + + resolve(); + }, + }); + }); + }); + it('should add the report preview action to the chat snapshot when it is created', async () => { jest.spyOn(require('@src/libs/SearchQueryUtils'), 'getCurrentSearchQueryJSON').mockImplementationOnce( () =>