Skip to content

Commit a44f476

Browse files
committed
add tests
1 parent 083ce8e commit a44f476

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

tests/navigation/getMatchingFullScreenRouteTests.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath';
44
import SCREENS from '@src/SCREENS';
55

66
jest.mock('@libs/Navigation/linkingConfig/config', () => ({
7-
normalizedConfigs: {},
7+
normalizedConfigs: {
8+
DynamicScreen: {path: 'suffix-a'},
9+
},
810
screensWithOnyxTabNavigator: new Set(),
911
}));
1012

@@ -180,4 +182,30 @@ describe('getMatchingFullScreenRoute - dynamic suffix', () => {
180182
expect(mockGetStateFromPath).toHaveBeenCalledWith('/broken/path/suffix-a');
181183
expect(result).toBeUndefined();
182184
});
185+
186+
it('should ignore backTo for a dynamic screen and resolve full screen route via dynamic suffix instead', () => {
187+
const route = {
188+
name: 'DynamicScreen',
189+
path: '/base/suffix-a',
190+
params: {backTo: '/some/other/path'},
191+
};
192+
const fullScreenRoute = {name: SCREENS.HOME};
193+
const basePathState = {
194+
routes: [{name: 'BaseScreen'}, fullScreenRoute],
195+
index: 1,
196+
};
197+
198+
mockGetStateFromPath.mockImplementation((path: string) => {
199+
if (path === '/base') {
200+
return basePathState;
201+
}
202+
return {routes: [{name: 'WrongScreen'}], index: 0};
203+
});
204+
205+
const result = getMatchingFullScreenRoute(route);
206+
207+
expect(mockGetStateFromPath).toHaveBeenCalledWith('/base');
208+
expect(mockGetStateFromPath).not.toHaveBeenCalledWith('/some/other/path');
209+
expect(result).toEqual(fullScreenRoute);
210+
});
183211
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import isDynamicRouteScreen from '@libs/Navigation/helpers/dynamicRoutesUtils/isDynamicRouteScreen';
2+
import type {Screen} from '@src/SCREENS';
3+
import SCREENS from '@src/SCREENS';
4+
5+
describe('isDynamicRouteScreen', () => {
6+
it('should return true for a static dynamic route screen (DYNAMIC_VERIFY_ACCOUNT)', () => {
7+
expect(isDynamicRouteScreen(SCREENS.SETTINGS.DYNAMIC_VERIFY_ACCOUNT)).toBe(true);
8+
});
9+
10+
it('should return true for a multi-segment dynamic route screen (DYNAMIC_ADD_BANK_ACCOUNT_VERIFY_ACCOUNT)', () => {
11+
expect(isDynamicRouteScreen(SCREENS.SETTINGS.DYNAMIC_ADD_BANK_ACCOUNT_VERIFY_ACCOUNT)).toBe(true);
12+
});
13+
14+
it('should return true for a parametric dynamic route screen (DYNAMIC_FLAG_COMMENT)', () => {
15+
expect(isDynamicRouteScreen(SCREENS.DYNAMIC_FLAG_COMMENT)).toBe(true);
16+
});
17+
18+
it('should return true for DYNAMIC_KEYBOARD_SHORTCUTS', () => {
19+
expect(isDynamicRouteScreen(SCREENS.SETTINGS.DYNAMIC_KEYBOARD_SHORTCUTS)).toBe(true);
20+
});
21+
22+
it('should return true for DYNAMIC_ADDRESS_COUNTRY', () => {
23+
expect(isDynamicRouteScreen(SCREENS.SETTINGS.PROFILE.DYNAMIC_ADDRESS_COUNTRY)).toBe(true);
24+
});
25+
26+
it('should return false for a regular screen (HOME)', () => {
27+
expect(isDynamicRouteScreen(SCREENS.HOME)).toBe(false);
28+
});
29+
30+
it('should return false for a regular screen (REPORT)', () => {
31+
expect(isDynamicRouteScreen(SCREENS.REPORT)).toBe(false);
32+
});
33+
34+
it('should return false for a regular settings screen (Settings_Root)', () => {
35+
expect(isDynamicRouteScreen(SCREENS.SETTINGS.ROOT)).toBe(false);
36+
});
37+
38+
it('should return false for a screen name not present in normalizedConfigs', () => {
39+
expect(isDynamicRouteScreen('NonExistentScreen_12345' as Screen)).toBe(false);
40+
});
41+
});

0 commit comments

Comments
 (0)