diff --git a/tests/navigation/GoBackTests.tsx b/tests/navigation/GoBackTests.tsx index 08483f6d01fd..8d5aaf747798 100644 --- a/tests/navigation/GoBackTests.tsx +++ b/tests/navigation/GoBackTests.tsx @@ -1,22 +1,14 @@ -import type {InitialState} from '@react-navigation/native'; -import {NavigationContainer} from '@react-navigation/native'; import {act, render} from '@testing-library/react-native'; import React from 'react'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; -import createRootStackNavigator from '@libs/Navigation/AppNavigator/createRootStackNavigator'; -import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import Navigation from '@libs/Navigation/Navigation'; import navigationRef from '@libs/Navigation/navigationRef'; -import type {AuthScreensParamList, ReportsSplitNavigatorParamList, SettingsSplitNavigatorParamList} from '@libs/Navigation/types'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; - -const RootStack = createRootStackNavigator(); -const ReportsSplit = createSplitNavigator(); -const SettingsSplit = createSplitNavigator(); +import TestNavigationContainer from '../utils/TestNavigationContainer'; jest.mock('@hooks/useResponsiveLayout', () => jest.fn()); jest.mock('@libs/getIsNarrowLayout', () => jest.fn()); @@ -26,78 +18,6 @@ jest.mock('@pages/home/sidebar/BottomTabAvatar'); const mockedGetIsNarrowLayout = getIsNarrowLayout as jest.MockedFunction; const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction; -function SettingsSplitNavigator() { - return ( - - jest.fn()} - /> - jest.fn()} - /> - jest.fn()} - /> - jest.fn()} - /> - - ); -} - -function ReportsSplitNavigator() { - return ( - - jest.fn()} - /> - jest.fn()} - /> - - ); -} - -type TestNavigationContainerProps = {initialState: InitialState}; - -function TestNavigationContainer({initialState}: TestNavigationContainerProps) { - return ( - - - - - jest.fn()} - /> - - - ); -} - describe('Go back on the narrow layout', () => { beforeEach(() => { mockedGetIsNarrowLayout.mockReturnValue(true); diff --git a/tests/navigation/NavigateTests.tsx b/tests/navigation/NavigateTests.tsx index f4bc3be4a001..0a290b4ce9a0 100644 --- a/tests/navigation/NavigateTests.tsx +++ b/tests/navigation/NavigateTests.tsx @@ -1,22 +1,14 @@ -import type {InitialState} from '@react-navigation/native'; -import {NavigationContainer} from '@react-navigation/native'; import {act, render} from '@testing-library/react-native'; import React from 'react'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; -import createRootStackNavigator from '@libs/Navigation/AppNavigator/createRootStackNavigator'; -import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import Navigation from '@libs/Navigation/Navigation'; import navigationRef from '@libs/Navigation/navigationRef'; -import type {AuthScreensParamList, ReportsSplitNavigatorParamList, SettingsSplitNavigatorParamList} from '@libs/Navigation/types'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; - -const RootStack = createRootStackNavigator(); -const ReportsSplit = createSplitNavigator(); -const SettingsSplit = createSplitNavigator(); +import TestNavigationContainer from '../utils/TestNavigationContainer'; jest.mock('@hooks/useResponsiveLayout', () => jest.fn()); jest.mock('@libs/getIsNarrowLayout', () => jest.fn()); @@ -26,78 +18,6 @@ jest.mock('@pages/home/sidebar/BottomTabAvatar'); const mockedGetIsNarrowLayout = getIsNarrowLayout as jest.MockedFunction; const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction; -function SettingsSplitNavigator() { - return ( - - jest.fn()} - /> - jest.fn()} - /> - jest.fn()} - /> - jest.fn()} - /> - - ); -} - -function ReportsSplitNavigator() { - return ( - - jest.fn()} - /> - jest.fn()} - /> - - ); -} - -type TestNavigationContainerProps = {initialState: InitialState}; - -function TestNavigationContainer({initialState}: TestNavigationContainerProps) { - return ( - - - - - jest.fn()} - /> - - - ); -} - describe('Navigate', () => { beforeEach(() => { mockedGetIsNarrowLayout.mockReturnValue(true); diff --git a/tests/navigation/SwitchPolicyIDTests.tsx b/tests/navigation/SwitchPolicyIDTests.tsx index b041f3046899..61900c2fb817 100644 --- a/tests/navigation/SwitchPolicyIDTests.tsx +++ b/tests/navigation/SwitchPolicyIDTests.tsx @@ -1,20 +1,13 @@ -import type {InitialState} from '@react-navigation/native'; -import {NavigationContainer} from '@react-navigation/native'; import {act, render} from '@testing-library/react-native'; import React from 'react'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; -import createRootStackNavigator from '@libs/Navigation/AppNavigator/createRootStackNavigator'; -import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import navigationRef from '@libs/Navigation/navigationRef'; -import type {AuthScreensParamList, ReportsSplitNavigatorParamList} from '@libs/Navigation/types'; import switchPolicyAfterInteractions from '@pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; - -const RootStack = createRootStackNavigator(); -const ReportsSplit = createSplitNavigator(); +import TestNavigationContainer from '../utils/TestNavigationContainer'; jest.mock('@hooks/useResponsiveLayout', () => jest.fn()); jest.mock('@libs/getIsNarrowLayout', () => jest.fn()); @@ -24,47 +17,6 @@ jest.mock('@pages/home/sidebar/BottomTabAvatar'); const mockedGetIsNarrowLayout = getIsNarrowLayout as jest.MockedFunction; const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction; -function ReportsSplitNavigator() { - return ( - - jest.fn()} - /> - jest.fn()} - /> - - ); -} - -type TestNavigationContainerProps = {initialState: InitialState}; - -function TestNavigationContainer({initialState}: TestNavigationContainerProps) { - return ( - - - - jest.fn()} - /> - - - ); -} - describe('Switch policy ID', () => { beforeEach(() => { mockedGetIsNarrowLayout.mockReturnValue(true); diff --git a/tests/utils/TestNavigationContainer.tsx b/tests/utils/TestNavigationContainer.tsx new file mode 100644 index 000000000000..9f19ca4658a0 --- /dev/null +++ b/tests/utils/TestNavigationContainer.tsx @@ -0,0 +1,87 @@ +import type {InitialState} from '@react-navigation/native'; +import {NavigationContainer} from '@react-navigation/native'; +import React from 'react'; +import createRootStackNavigator from '@libs/Navigation/AppNavigator/createRootStackNavigator'; +import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; +import navigationRef from '@libs/Navigation/navigationRef'; +import type {AuthScreensParamList, ReportsSplitNavigatorParamList, SettingsSplitNavigatorParamList} from '@libs/Navigation/types'; +import CONST from '@src/CONST'; +import NAVIGATORS from '@src/NAVIGATORS'; +import SCREENS from '@src/SCREENS'; + +const RootStack = createRootStackNavigator(); +const ReportsSplit = createSplitNavigator(); +const SettingsSplit = createSplitNavigator(); + +type TestNavigationContainerProps = {initialState: InitialState}; + +function TestReportsSplitNavigator() { + return ( + + jest.fn()} + /> + jest.fn()} + /> + + ); +} + +function TestSettingsSplitNavigator() { + return ( + + jest.fn()} + /> + jest.fn()} + /> + jest.fn()} + /> + jest.fn()} + /> + + ); +} + +function TestNavigationContainer({initialState}: TestNavigationContainerProps) { + return ( + + + + + jest.fn()} + /> + + + ); +} +export default TestNavigationContainer;