@@ -34,8 +34,9 @@ jest.mock('@libs/Navigation/linkingConfig/RELATIONS', () => {
3434
3535jest . mock ( '@src/ROUTES' , ( ) => ( {
3636 DYNAMIC_ROUTES : {
37- VERIFY_ACCOUNT : { path : 'verify-account' , entryScreens : [ ] } ,
38- CUSTOM_FLOW : { path : 'custom-flow' , entryScreens : [ ] } ,
37+ SUFFIX_A : { path : 'suffix-a' , entryScreens : [ ] } ,
38+ SUFFIX_B : { path : 'suffix-b' , entryScreens : [ ] } ,
39+ MULTI_SEG : { path : 'deep/suffix-a' , entryScreens : [ ] } ,
3940 } ,
4041 HOME : 'home' ,
4142} ) ) ;
@@ -48,50 +49,90 @@ describe('getMatchingFullScreenRoute - dynamic suffix', () => {
4849 jest . clearAllMocks ( ) ;
4950 } ) ;
5051
51- it ( 'should return last route when path has dynamic suffix and base path state has full screen as last route' , ( ) => {
52+ it ( 'should return last route when path has a single dynamic suffix and base path state has full screen as last route' , ( ) => {
5253 const route = {
5354 name : 'DynamicScreen' ,
54- path : '/settings/wallet/verify-account ' ,
55+ path : '/base/suffix-a ' ,
5556 } ;
5657 const fullScreenRoute = { name : SCREENS . HOME } ;
5758 const basePathState = {
58- routes : [ { name : 'Settings ' } , fullScreenRoute ] ,
59+ routes : [ { name : 'BaseScreen ' } , fullScreenRoute ] ,
5960 index : 1 ,
6061 } ;
6162
62- mockGetStateFromPath . mockReturnValue ( basePathState ) ;
63+ mockGetStateFromPath . mockImplementation ( ( path : string ) => ( path === '/base' ? basePathState : undefined ) ) ;
6364
6465 const result = getMatchingFullScreenRoute ( route ) ;
6566
66- expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/settings/wallet ' ) ;
67+ expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/base ' ) ;
6768 expect ( result ) . toEqual ( fullScreenRoute ) ;
6869 } ) ;
6970
70- it ( 'should recursively find full screen route when base path has nested state with non- full-screen last route' , ( ) => {
71+ it ( 'should strip the outermost suffix from a layered path before resolving the matching full screen route' , ( ) => {
7172 const route = {
7273 name : 'DynamicScreen' ,
73- path : '/workspace/123/custom-flow' ,
74+ path : '/base/suffix-a/suffix-b' ,
75+ } ;
76+ const fullScreenRoute = { name : SCREENS . HOME } ;
77+ const basePathState = {
78+ routes : [ { name : 'BaseScreen' } , fullScreenRoute ] ,
79+ index : 1 ,
80+ } ;
81+
82+ mockGetStateFromPath . mockImplementation ( ( path : string ) => ( path === '/base/suffix-a' ? basePathState : undefined ) ) ;
83+
84+ const result = getMatchingFullScreenRoute ( route ) ;
85+
86+ expect ( mockGetStateFromPath ) . toHaveBeenCalledTimes ( 1 ) ;
87+ expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/base/suffix-a' ) ;
88+ expect ( result ) . toEqual ( fullScreenRoute ) ;
89+ } ) ;
90+
91+ it ( 'should strip the outermost suffix when the inner suffix is multi-segment' , ( ) => {
92+ const route = {
93+ name : 'DynamicScreen' ,
94+ path : '/base/deep/suffix-a/suffix-b' ,
95+ } ;
96+ const fullScreenRoute = { name : SCREENS . HOME } ;
97+ const basePathState = {
98+ routes : [ { name : 'BaseScreen' } , fullScreenRoute ] ,
99+ index : 1 ,
100+ } ;
101+
102+ mockGetStateFromPath . mockImplementation ( ( path : string ) => ( path === '/base/deep/suffix-a' ? basePathState : undefined ) ) ;
103+
104+ const result = getMatchingFullScreenRoute ( route ) ;
105+
106+ expect ( mockGetStateFromPath ) . toHaveBeenCalledTimes ( 1 ) ;
107+ expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/base/deep/suffix-a' ) ;
108+ expect ( result ) . toEqual ( fullScreenRoute ) ;
109+ } ) ;
110+
111+ it ( 'should recursively find full screen route when the stripped base path has nested state with non-full-screen last route' , ( ) => {
112+ const route = {
113+ name : 'DynamicScreen' ,
114+ path : '/base/suffix-a' ,
74115 } ;
75116 const nestedFocusedRoute = { name : SCREENS . HOME } ;
76117 const basePathState = {
77118 routes : [
78119 {
79- name : 'Workspace ' ,
120+ name : 'BaseNavigator ' ,
80121 state : {
81- routes : [ { name : 'SomeNestedScreen' , path : '/workspace/123 ' } ] ,
122+ routes : [ { name : 'SomeNestedScreen' , path : '/base ' } ] ,
82123 index : 0 ,
83124 } ,
84125 } ,
85126 ] ,
86127 index : 0 ,
87128 } ;
88129
89- mockGetStateFromPath . mockReturnValue ( basePathState ) ;
130+ mockGetStateFromPath . mockImplementation ( ( path : string ) => ( path === '/base' ? basePathState : undefined ) ) ;
90131 mockFindFocusedRoute . mockReturnValue ( nestedFocusedRoute ) ;
91132
92133 const result = getMatchingFullScreenRoute ( route ) ;
93134
94- expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/workspace/123 ' ) ;
135+ expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/base ' ) ;
95136 expect ( mockFindFocusedRoute ) . toHaveBeenCalledWith ( basePathState ) ;
96137 expect ( result ) . toBeDefined ( ) ;
97138 expect ( result ?. name ) . toBe ( SCREENS . HOME ) ;
@@ -100,18 +141,18 @@ describe('getMatchingFullScreenRoute - dynamic suffix', () => {
100141 it ( 'should return undefined when path has dynamic suffix but base path resolves to NOT_FOUND' , ( ) => {
101142 const route = {
102143 name : 'DynamicScreen' ,
103- path : '/invalid/base/verify-account ' ,
144+ path : '/invalid/base/suffix-a/suffix-b ' ,
104145 } ;
105146 const invalidRouteState = {
106- routes : [ { name : SCREENS . NOT_FOUND , path : '/invalid/base' } ] ,
147+ routes : [ { name : SCREENS . NOT_FOUND , path : '/invalid/base/suffix-a ' } ] ,
107148 index : 0 ,
108149 } ;
109150
110- mockGetStateFromPath . mockReturnValue ( invalidRouteState ) ;
151+ mockGetStateFromPath . mockImplementation ( ( path : string ) => ( path === '/invalid/base/suffix-a' ? invalidRouteState : undefined ) ) ;
111152
112153 const result = getMatchingFullScreenRoute ( route ) ;
113154
114- expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/invalid/base' ) ;
155+ expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/invalid/base/suffix-a ' ) ;
115156 expect ( result ) . toBeUndefined ( ) ;
116157 } ) ;
117158
@@ -130,14 +171,14 @@ describe('getMatchingFullScreenRoute - dynamic suffix', () => {
130171 it ( 'should return undefined when path has dynamic suffix but base path state is undefined' , ( ) => {
131172 const route = {
132173 name : 'DynamicScreen' ,
133- path : '/broken/path/verify-account ' ,
174+ path : '/broken/path/suffix-a/suffix-b ' ,
134175 } ;
135176
136177 mockGetStateFromPath . mockReturnValue ( undefined ) ;
137178
138179 const result = getMatchingFullScreenRoute ( route ) ;
139180
140- expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/broken/path' ) ;
181+ expect ( mockGetStateFromPath ) . toHaveBeenCalledWith ( '/broken/path/suffix-a ' ) ;
141182 expect ( result ) . toBeUndefined ( ) ;
142183 } ) ;
143184} ) ;
0 commit comments