Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6786,7 +6786,7 @@ function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>, isEmptyOptimi
};
}

if (isInstantSubmitEnabledLocal) {
if (isInstantSubmitEnabledLocal && !(isSubmitAndCloseLocal && isEmptyOptimisticReport)) {
return {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
Expand Down
36 changes: 36 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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(
() =>
Expand Down
Loading