| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 16:19:52 -07:00
										 |  |  | import {Routes} from '../src/config'; | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  | import {Recognizer} from '../src/recognize'; | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  | import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state'; | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  | import {Params, PRIMARY_OUTLET} from '../src/shared'; | 
					
						
							| 
									
										
										
										
											2016-06-21 11:56:40 -07:00
										 |  |  | import {DefaultUrlSerializer, UrlTree} from '../src/url_tree'; | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('recognize', () => { | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |   it('should work', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize([{path: 'a', component: ComponentA}], 'a'); | 
					
						
							|  |  |  |     checkActivatedRoute(s.root, '', {}, RootComponent); | 
					
						
							|  |  |  |     checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 13:33:05 -07:00
										 |  |  |   it('should freeze params object', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s: RouterStateSnapshot = recognize([{path: 'a/:id', component: ComponentA}], 'a/10'); | 
					
						
							|  |  |  |     checkActivatedRoute(s.root, '', {}, RootComponent); | 
					
						
							|  |  |  |     const child = s.root.firstChild!; | 
					
						
							|  |  |  |     expect(Object.isFrozen(child.params)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2016-07-14 13:33:05 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 16:51:44 -07:00
										 |  |  |   it('should support secondary routes', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s: RouterStateSnapshot = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'}, | 
					
						
							|  |  |  |           {path: 'c', component: ComponentC, outlet: 'right'} | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a(left:b//right:c)'); | 
					
						
							|  |  |  |     const c = s.root.children; | 
					
						
							|  |  |  |     checkActivatedRoute(c[0], 'a', {}, ComponentA); | 
					
						
							|  |  |  |     checkActivatedRoute(c[1], 'b', {}, ComponentB, 'left'); | 
					
						
							|  |  |  |     checkActivatedRoute(c[2], 'c', {}, ComponentC, 'right'); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |   it('should set url segment and index properly', () => { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     const url = tree('a(left:b//right:c)'); | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'}, | 
					
						
							|  |  |  |           {path: 'c', component: ComponentC, outlet: 'right'} | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a(left:b//right:c)'); | 
					
						
							|  |  |  |     expect(s.root.url.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |     expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const c = s.root.children; | 
					
						
							|  |  |  |     expect(c[0].url.toString()).toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |     expect((c[0] as any)._lastPathIndex).toBe(0); | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     expect(c[1].url.toString()).toEqual(url.root.children['left'].toString()); | 
					
						
							|  |  |  |     expect((c[1] as any)._lastPathIndex).toBe(0); | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     expect(c[2].url.toString()).toEqual(url.root.children['right'].toString()); | 
					
						
							|  |  |  |     expect((c[2] as any)._lastPathIndex).toBe(0); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should set url segment and index properly (nested case)', () => { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     const url = tree('a/b/c'); | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a/b', component: ComponentA, children: [{path: 'c', component: ComponentC}]}, | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a/b/c'); | 
					
						
							|  |  |  |     expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |     expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const compA = s.root.firstChild!; | 
					
						
							|  |  |  |     expect((compA as any)._urlSegment.toString()) | 
					
						
							|  |  |  |         .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |     expect((compA as any)._lastPathIndex).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const compC = compA.firstChild!; | 
					
						
							|  |  |  |     expect((compC as any)._urlSegment.toString()) | 
					
						
							|  |  |  |         .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |     expect((compC as any)._lastPathIndex).toBe(2); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |   it('should set url segment and index properly (wildcard)', () => { | 
					
						
							|  |  |  |     const url = tree('a/b/c'); | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA, children: [{path: '**', component: ComponentB}]}, | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a/b/c'); | 
					
						
							|  |  |  |     expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |     expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const compA = s.root.firstChild!; | 
					
						
							|  |  |  |     expect((compA as any)._urlSegment.toString()) | 
					
						
							|  |  |  |         .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |     expect((compA as any)._lastPathIndex).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const compC = compA.firstChild!; | 
					
						
							|  |  |  |     expect((compC as any)._urlSegment.toString()) | 
					
						
							|  |  |  |         .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |     expect((compC as any)._lastPathIndex).toBe(2); | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |   it('should match routes in the depth first order', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA, children: [{path: ':id', component: ComponentB}]}, | 
					
						
							|  |  |  |           {path: 'a/:id', component: ComponentC} | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a/paramA'); | 
					
						
							|  |  |  |     checkActivatedRoute(s.root, '', {}, RootComponent); | 
					
						
							|  |  |  |     checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							|  |  |  |     checkActivatedRoute(s.root.firstChild!.firstChild!, 'paramA', {id: 'paramA'}, ComponentB); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const s2 = recognize( | 
					
						
							|  |  |  |         [{path: 'a', component: ComponentA}, {path: 'a/:id', component: ComponentC}], 'a/paramA'); | 
					
						
							|  |  |  |     checkActivatedRoute(s2.root, '', {}, RootComponent); | 
					
						
							|  |  |  |     checkActivatedRoute(s2.root.firstChild!, 'a/paramA', {id: 'paramA'}, ComponentC); | 
					
						
							| 
									
										
										
										
											2016-06-06 10:15:23 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 16:51:44 -07:00
										 |  |  |   it('should use outlet name when matching secondary routes', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'}, | 
					
						
							|  |  |  |           {path: 'b', component: ComponentC, outlet: 'right'} | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a(right:b)'); | 
					
						
							|  |  |  |     const c = s.root.children; | 
					
						
							|  |  |  |     checkActivatedRoute(c[0], 'a', {}, ComponentA); | 
					
						
							|  |  |  |     checkActivatedRoute(c[1], 'b', {}, ComponentC, 'right'); | 
					
						
							| 
									
										
										
										
											2016-05-26 16:51:44 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should handle non top-level secondary routes', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             path: 'a', | 
					
						
							|  |  |  |             component: ComponentA, | 
					
						
							|  |  |  |             children: [ | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               {path: 'b', component: ComponentB}, {path: 'c', component: ComponentC, outlet: 'left'} | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |             ] | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a/(b//left:c)'); | 
					
						
							|  |  |  |     const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |     checkActivatedRoute(c[0], 'b', {}, ComponentB, PRIMARY_OUTLET); | 
					
						
							|  |  |  |     checkActivatedRoute(c[1], 'c', {}, ComponentC, 'left'); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 13:29:52 -07:00
										 |  |  |   it('should sort routes by outlet name', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA}, {path: 'c', component: ComponentC, outlet: 'c'}, | 
					
						
							|  |  |  |           {path: 'b', component: ComponentB, outlet: 'b'} | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a(c:c//b:b)'); | 
					
						
							|  |  |  |     const c = s.root.children; | 
					
						
							|  |  |  |     checkActivatedRoute(c[0], 'a', {}, ComponentA); | 
					
						
							|  |  |  |     checkActivatedRoute(c[1], 'b', {}, ComponentB, 'b'); | 
					
						
							|  |  |  |     checkActivatedRoute(c[2], 'c', {}, ComponentC, 'c'); | 
					
						
							| 
									
										
										
										
											2016-06-01 13:29:52 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 16:51:44 -07:00
										 |  |  |   it('should support matrix parameters', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |     const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         [ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}, | 
					
						
							|  |  |  |           {path: 'c', component: ComponentC, outlet: 'left'} | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         'a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)'); | 
					
						
							|  |  |  |     const c = s.root.children; | 
					
						
							|  |  |  |     checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA); | 
					
						
							|  |  |  |     checkActivatedRoute(c[0].firstChild!, 'b', {b1: '111', b2: '222'}, ComponentB); | 
					
						
							|  |  |  |     checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left'); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 14:00:07 -07:00
										 |  |  |   describe('data', () => { | 
					
						
							|  |  |  |     it('should set static data', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize([{path: 'a', data: {one: 1}, component: ComponentA}], 'a'); | 
					
						
							|  |  |  |       const r: ActivatedRouteSnapshot = s.root.firstChild!; | 
					
						
							|  |  |  |       expect(r.data).toEqual({one: 1}); | 
					
						
							| 
									
										
										
										
											2016-06-27 14:00:07 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |     it('should inherit componentless route\'s data', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-27 14:00:07 -07:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'a', | 
					
						
							|  |  |  |             data: {one: 1}, | 
					
						
							|  |  |  |             children: [{path: 'b', data: {two: 2}, component: ComponentB}] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'a/b'); | 
					
						
							|  |  |  |       const r: ActivatedRouteSnapshot = s.root.firstChild!.firstChild!; | 
					
						
							|  |  |  |       expect(r.data).toEqual({one: 1, two: 2}); | 
					
						
							| 
									
										
										
										
											2016-06-27 14:00:07 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |     it('should not inherit route\'s data if it has component', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'a', | 
					
						
							|  |  |  |             component: ComponentA, | 
					
						
							|  |  |  |             data: {one: 1}, | 
					
						
							|  |  |  |             children: [{path: 'b', data: {two: 2}, component: ComponentB}] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'a/b'); | 
					
						
							|  |  |  |       const r: ActivatedRouteSnapshot = s.root.firstChild!.firstChild!; | 
					
						
							|  |  |  |       expect(r.data).toEqual({two: 2}); | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should inherit route\'s data if paramsInheritanceStrategy is \'always\'', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'a', | 
					
						
							|  |  |  |             component: ComponentA, | 
					
						
							|  |  |  |             data: {one: 1}, | 
					
						
							|  |  |  |             children: [{path: 'b', data: {two: 2}, component: ComponentB}] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'a/b', 'always'); | 
					
						
							|  |  |  |       const r: ActivatedRouteSnapshot = s.root.firstChild!.firstChild!; | 
					
						
							|  |  |  |       expect(r.data).toEqual({one: 1, two: 2}); | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 14:00:07 -07:00
										 |  |  |     it('should set resolved data', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize([{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a'); | 
					
						
							|  |  |  |       const r: any = s.root.firstChild!; | 
					
						
							|  |  |  |       expect(r._resolve).toEqual({one: 'some-token'}); | 
					
						
							| 
									
										
										
										
											2016-06-27 14:00:07 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |   describe('empty path', () => { | 
					
						
							|  |  |  |     describe('root', () => { | 
					
						
							|  |  |  |       it('should work', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize([{path: '', component: ComponentA}], ''); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, '', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       it('should match when terminal', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize([{path: '', pathMatch: 'full', component: ComponentA}], ''); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, '', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       it('should work (nested case)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], ''); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, '', {}, ComponentA); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!.firstChild!, '', {}, ComponentB); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should set url segment and index properly', () => { | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |         const url = tree('') as any; | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], ''); | 
					
						
							|  |  |  |         expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const c = s.root.firstChild!; | 
					
						
							|  |  |  |         expect((c as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((c as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const c2 = s.root.firstChild!.firstChild!; | 
					
						
							|  |  |  |         expect((c2 as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((c2 as any)._lastPathIndex).toBe(-1); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-07-08 14:23:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should inherit params', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-07-08 14:23:23 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               children: | 
					
						
							|  |  |  |                   [{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}] | 
					
						
							| 
									
										
										
										
											2016-07-08 14:23:23 -07:00
										 |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             '/a;p=1'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {p: '1'}, ComponentA); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!.firstChild!, '', {p: '1'}, ComponentB); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!.firstChild!.firstChild!, '', {p: '1'}, ComponentC); | 
					
						
							| 
									
										
										
										
											2016-07-08 14:23:23 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |     describe('aux split is in the middle', () => { | 
					
						
							|  |  |  |       it('should match (non-terminal)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                 {path: 'b', component: ComponentB}, {path: '', component: ComponentC, outlet: 'aux'} | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a/b'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |         checkActivatedRoute(c[0], 'b', {}, ComponentB); | 
					
						
							|  |  |  |         checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |       it('should match (non-terminal) when both primary and secondary and primary has a child', | 
					
						
							| 
									
										
										
										
											2016-07-22 18:32:26 -07:00
										 |  |  |          () => { | 
					
						
							|  |  |  |            const config = [{ | 
					
						
							|  |  |  |              path: 'parent', | 
					
						
							|  |  |  |              children: [ | 
					
						
							|  |  |  |                { | 
					
						
							|  |  |  |                  path: '', | 
					
						
							|  |  |  |                  component: ComponentA, | 
					
						
							|  |  |  |                  children: [ | 
					
						
							|  |  |  |                    {path: 'b', component: ComponentB}, | 
					
						
							|  |  |  |                    {path: 'c', component: ComponentC}, | 
					
						
							|  |  |  |                  ] | 
					
						
							|  |  |  |                }, | 
					
						
							|  |  |  |                { | 
					
						
							|  |  |  |                  path: '', | 
					
						
							|  |  |  |                  component: ComponentD, | 
					
						
							|  |  |  |                  outlet: 'secondary', | 
					
						
							|  |  |  |                } | 
					
						
							|  |  |  |              ] | 
					
						
							|  |  |  |            }]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |            const s = recognize(config, 'parent/b'); | 
					
						
							|  |  |  |            checkActivatedRoute(s.root, '', {}, RootComponent); | 
					
						
							|  |  |  |            checkActivatedRoute(s.root.firstChild!, 'parent', {}, undefined!); | 
					
						
							| 
									
										
										
										
											2016-07-22 18:32:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |            const cc = s.root.firstChild!.children; | 
					
						
							|  |  |  |            checkActivatedRoute(cc[0], '', {}, ComponentA); | 
					
						
							|  |  |  |            checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary'); | 
					
						
							| 
									
										
										
										
											2016-07-22 18:32:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |            checkActivatedRoute(cc[0].firstChild!, 'b', {}, ComponentB); | 
					
						
							| 
									
										
										
										
											2016-07-22 18:32:26 -07:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       it('should match (terminal)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 {path: 'b', component: ComponentB}, | 
					
						
							| 
									
										
										
										
											2016-06-27 20:10:36 -07:00
										 |  |  |                 {path: '', pathMatch: 'full', component: ComponentC, outlet: 'aux'} | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a/b'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |         expect(c.length).toEqual(1); | 
					
						
							|  |  |  |         checkActivatedRoute(c[0], 'b', {}, ComponentB); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should set url segment and index properly', () => { | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |         const url = tree('a/b') as any; | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{ | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |                 {path: 'b', component: ComponentB}, {path: '', component: ComponentC, outlet: 'aux'} | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a/b'); | 
					
						
							|  |  |  |         expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const a = s.root.firstChild!; | 
					
						
							|  |  |  |         expect((a as any)._urlSegment.toString()) | 
					
						
							|  |  |  |             .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |         expect((a as any)._lastPathIndex).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const b = a.firstChild!; | 
					
						
							|  |  |  |         expect((b as any)._urlSegment.toString()) | 
					
						
							|  |  |  |             .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |         expect((b as any)._lastPathIndex).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const c = a.children[1]; | 
					
						
							|  |  |  |         expect((c as any)._urlSegment.toString()) | 
					
						
							|  |  |  |             .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |         expect((c as any)._lastPathIndex).toBe(0); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should set url segment and index properly when nested empty-path segments', () => { | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |         const url = tree('a') as any; | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{ | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |               path: 'a', | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               children: | 
					
						
							|  |  |  |                   [{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}] | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a'); | 
					
						
							|  |  |  |         expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const a = s.root.firstChild!; | 
					
						
							|  |  |  |         expect((a as any)._urlSegment.toString()) | 
					
						
							|  |  |  |             .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |         expect((a as any)._lastPathIndex).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const b = a.firstChild!; | 
					
						
							|  |  |  |         expect((b as any)._urlSegment.toString()) | 
					
						
							|  |  |  |             .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |         expect((b as any)._lastPathIndex).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const c = b.firstChild!; | 
					
						
							|  |  |  |         expect((c as any)._urlSegment.toString()) | 
					
						
							|  |  |  |             .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |         expect((c as any)._lastPathIndex).toBe(0); | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-23 10:24:51 +01:00
										 |  |  |       it('should set url segment and index properly with the "corrected" option for nested empty-path segments', | 
					
						
							|  |  |  |          () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |            const url = tree('a/b'); | 
					
						
							|  |  |  |            const s = recognize( | 
					
						
							|  |  |  |                [{ | 
					
						
							| 
									
										
										
										
											2018-02-23 10:24:51 +01:00
										 |  |  |                  path: 'a', | 
					
						
							|  |  |  |                  children: [{ | 
					
						
							|  |  |  |                    path: 'b', | 
					
						
							|  |  |  |                    component: ComponentB, | 
					
						
							|  |  |  |                    children: [{ | 
					
						
							|  |  |  |                      path: '', | 
					
						
							|  |  |  |                      component: ComponentC, | 
					
						
							|  |  |  |                      children: [{path: '', component: ComponentD}] | 
					
						
							|  |  |  |                    }] | 
					
						
							|  |  |  |                  }] | 
					
						
							|  |  |  |                }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |                'a/b', 'emptyOnly', 'corrected'); | 
					
						
							|  |  |  |            expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |            expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            const a = s.root.firstChild!; | 
					
						
							|  |  |  |            expect((a as any)._urlSegment.toString()) | 
					
						
							|  |  |  |                .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |            expect((a as any)._lastPathIndex).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            const b = a.firstChild!; | 
					
						
							|  |  |  |            expect((b as any)._urlSegment.toString()) | 
					
						
							|  |  |  |                .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |            expect((b as any)._lastPathIndex).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            const c = b.firstChild!; | 
					
						
							|  |  |  |            expect((c as any)._urlSegment.toString()) | 
					
						
							|  |  |  |                .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |            expect((c as any)._lastPathIndex).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            const d = c.firstChild!; | 
					
						
							|  |  |  |            expect((d as any)._urlSegment.toString()) | 
					
						
							|  |  |  |                .toEqual(url.root.children[PRIMARY_OUTLET].toString()); | 
					
						
							|  |  |  |            expect((d as any)._lastPathIndex).toBe(1); | 
					
						
							| 
									
										
										
										
											2018-02-23 10:24:51 +01:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |       it('should set url segment and index properly when nested empty-path segments (2)', () => { | 
					
						
							|  |  |  |         const url = tree(''); | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{ | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |               path: '', | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               children: | 
					
						
							|  |  |  |                   [{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}] | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             ''); | 
					
						
							|  |  |  |         expect((s.root as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((s.root as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const a = s.root.firstChild!; | 
					
						
							|  |  |  |         expect((a as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((a as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const b = a.firstChild!; | 
					
						
							|  |  |  |         expect((b as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((b as any)._lastPathIndex).toBe(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const c = b.firstChild!; | 
					
						
							|  |  |  |         expect((c as any)._urlSegment.toString()).toEqual(url.root.toString()); | 
					
						
							|  |  |  |         expect((c as any)._lastPathIndex).toBe(-1); | 
					
						
							| 
									
										
										
										
											2016-07-18 14:53:13 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |     describe('aux split at the end (no right child)', () => { | 
					
						
							|  |  |  |       it('should match (non-terminal)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 {path: '', component: ComponentB}, | 
					
						
							|  |  |  |                 {path: '', component: ComponentC, outlet: 'aux'}, | 
					
						
							|  |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |         checkActivatedRoute(c[0], '', {}, ComponentB); | 
					
						
							|  |  |  |         checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should match (terminal)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							| 
									
										
										
										
											2016-06-27 20:10:36 -07:00
										 |  |  |                 {path: '', pathMatch: 'full', component: ComponentB}, | 
					
						
							|  |  |  |                 {path: '', pathMatch: 'full', component: ComponentC, outlet: 'aux'}, | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |         checkActivatedRoute(c[0], '', {}, ComponentB); | 
					
						
							|  |  |  |         checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work only only primary outlet', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 {path: '', component: ComponentB}, | 
					
						
							|  |  |  |                 {path: 'c', component: ComponentC, outlet: 'aux'}, | 
					
						
							|  |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a/(aux:c)'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |         checkActivatedRoute(c[0], '', {}, ComponentB); | 
					
						
							|  |  |  |         checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-07-21 14:50:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should work when split is at the root level', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-07-21 14:50:38 -07:00
										 |  |  |             [ | 
					
						
							|  |  |  |               {path: '', component: ComponentA}, {path: 'b', component: ComponentB}, | 
					
						
							|  |  |  |               {path: 'c', component: ComponentC, outlet: 'aux'} | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             '(aux:c)'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root, '', {}, RootComponent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const children = s.root.children; | 
					
						
							|  |  |  |         expect(children.length).toEqual(2); | 
					
						
							|  |  |  |         checkActivatedRoute(children[0], '', {}, ComponentA); | 
					
						
							|  |  |  |         checkActivatedRoute(children[1], 'c', {}, ComponentC, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-07-21 14:50:38 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |     describe('split at the end (right child)', () => { | 
					
						
							|  |  |  |       it('should match (non-terminal)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |         const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |             [{ | 
					
						
							|  |  |  |               path: 'a', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 {path: '', component: ComponentB, children: [{path: 'd', component: ComponentD}]}, | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   path: '', | 
					
						
							|  |  |  |                   component: ComponentC, | 
					
						
							|  |  |  |                   outlet: 'aux', | 
					
						
							|  |  |  |                   children: [{path: 'e', component: ComponentE}] | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               ] | 
					
						
							|  |  |  |             }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |             'a/(d//aux:e)'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.firstChild!, 'a', {}, ComponentA); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const c = s.root.firstChild!.children; | 
					
						
							|  |  |  |         checkActivatedRoute(c[0], '', {}, ComponentB); | 
					
						
							|  |  |  |         checkActivatedRoute(c[0].firstChild!, 'd', {}, ComponentD); | 
					
						
							|  |  |  |         checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); | 
					
						
							|  |  |  |         checkActivatedRoute(c[1].firstChild!, 'e', {}, ComponentE); | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-06-02 11:30:38 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-11-25 17:27:48 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('with outlets', () => { | 
					
						
							|  |  |  |       it('should work when outlet is a child of empty path parent', () => { | 
					
						
							|  |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{ | 
					
						
							|  |  |  |               path: '', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [{path: 'b', outlet: 'b', component: ComponentB}] | 
					
						
							|  |  |  |             }], | 
					
						
							|  |  |  |             '(b:b)'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.children[0], '', {}, ComponentA); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.children[0].children[0], 'b', {}, ComponentB, 'b'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work for outlets adjacent to empty path', () => { | 
					
						
							|  |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 path: '', | 
					
						
							|  |  |  |                 component: ComponentA, | 
					
						
							|  |  |  |                 children: [{path: '', component: ComponentC}], | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               {path: 'b', outlet: 'b', component: ComponentB} | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             '(b:b)'); | 
					
						
							|  |  |  |         const [primaryChild, outletChild] = s.root.children; | 
					
						
							|  |  |  |         checkActivatedRoute(primaryChild, '', {}, ComponentA); | 
					
						
							|  |  |  |         checkActivatedRoute(outletChild, 'b', {}, ComponentB, 'b'); | 
					
						
							|  |  |  |         checkActivatedRoute(primaryChild.children[0], '', {}, ComponentC); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with named outlets both adjecent to and as a child of empty path', () => { | 
					
						
							|  |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 path: '', | 
					
						
							|  |  |  |                 component: ComponentA, | 
					
						
							|  |  |  |                 children: [{path: 'b', outlet: 'b', component: ComponentB}] | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               {path: 'c', outlet: 'c', component: ComponentC} | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             '(b:b//c:c)'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.children[0], '', {}, ComponentA); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.children[1], 'c', {}, ComponentC, 'c'); | 
					
						
							|  |  |  |         checkActivatedRoute(s.root.children[0].children[0], 'b', {}, ComponentB, 'b'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should work with children outlets within two levels of empty parents', () => { | 
					
						
							|  |  |  |         const s = recognize( | 
					
						
							|  |  |  |             [{ | 
					
						
							|  |  |  |               path: '', | 
					
						
							|  |  |  |               component: ComponentA, | 
					
						
							|  |  |  |               children: [{ | 
					
						
							|  |  |  |                 path: '', | 
					
						
							|  |  |  |                 component: ComponentB, | 
					
						
							|  |  |  |                 children: [{path: 'c', outlet: 'c', component: ComponentC}], | 
					
						
							|  |  |  |               }] | 
					
						
							|  |  |  |             }], | 
					
						
							|  |  |  |             '(c:c)'); | 
					
						
							| 
									
										
										
										
											2021-04-09 14:58:55 -07:00
										 |  |  |         const [compAConfig] = s.root.children; | 
					
						
							|  |  |  |         checkActivatedRoute(compAConfig, '', {}, ComponentA); | 
					
						
							|  |  |  |         expect(compAConfig.children.length).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const [compBConfig] = compAConfig.children; | 
					
						
							|  |  |  |         checkActivatedRoute(compBConfig, '', {}, ComponentB); | 
					
						
							|  |  |  |         expect(compBConfig.children.length).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const [compCConfig] = compBConfig.children; | 
					
						
							|  |  |  |         checkActivatedRoute(compCConfig, 'c', {}, ComponentC, 'c'); | 
					
						
							| 
									
										
										
										
											2020-11-25 17:27:48 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not persist a primary segment beyond the boundary of a named outlet match', () => { | 
					
						
							|  |  |  |         const s = new Recognizer( | 
					
						
							|  |  |  |                       RootComponent, | 
					
						
							|  |  |  |                       [ | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                           path: '', | 
					
						
							|  |  |  |                           component: ComponentA, | 
					
						
							|  |  |  |                           outlet: 'a', | 
					
						
							|  |  |  |                           children: [{path: 'b', component: ComponentB}], | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                       ], | 
					
						
							|  |  |  |                       tree('/b'), '/b', 'emptyOnly', 'corrected') | 
					
						
							|  |  |  |                       .recognize(); | 
					
						
							|  |  |  |         expect(s).toBeNull(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   describe('wildcards', () => { | 
					
						
							|  |  |  |     it('should support simple wildcards', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize([{path: '**', component: ComponentA}], 'a/b/c/d;a1=11'); | 
					
						
							|  |  |  |       checkActivatedRoute(s.root.firstChild!, 'a/b/c/d', {a1: '11'}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   describe('componentless routes', () => { | 
					
						
							|  |  |  |     it('should work', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'p/:id', | 
					
						
							|  |  |  |             children: [ | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'aux'} | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |             ] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'p/11;pp=22/(a;pa=33//aux:b;pb=44)'); | 
					
						
							|  |  |  |       const p = s.root.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined!); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const c = p.children; | 
					
						
							|  |  |  |       checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA); | 
					
						
							|  |  |  |       checkActivatedRoute(c[1], 'b', {id: '11', pp: '22', pb: '44'}, ComponentB, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-06-19 14:44:20 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |     it('should inherit params until encounters a normal route', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'p/:id', | 
					
						
							|  |  |  |             children: [{ | 
					
						
							|  |  |  |               path: 'a/:name', | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               children: [ | 
					
						
							|  |  |  |                 {path: 'b', component: ComponentB, children: [{path: 'c', component: ComponentC}]} | 
					
						
							|  |  |  |               ] | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |             }] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'p/11/a/victor/b/c'); | 
					
						
							|  |  |  |       const p = s.root.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(p, 'p/11', {id: '11'}, undefined!); | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const a = p.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined!); | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const b = a.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB); | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const c = b.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(c, 'c', {}, ComponentC); | 
					
						
							| 
									
										
										
										
											2016-06-19 14:44:20 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should inherit all params if paramsInheritanceStrategy is \'always\'', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'p/:id', | 
					
						
							|  |  |  |             children: [{ | 
					
						
							|  |  |  |               path: 'a/:name', | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               children: [ | 
					
						
							|  |  |  |                 {path: 'b', component: ComponentB, children: [{path: 'c', component: ComponentC}]} | 
					
						
							|  |  |  |               ] | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |             }] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'p/11/a/victor/b/c', 'always'); | 
					
						
							|  |  |  |       const c = s.root.firstChild!.firstChild!.firstChild!.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(c, 'c', {id: '11', name: 'victor'}, ComponentC); | 
					
						
							| 
									
										
										
										
											2017-11-28 16:57:10 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-06-19 14:44:20 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-08 13:36:59 -08:00
										 |  |  |   describe('empty URL leftovers', () => { | 
					
						
							|  |  |  |     it('should not throw when no children matching', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-11-08 13:36:59 -08:00
										 |  |  |           [{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           '/a'); | 
					
						
							|  |  |  |       const a = s.root.firstChild; | 
					
						
							|  |  |  |       checkActivatedRoute(a!, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2016-11-08 13:36:59 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not throw when no children matching (aux routes)', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-11-08 13:36:59 -08:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             path: 'a', | 
					
						
							|  |  |  |             component: ComponentA, | 
					
						
							|  |  |  |             children: [ | 
					
						
							|  |  |  |               {path: 'b', component: ComponentB}, | 
					
						
							|  |  |  |               {path: '', component: ComponentC, outlet: 'aux'}, | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |           }], | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           '/a'); | 
					
						
							|  |  |  |       const a = s.root.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(a, 'a', {}, ComponentA); | 
					
						
							|  |  |  |       checkActivatedRoute(a.children[0], '', {}, ComponentC, 'aux'); | 
					
						
							| 
									
										
										
										
											2016-11-08 13:36:59 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-09 15:25:47 -08:00
										 |  |  |   describe('custom path matchers', () => { | 
					
						
							|  |  |  |     it('should use custom path matcher', () => { | 
					
						
							|  |  |  |       const matcher = (s: any, g: any, r: any) => { | 
					
						
							|  |  |  |         if (s[0].path === 'a') { | 
					
						
							|  |  |  |           return {consumed: s.slice(0, 2), posParams: {id: s[1]}}; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2016-11-09 15:25:47 -08:00
										 |  |  |           [{ | 
					
						
							|  |  |  |             matcher: matcher, | 
					
						
							|  |  |  |             component: ComponentA, | 
					
						
							|  |  |  |             children: [{path: 'b', component: ComponentB}] | 
					
						
							| 
									
										
										
										
											2017-04-17 11:13:13 -07:00
										 |  |  |           }] as any, | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           '/a/1;p=99/b'); | 
					
						
							|  |  |  |       const a = s.root.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA); | 
					
						
							|  |  |  |       checkActivatedRoute(a.firstChild!, 'b', {}, ComponentB); | 
					
						
							| 
									
										
										
										
											2016-11-09 15:25:47 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-03-01 21:37:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should work with terminal route', () => { | 
					
						
							|  |  |  |       const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize([{matcher, component: ComponentA}] as any, ''); | 
					
						
							|  |  |  |       const a = s.root.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(a, '', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2017-03-01 21:37:28 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should work with child terminal route', () => { | 
					
						
							|  |  |  |       const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize( | 
					
						
							| 
									
										
										
										
											2017-03-01 21:37:28 +01:00
										 |  |  |           [{path: 'a', component: ComponentA, children: [{matcher, component: ComponentB}]}] as any, | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |           'a'); | 
					
						
							|  |  |  |       const a = s.root.firstChild!; | 
					
						
							|  |  |  |       checkActivatedRoute(a, 'a', {}, ComponentA); | 
					
						
							| 
									
										
										
										
											2017-03-01 21:37:28 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-11-09 15:25:47 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   describe('query parameters', () => { | 
					
						
							|  |  |  |     it('should support query params', () => { | 
					
						
							| 
									
										
										
										
											2016-05-26 16:51:44 -07:00
										 |  |  |       const config = [{path: 'a', component: ComponentA}]; | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize(config, 'a?q=11'); | 
					
						
							|  |  |  |       expect(s.root.queryParams).toEqual({q: '11'}); | 
					
						
							|  |  |  |       expect(s.root.queryParamMap.get('q')).toEqual('11'); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-07-14 13:33:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should freeze query params object', () => { | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize([{path: 'a', component: ComponentA}], 'a?q=11'); | 
					
						
							|  |  |  |       expect(Object.isFrozen(s.root.queryParams)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2016-07-14 13:33:05 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-08 12:16:01 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should not freeze UrlTree query params', () => { | 
					
						
							|  |  |  |       const url = tree('a?q=11'); | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize([{path: 'a', component: ComponentA}], 'a?q=11'); | 
					
						
							|  |  |  |       expect(Object.isFrozen(url.queryParams)).toBe(false); | 
					
						
							| 
									
										
										
										
											2018-03-08 12:16:01 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   describe('fragment', () => { | 
					
						
							|  |  |  |     it('should support fragment', () => { | 
					
						
							| 
									
										
										
										
											2016-05-26 16:51:44 -07:00
										 |  |  |       const config = [{path: 'a', component: ComponentA}]; | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  |       const s = recognize(config, 'a#f1'); | 
					
						
							|  |  |  |       expect(s.root.fragment).toEqual('f1'); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 09:26:57 -08:00
										 |  |  | function recognize( | 
					
						
							|  |  |  |     config: Routes, url: string, paramsInheritanceStrategy: 'emptyOnly'|'always' = 'emptyOnly', | 
					
						
							|  |  |  |     relativeLinkResolution: 'legacy'|'corrected' = 'legacy'): RouterStateSnapshot { | 
					
						
							|  |  |  |   const result = | 
					
						
							|  |  |  |       new Recognizer( | 
					
						
							|  |  |  |           RootComponent, config, tree(url), url, paramsInheritanceStrategy, relativeLinkResolution) | 
					
						
							|  |  |  |           .recognize(); | 
					
						
							|  |  |  |   expect(result).not.toBeNull(); | 
					
						
							|  |  |  |   return result!; | 
					
						
							| 
									
										
										
										
											2016-06-14 14:55:59 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | function checkActivatedRoute( | 
					
						
							|  |  |  |     actual: ActivatedRouteSnapshot, url: string, params: Params, cmp: Function, | 
					
						
							|  |  |  |     outlet: string = PRIMARY_OUTLET): void { | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   if (actual === null) { | 
					
						
							| 
									
										
										
										
											2016-06-02 11:30:38 -07:00
										 |  |  |     expect(actual).not.toBeNull(); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     expect(actual.url.map(s => s.path).join('/')).toEqual(url); | 
					
						
							| 
									
										
										
										
											2016-06-01 13:29:52 -07:00
										 |  |  |     expect(actual.params).toEqual(params); | 
					
						
							| 
									
										
										
										
											2017-10-24 14:54:08 +03:00
										 |  |  |     expect(actual.component as any).toBe(cmp); | 
					
						
							| 
									
										
										
										
											2016-05-23 16:14:23 -07:00
										 |  |  |     expect(actual.outlet).toEqual(outlet); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function tree(url: string): UrlTree { | 
					
						
							|  |  |  |   return new DefaultUrlSerializer().parse(url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RootComponent {} | 
					
						
							|  |  |  | class ComponentA {} | 
					
						
							|  |  |  | class ComponentB {} | 
					
						
							|  |  |  | class ComponentC {} | 
					
						
							| 
									
										
										
										
											2016-06-24 11:17:17 -07:00
										 |  |  | class ComponentD {} | 
					
						
							|  |  |  | class ComponentE {} |