Skip to content

Fix - Send invoice flow becomes create expense flow #59816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
6 changes: 5 additions & 1 deletion src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ function IOURequestStepConfirmation({
: transaction?.reportID === reportID;

// Exit if the transaction already exists and is associated with the current report
if (transaction?.transactionID && (!transaction?.isFromGlobalCreate || !isEmptyObject(transaction?.participants)) && (isCurrentReportID || isMovingTransactionFromTrackExpense)) {
if (
transaction?.transactionID &&
(!transaction?.isFromGlobalCreate || !isEmptyObject(transaction?.participants)) &&
(isCurrentReportID || isMovingTransactionFromTrackExpense || iouType === CONST.IOU.TYPE.INVOICE)
) {
return;
}

Expand Down
92 changes: 92 additions & 0 deletions tests/ui/components/IOURequestStepConfirmationPageTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {render} from '@testing-library/react-native';
import React from 'react';
import Onyx from 'react-native-onyx';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxProvider from '@components/OnyxProvider';
import IOURequestStepConfirmationWithWritableReportOrNotFound from '@pages/iou/request/step/IOURequestStepConfirmation';
import ONYXKEYS from '@src/ONYXKEYS';
import * as IOU from '../../../src/libs/actions/IOU';
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';

jest.mock('@rnmapbox/maps', () => {
return {
default: jest.fn(),
MarkerView: jest.fn(),
setAccessToken: jest.fn(),
};
});
jest.mock('@react-native-community/geolocation', () => ({
setRNConfiguration: jest.fn(),
}));
jest.mock('@libs/actions/IOU', () => {
const actualNav = jest.requireActual<typeof IOU>('@libs/actions/IOU');
return {
...actualNav,
startMoneyRequest: jest.fn(),
};
});
jest.mock('@libs/Fullstory');
jest.mock('@components/ProductTrainingContext', () => ({
useProductTrainingContext: () => [false],
}));
jest.mock('@components/Tooltip/EducationalTooltip');
jest.mock('@src/hooks/useResponsiveLayout');
jest.mock('@react-navigation/native', () => ({
createNavigationContainerRef: jest.fn(),
useIsFocused: () => true,
useNavigation: () => ({navigate: jest.fn(), addListener: jest.fn()}),
useFocusEffect: jest.fn(),
// eslint-disable-next-line @typescript-eslint/naming-convention
UNSTABLE_usePreventRemove: jest.fn(),
}));

describe('IOURequestStepConfirmationPageTest', () => {
beforeAll(() => {
Onyx.init({keys: ONYXKEYS});
});

it('should not restart the money request creation flow when sending invoice from global FAB', async () => {
// Given an invoice creation flow started from global FAB menu
const TRANSACTION_ID = '1';
const routeReportID = '1';
const participantReportID = '2';

await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${TRANSACTION_ID}`, {
transactionID: TRANSACTION_ID,
isFromGlobalCreate: true,
participants: [
{
accountID: 1,
reportID: participantReportID,
iouType: 'invoice',
},
],
});

render(
<OnyxProvider>
<LocaleContextProvider>
<IOURequestStepConfirmationWithWritableReportOrNotFound
route={{
key: 'Money_Request_Step_Confirmation--30aPPAdjWan56sE5OpcG',
name: 'Money_Request_Step_Confirmation',
params: {
action: 'create',
iouType: 'invoice',
transactionID: TRANSACTION_ID,
reportID: routeReportID,
},
}}
// @ts-expect-error we don't need navigation param here.
navigation={undefined}
/>
</LocaleContextProvider>
</OnyxProvider>,
);

await waitForBatchedUpdates();

// Then startMoneyRequest should not be called from IOURequestConfirmationPage.
expect(IOU.startMoneyRequest).not.toBeCalled();
});
});