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
3 changes: 2 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5505,7 +5505,7 @@ function buildOptimisticExpenseReport(
return expenseReport;
}

function buildOptimisticEmptyReport(reportID: string, accountID: number, parentReport: OnyxEntry<Report>, policy: OnyxEntry<Policy>, timeOfCreation: string) {
function buildOptimisticEmptyReport(reportID: string, accountID: number, parentReport: OnyxEntry<Report>, parentReportActionID: string, policy: OnyxEntry<Policy>, timeOfCreation: string) {
const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy);
const titleReportField = getTitleReportField(getReportFieldsByPolicyID(policy?.id) ?? {});
const optimisticEmptyReport: OptimisticNewReport = {
Expand All @@ -5523,6 +5523,7 @@ function buildOptimisticEmptyReport(reportID: string, accountID: number, parentR
lastVisibleActionCreated: timeOfCreation,
pendingFields: {createReport: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
parentReportID: parentReport?.reportID,
parentReportActionID,
chatReportID: parentReport?.reportID,
managerID: getSubmitToAccountID(policy, undefined),
};
Expand Down
5 changes: 4 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,7 @@ function buildNewReportOptimisticData(policy: OnyxEntry<Policy>, reportID: strin
const {accountID, login} = creatorPersonalDetails;
const timeOfCreation = DateUtils.getDBTime();
const parentReport = getPolicyExpenseChat(accountID, policy?.id);
const optimisticReportData = buildOptimisticEmptyReport(reportID, accountID, parentReport, policy, timeOfCreation);
const optimisticReportData = buildOptimisticEmptyReport(reportID, accountID, parentReport, reportPreviewReportActionID, policy, timeOfCreation);

const optimisticCreateAction = {
action: CONST.REPORT.ACTIONS.TYPE.CREATED,
Expand Down Expand Up @@ -2549,6 +2549,9 @@ function buildNewReportOptimisticData(policy: OnyxEntry<Policy>, reportID: strin
isAttachmentOnly: false,
reportActionID: reportPreviewReportActionID,
message: createReportActionMessage,
originalMessage: {
linkedReportID: reportID,
},
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};

Expand Down
19 changes: 18 additions & 1 deletion tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import OnyxUtils from 'react-native-onyx/dist/OnyxUtils';
import {WRITE_COMMANDS} from '@libs/API/types';
import HttpUtils from '@libs/HttpUtils';
import {getOriginalMessage} from '@libs/ReportActionsUtils';
import initOnyxDerivedValues from '@userActions/OnyxDerived';
import CONST from '@src/CONST';
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
Expand Down Expand Up @@ -1529,7 +1530,22 @@ describe('actions/Report', () => {
});

it('should create new report and "create report" quick action, when createNewReport gets called', async () => {
const reportID = Report.createNewReport({accountID: 1234}, '5678');
const accountID = 1234;
const policyID = '5678';
const reportID = Report.createNewReport({accountID}, policyID);
const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID);
const reportPreviewAction = await new Promise<OnyxEntry<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW>>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`,
callback: (reportActions) => {
Onyx.disconnect(connection);
const action = Object.values(reportActions ?? {}).at(0);
resolve(action as OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW>);
},
});
});
expect(getOriginalMessage(reportPreviewAction)?.linkedReportID).toBe(reportID);

await new Promise<void>((resolve) => {
const connection = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand All @@ -1541,6 +1557,7 @@ describe('actions/Report', () => {
// assert correctness of crucial onyx data
expect(createdReport?.reportID).toBe(reportID);
expect(createdReport?.total).toBe(0);
expect(createdReport?.parentReportActionID).toBe(reportPreviewAction?.reportActionID);

resolve();
},
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ describe('libs/NextStepUtils', () => {

describe('it generates and optimistic nextStep once a report has been created', () => {
test('Correct next steps message', () => {
const emptyReport = buildOptimisticEmptyReport('fake-empty-report-id-2', currentUserAccountID, {reportID: 'fake-parent-report-id-3'}, policy, '2025-03-31 13:23:11');
const emptyReport = buildOptimisticEmptyReport(
'fake-empty-report-id-2',
currentUserAccountID,
{reportID: 'fake-parent-report-id-3'},
'fake-parent-report-action-id-4',
policy,
'2025-03-31 13:23:11',
);

optimisticNextStep.message = [
{
Expand Down