diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index 37b9c3e61498..7df8864d7f6f 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -27,6 +27,7 @@ import {initMoneyRequest} from '@userActions/IOU'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; +import type {SelectedTabRequest} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import IOURequestStepAmount from './step/IOURequestStepAmount'; @@ -36,7 +37,9 @@ import IOURequestStepPerDiemWorkspace from './step/IOURequestStepPerDiemWorkspac import IOURequestStepScan from './step/IOURequestStepScan'; import type {WithWritableReportOrNotFoundProps} from './step/withWritableReportOrNotFound'; -type IOURequestStartPageProps = WithWritableReportOrNotFoundProps; +type IOURequestStartPageProps = WithWritableReportOrNotFoundProps & { + defaultSelectedTab: SelectedTabRequest; +}; function IOURequestStartPage({ route, @@ -44,6 +47,8 @@ function IOURequestStartPage({ params: {iouType, reportID}, }, navigation, + // This is currently only being used for testing + defaultSelectedTab = CONST.TAB_REQUEST.SCAN, }: IOURequestStartPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -51,7 +56,7 @@ function IOURequestStartPage({ const [isDraggingOver, setIsDraggingOver] = useState(false); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); const policy = usePolicy(report?.policyID); - const [selectedTab = CONST.TAB_REQUEST.SCAN, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true}); + const [selectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); const isLoadingSelectedTab = shouldUseTab ? isLoadingOnyxValue(selectedTabResult) : false; const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${route?.params.transactionID}`, {canBeMissing: true}); @@ -129,16 +134,11 @@ function IOURequestStartPage({ useFocusEffect( useCallback(() => { // The test transaction can change the reportID of the transaction on the flow so we should prevent the reportID from being reverted again. - if ( - (transaction?.reportID === reportID && iouType !== CONST.IOU.TYPE.CREATE && iouType !== CONST.IOU.TYPE.SUBMIT) || - isLoadingSelectedTab || - !transactionRequestType || - prevTransactionReportID !== transaction?.reportID - ) { + if (transaction?.reportID === reportID || isLoadingSelectedTab || !transactionRequestType || prevTransactionReportID !== transaction?.reportID) { return; } resetIOUTypeIfChanged(transactionRequestType); - }, [transaction?.reportID, reportID, iouType, resetIOUTypeIfChanged, transactionRequestType, isLoadingSelectedTab, prevTransactionReportID]), + }, [transaction?.reportID, reportID, resetIOUTypeIfChanged, transactionRequestType, isLoadingSelectedTab, prevTransactionReportID]), ); const [headerWithBackBtnContainerElement, setHeaderWithBackButtonContainerElement] = useState(null); @@ -197,7 +197,7 @@ function IOURequestStartPage({ {shouldUseTab ? ( ({ + default: jest.fn(), + MarkerView: jest.fn(), + setAccessToken: jest.fn(), +})); + +jest.mock('react-native-tab-view', () => ({ + TabView: 'TabView', + SceneMap: jest.fn(), + TabBar: 'TabBar', +})); + +jest.mock('@react-native-community/geolocation', () => ({ + setRNConfiguration: jest.fn(), +})); + +jest.mock('react-native-vision-camera', () => ({ + useCameraDevice: jest.fn(), +})); + +describe('IOURequestStartPage', () => { + beforeAll(() => { + Onyx.init({ + keys: ONYXKEYS, + }); + }); + + afterEach(async () => { + await Onyx.clear(); + }); + + it('self DM track options should disappear when report moved to workspace', async () => { + // Given no selected tab data in Onyx + await Onyx.merge(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, null); + + // When the page is mounted with MANUAL tab + render( + + + + ['route'] + } + report={undefined} + reportDraft={undefined} + navigation={{} as PlatformStackScreenProps['navigation']} + defaultSelectedTab={CONST.TAB_REQUEST.MANUAL} + /> + + + , + ); + + await waitForBatchedUpdates(); + + // Then the iou type should be MANUAL + const iouRequestType = await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, + callback: (val) => { + resolve(val?.iouRequestType); + Onyx.disconnect(connection); + }, + }); + }); + expect(iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.MANUAL); + }); +});