@ -9,21 +9,21 @@
|
||||
import {Routes} from '../src/config';
|
||||
import {recognize} from '../src/recognize';
|
||||
import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';
|
||||
import {PRIMARY_OUTLET, Params} from '../src/shared';
|
||||
import {Params, PRIMARY_OUTLET} from '../src/shared';
|
||||
import {DefaultUrlSerializer, UrlTree} from '../src/url_tree';
|
||||
|
||||
describe('recognize', () => {
|
||||
it('should work', () => {
|
||||
checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: any) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
||||
it('should freeze params object', () => {
|
||||
checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
const child = (s as any).firstChild(s.root) !;
|
||||
const child = (s as any).firstChild(s.root)!;
|
||||
expect(Object.isFrozen(child.params)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -79,11 +79,11 @@ describe('recognize', () => {
|
||||
expect((s.root as any)._urlSegment).toBe(url.root);
|
||||
expect((s.root as any)._lastPathIndex).toBe(-1);
|
||||
|
||||
const compA = (s as any).firstChild(s.root) !;
|
||||
const compA = (s as any).firstChild(s.root)!;
|
||||
expect(compA._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]);
|
||||
expect(compA._lastPathIndex).toBe(1);
|
||||
|
||||
const compC = (s as any).firstChild(<any>compA) !;
|
||||
const compC = (s as any).firstChild(<any>compA)!;
|
||||
expect(compC._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]);
|
||||
expect(compC._lastPathIndex).toBe(2);
|
||||
});
|
||||
@ -101,11 +101,11 @@ describe('recognize', () => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
const compA = (s as any).firstChild(s.root) !;
|
||||
const compA = (s as any).firstChild(s.root)!;
|
||||
expect(compA._urlSegment).toBe((url as any).root.children[PRIMARY_OUTLET]);
|
||||
expect(compA._lastPathIndex).toBe(0);
|
||||
|
||||
const compC = (s as any).firstChild(<any>compA) !;
|
||||
const compC = (s as any).firstChild(<any>compA)!;
|
||||
expect(compC._urlSegment).toBe((url as any).root.children[PRIMARY_OUTLET]);
|
||||
expect(compC._lastPathIndex).toBe(2);
|
||||
});
|
||||
@ -119,9 +119,9 @@ describe('recognize', () => {
|
||||
],
|
||||
'a/paramA', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
checkActivatedRoute(
|
||||
(s as any).firstChild(<any>(s as any).firstChild(s.root)) !, 'paramA', {id: 'paramA'},
|
||||
(s as any).firstChild(<any>(s as any).firstChild(s.root))!, 'paramA', {id: 'paramA'},
|
||||
ComponentB);
|
||||
});
|
||||
|
||||
@ -130,7 +130,7 @@ describe('recognize', () => {
|
||||
(s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
checkActivatedRoute(
|
||||
(s as any).firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC);
|
||||
(s as any).firstChild(s.root)!, 'a/paramA', {id: 'paramA'}, ComponentC);
|
||||
});
|
||||
});
|
||||
|
||||
@ -154,8 +154,7 @@ describe('recognize', () => {
|
||||
path: 'a',
|
||||
component: ComponentA,
|
||||
children: [
|
||||
{path: 'b', component: ComponentB},
|
||||
{path: 'c', component: ComponentC, outlet: 'left'}
|
||||
{path: 'b', component: ComponentB}, {path: 'c', component: ComponentC, outlet: 'left'}
|
||||
]
|
||||
},
|
||||
],
|
||||
@ -190,7 +189,7 @@ describe('recognize', () => {
|
||||
const c = (s as any).children(s.root);
|
||||
checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA);
|
||||
checkActivatedRoute(
|
||||
(s as any).firstChild(<any>c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB);
|
||||
(s as any).firstChild(<any>c[0])!, 'b', {b1: '111', b2: '222'}, ComponentB);
|
||||
checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left');
|
||||
});
|
||||
});
|
||||
@ -199,7 +198,7 @@ describe('recognize', () => {
|
||||
it('should set static data', () => {
|
||||
checkRecognize(
|
||||
[{path: 'a', data: {one: 1}, component: ComponentA}], 'a', (s: RouterStateSnapshot) => {
|
||||
const r: ActivatedRouteSnapshot = (s as any).firstChild(s.root) !;
|
||||
const r: ActivatedRouteSnapshot = (s as any).firstChild(s.root)!;
|
||||
expect(r.data).toEqual({one: 1});
|
||||
});
|
||||
});
|
||||
@ -213,7 +212,7 @@ describe('recognize', () => {
|
||||
}],
|
||||
'a/b', (s: RouterStateSnapshot) => {
|
||||
const r: ActivatedRouteSnapshot =
|
||||
(s as any).firstChild(<any>(s as any).firstChild(s.root)) !;
|
||||
(s as any).firstChild(<any>(s as any).firstChild(s.root))!;
|
||||
expect(r.data).toEqual({one: 1, two: 2});
|
||||
});
|
||||
});
|
||||
@ -227,7 +226,7 @@ describe('recognize', () => {
|
||||
children: [{path: 'b', data: {two: 2}, component: ComponentB}]
|
||||
}],
|
||||
'a/b', (s: any /* RouterStateSnapshot */) => {
|
||||
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !;
|
||||
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root))!;
|
||||
expect(r.data).toEqual({two: 2});
|
||||
});
|
||||
});
|
||||
@ -241,7 +240,7 @@ describe('recognize', () => {
|
||||
children: [{path: 'b', data: {two: 2}, component: ComponentB}]
|
||||
}],
|
||||
'a/b', (s: any /* RouterStateSnapshot */) => {
|
||||
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !;
|
||||
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root))!;
|
||||
expect(r.data).toEqual({one: 1, two: 2});
|
||||
}, 'always');
|
||||
});
|
||||
@ -249,7 +248,7 @@ describe('recognize', () => {
|
||||
it('should set resolved data', () => {
|
||||
checkRecognize(
|
||||
[{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a', (s: any) => {
|
||||
const r: any = s.firstChild(s.root) !;
|
||||
const r: any = s.firstChild(s.root)!;
|
||||
expect(r._resolve).toEqual({one: 'some-token'});
|
||||
});
|
||||
});
|
||||
@ -259,7 +258,7 @@ describe('recognize', () => {
|
||||
describe('root', () => {
|
||||
it('should work', () => {
|
||||
checkRecognize([{path: '', component: ComponentA}], '', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, '', {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
||||
@ -267,7 +266,7 @@ describe('recognize', () => {
|
||||
checkRecognize(
|
||||
[{path: '', pathMatch: 'full', component: ComponentA}], '',
|
||||
(s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, '', {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
||||
@ -275,9 +274,9 @@ describe('recognize', () => {
|
||||
checkRecognize(
|
||||
[{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '',
|
||||
(s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, '', {}, ComponentA);
|
||||
checkActivatedRoute(
|
||||
(s as any).firstChild(<any>(s as any).firstChild(s.root)) !, '', {}, ComponentB);
|
||||
(s as any).firstChild(<any>(s as any).firstChild(s.root))!, '', {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
@ -291,11 +290,11 @@ describe('recognize', () => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
const c = s.firstChild(s.root) !;
|
||||
const c = s.firstChild(s.root)!;
|
||||
expect(c._urlSegment).toBe(url.root);
|
||||
expect(c._lastPathIndex).toBe(-1);
|
||||
|
||||
const c2 = s.firstChild(<any>s.firstChild(s.root)) !;
|
||||
const c2 = s.firstChild(<any>s.firstChild(s.root))!;
|
||||
expect(c2._urlSegment).toBe(url.root);
|
||||
expect(c2._lastPathIndex).toBe(-1);
|
||||
});
|
||||
@ -306,17 +305,15 @@ describe('recognize', () => {
|
||||
[{
|
||||
path: 'a',
|
||||
component: ComponentA,
|
||||
children: [
|
||||
{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}
|
||||
]
|
||||
children:
|
||||
[{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}]
|
||||
}],
|
||||
'/a;p=1', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {p: '1'}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {p: '1'}, ComponentA);
|
||||
checkActivatedRoute(
|
||||
(s as any).firstChild((s as any).firstChild(s.root) !) !, '', {p: '1'},
|
||||
ComponentB);
|
||||
(s as any).firstChild((s as any).firstChild(s.root)!)!, '', {p: '1'}, ComponentB);
|
||||
checkActivatedRoute(
|
||||
(s as any).firstChild((s as any).firstChild((s as any).firstChild(s.root) !) !) !,
|
||||
(s as any).firstChild((s as any).firstChild((s as any).firstChild(s.root)!)!)!,
|
||||
'', {p: '1'}, ComponentC);
|
||||
});
|
||||
});
|
||||
@ -329,14 +326,13 @@ describe('recognize', () => {
|
||||
path: 'a',
|
||||
component: ComponentA,
|
||||
children: [
|
||||
{path: 'b', component: ComponentB},
|
||||
{path: '', component: ComponentC, outlet: 'aux'}
|
||||
{path: 'b', component: ComponentB}, {path: '', component: ComponentC, outlet: 'aux'}
|
||||
]
|
||||
}],
|
||||
'a/b', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
|
||||
const c = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const c = (s as any).children((s as any).firstChild(s.root)!);
|
||||
checkActivatedRoute(c[0], 'b', {}, ComponentB);
|
||||
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
|
||||
});
|
||||
@ -365,13 +361,13 @@ describe('recognize', () => {
|
||||
|
||||
checkRecognize(config, 'parent/b', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'parent', {}, undefined !);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'parent', {}, undefined!);
|
||||
|
||||
const cc = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const cc = (s as any).children((s as any).firstChild(s.root)!);
|
||||
checkActivatedRoute(cc[0], '', {}, ComponentA);
|
||||
checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary');
|
||||
|
||||
checkActivatedRoute((s as any).firstChild(cc[0]) !, 'b', {}, ComponentB);
|
||||
checkActivatedRoute((s as any).firstChild(cc[0])!, 'b', {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
@ -386,9 +382,9 @@ describe('recognize', () => {
|
||||
]
|
||||
}],
|
||||
'a/b', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
|
||||
const c = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const c = (s as any).children((s as any).firstChild(s.root)!);
|
||||
expect(c.length).toEqual(1);
|
||||
checkActivatedRoute(c[0], 'b', {}, ComponentB);
|
||||
});
|
||||
@ -401,8 +397,7 @@ describe('recognize', () => {
|
||||
path: 'a',
|
||||
component: ComponentA,
|
||||
children: [
|
||||
{path: 'b', component: ComponentB},
|
||||
{path: '', component: ComponentC, outlet: 'aux'}
|
||||
{path: 'b', component: ComponentB}, {path: '', component: ComponentC, outlet: 'aux'}
|
||||
]
|
||||
}],
|
||||
url, 'a/b')
|
||||
@ -410,11 +405,11 @@ describe('recognize', () => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
const a = s.firstChild(s.root) !;
|
||||
const a = s.firstChild(s.root)!;
|
||||
expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(a._lastPathIndex).toBe(0);
|
||||
|
||||
const b = s.firstChild(a) !;
|
||||
const b = s.firstChild(a)!;
|
||||
expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(b._lastPathIndex).toBe(1);
|
||||
|
||||
@ -429,24 +424,23 @@ describe('recognize', () => {
|
||||
recognize(
|
||||
RootComponent, [{
|
||||
path: 'a',
|
||||
children: [
|
||||
{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}
|
||||
]
|
||||
children:
|
||||
[{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}]
|
||||
}],
|
||||
url, 'a')
|
||||
.forEach((s: any) => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
const a = s.firstChild(s.root) !;
|
||||
const a = s.firstChild(s.root)!;
|
||||
expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(a._lastPathIndex).toBe(0);
|
||||
|
||||
const b = s.firstChild(a) !;
|
||||
const b = s.firstChild(a)!;
|
||||
expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(b._lastPathIndex).toBe(0);
|
||||
|
||||
const c = s.firstChild(b) !;
|
||||
const c = s.firstChild(b)!;
|
||||
expect(c._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(c._lastPathIndex).toBe(0);
|
||||
});
|
||||
@ -473,19 +467,19 @@ describe('recognize', () => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
const a = s.firstChild(s.root) !;
|
||||
const a = s.firstChild(s.root)!;
|
||||
expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(a._lastPathIndex).toBe(0);
|
||||
|
||||
const b = s.firstChild(a) !;
|
||||
const b = s.firstChild(a)!;
|
||||
expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(b._lastPathIndex).toBe(1);
|
||||
|
||||
const c = s.firstChild(b) !;
|
||||
const c = s.firstChild(b)!;
|
||||
expect(c._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(c._lastPathIndex).toBe(1);
|
||||
|
||||
const d = s.firstChild(c) !;
|
||||
const d = s.firstChild(c)!;
|
||||
expect(d._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
|
||||
expect(d._lastPathIndex).toBe(1);
|
||||
});
|
||||
@ -496,24 +490,23 @@ describe('recognize', () => {
|
||||
recognize(
|
||||
RootComponent, [{
|
||||
path: '',
|
||||
children: [
|
||||
{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}
|
||||
]
|
||||
children:
|
||||
[{path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}]
|
||||
}],
|
||||
url, '')
|
||||
.forEach((s: any) => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
const a = (s as any).firstChild(s.root) !;
|
||||
const a = (s as any).firstChild(s.root)!;
|
||||
expect(a._urlSegment).toBe(url.root);
|
||||
expect(a._lastPathIndex).toBe(-1);
|
||||
|
||||
const b = (s as any).firstChild(a) !;
|
||||
const b = (s as any).firstChild(a)!;
|
||||
expect(b._urlSegment).toBe(url.root);
|
||||
expect(b._lastPathIndex).toBe(-1);
|
||||
|
||||
const c = (s as any).firstChild(b) !;
|
||||
const c = (s as any).firstChild(b)!;
|
||||
expect(c._urlSegment).toBe(url.root);
|
||||
expect(c._lastPathIndex).toBe(-1);
|
||||
});
|
||||
@ -532,9 +525,9 @@ describe('recognize', () => {
|
||||
]
|
||||
}],
|
||||
'a', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
|
||||
const c = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const c = (s as any).children((s as any).firstChild(s.root)!);
|
||||
checkActivatedRoute(c[0], '', {}, ComponentB);
|
||||
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
|
||||
});
|
||||
@ -551,9 +544,9 @@ describe('recognize', () => {
|
||||
]
|
||||
}],
|
||||
'a', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
|
||||
const c = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const c = (s as any).children((s as any).firstChild(s.root)!);
|
||||
checkActivatedRoute(c[0], '', {}, ComponentB);
|
||||
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
|
||||
});
|
||||
@ -570,9 +563,9 @@ describe('recognize', () => {
|
||||
]
|
||||
}],
|
||||
'a/(aux:c)', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
|
||||
const c = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const c = (s as any).children((s as any).firstChild(s.root)!);
|
||||
checkActivatedRoute(c[0], '', {}, ComponentB);
|
||||
checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux');
|
||||
});
|
||||
@ -612,13 +605,13 @@ describe('recognize', () => {
|
||||
]
|
||||
}],
|
||||
'a/(d//aux:e)', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a', {}, ComponentA);
|
||||
|
||||
const c = (s as any).children((s as any).firstChild(s.root) !);
|
||||
const c = (s as any).children((s as any).firstChild(s.root)!);
|
||||
checkActivatedRoute(c[0], '', {}, ComponentB);
|
||||
checkActivatedRoute((s as any).firstChild(c[0]) !, 'd', {}, ComponentD);
|
||||
checkActivatedRoute((s as any).firstChild(c[0])!, 'd', {}, ComponentD);
|
||||
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
|
||||
checkActivatedRoute((s as any).firstChild(c[1]) !, 'e', {}, ComponentE);
|
||||
checkActivatedRoute((s as any).firstChild(c[1])!, 'e', {}, ComponentE);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -628,7 +621,7 @@ describe('recognize', () => {
|
||||
it('should support simple wildcards', () => {
|
||||
checkRecognize(
|
||||
[{path: '**', component: ComponentA}], 'a/b/c/d;a1=11', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute((s as any).firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA);
|
||||
checkActivatedRoute((s as any).firstChild(s.root)!, 'a/b/c/d', {a1: '11'}, ComponentA);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -639,13 +632,12 @@ describe('recognize', () => {
|
||||
[{
|
||||
path: 'p/:id',
|
||||
children: [
|
||||
{path: 'a', component: ComponentA},
|
||||
{path: 'b', component: ComponentB, outlet: 'aux'}
|
||||
{path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'aux'}
|
||||
]
|
||||
}],
|
||||
'p/11;pp=22/(a;pa=33//aux:b;pb=44)', (s: RouterStateSnapshot) => {
|
||||
const p = (s as any).firstChild(s.root) !;
|
||||
checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined !);
|
||||
const p = (s as any).firstChild(s.root)!;
|
||||
checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined!);
|
||||
|
||||
const c = (s as any).children(p);
|
||||
checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA);
|
||||
@ -659,24 +651,22 @@ describe('recognize', () => {
|
||||
path: 'p/:id',
|
||||
children: [{
|
||||
path: 'a/:name',
|
||||
children: [{
|
||||
path: 'b',
|
||||
component: ComponentB,
|
||||
children: [{path: 'c', component: ComponentC}]
|
||||
}]
|
||||
children: [
|
||||
{path: 'b', component: ComponentB, children: [{path: 'c', component: ComponentC}]}
|
||||
]
|
||||
}]
|
||||
}],
|
||||
'p/11/a/victor/b/c', (s: RouterStateSnapshot) => {
|
||||
const p = (s as any).firstChild(s.root) !;
|
||||
checkActivatedRoute(p, 'p/11', {id: '11'}, undefined !);
|
||||
const p = (s as any).firstChild(s.root)!;
|
||||
checkActivatedRoute(p, 'p/11', {id: '11'}, undefined!);
|
||||
|
||||
const a = (s as any).firstChild(p) !;
|
||||
checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined !);
|
||||
const a = (s as any).firstChild(p)!;
|
||||
checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined!);
|
||||
|
||||
const b = (s as any).firstChild(a) !;
|
||||
const b = (s as any).firstChild(a)!;
|
||||
checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB);
|
||||
|
||||
const c = (s as any).firstChild(b) !;
|
||||
const c = (s as any).firstChild(b)!;
|
||||
checkActivatedRoute(c, 'c', {}, ComponentC);
|
||||
});
|
||||
});
|
||||
@ -687,15 +677,13 @@ describe('recognize', () => {
|
||||
path: 'p/:id',
|
||||
children: [{
|
||||
path: 'a/:name',
|
||||
children: [{
|
||||
path: 'b',
|
||||
component: ComponentB,
|
||||
children: [{path: 'c', component: ComponentC}]
|
||||
}]
|
||||
children: [
|
||||
{path: 'b', component: ComponentB, children: [{path: 'c', component: ComponentC}]}
|
||||
]
|
||||
}]
|
||||
}],
|
||||
'p/11/a/victor/b/c', (s: any /* RouterStateSnapshot */) => {
|
||||
const c = s.firstChild(s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !) !;
|
||||
const c = s.firstChild(s.firstChild(s.firstChild(s.firstChild(s.root)!)!)!)!;
|
||||
checkActivatedRoute(c, 'c', {id: '11', name: 'victor'}, ComponentC);
|
||||
}, 'always');
|
||||
});
|
||||
@ -707,7 +695,7 @@ describe('recognize', () => {
|
||||
[{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}],
|
||||
'/a', (s: RouterStateSnapshot) => {
|
||||
const a = (s as any).firstChild(s.root);
|
||||
checkActivatedRoute(a !, 'a', {}, ComponentA);
|
||||
checkActivatedRoute(a!, 'a', {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
||||
@ -722,7 +710,7 @@ describe('recognize', () => {
|
||||
]
|
||||
}],
|
||||
'/a', (s: RouterStateSnapshot) => {
|
||||
const a = (s as any).firstChild(s.root) !;
|
||||
const a = (s as any).firstChild(s.root)!;
|
||||
checkActivatedRoute(a, 'a', {}, ComponentA);
|
||||
checkActivatedRoute((a as any).children[0], '', {}, ComponentC, 'aux');
|
||||
});
|
||||
@ -746,9 +734,9 @@ describe('recognize', () => {
|
||||
children: [{path: 'b', component: ComponentB}]
|
||||
}] as any,
|
||||
'/a/1;p=99/b', (s: RouterStateSnapshot) => {
|
||||
const a = (s as any).root.firstChild !;
|
||||
const a = (s as any).root.firstChild!;
|
||||
checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA);
|
||||
checkActivatedRoute((a as any).firstChild !, 'b', {}, ComponentB);
|
||||
checkActivatedRoute((a as any).firstChild!, 'b', {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
@ -756,7 +744,7 @@ describe('recognize', () => {
|
||||
const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null;
|
||||
|
||||
checkRecognize([{matcher, component: ComponentA}] as any, '', (s: RouterStateSnapshot) => {
|
||||
const a = (s as any).root.firstChild !;
|
||||
const a = (s as any).root.firstChild!;
|
||||
checkActivatedRoute(a, '', {}, ComponentA);
|
||||
});
|
||||
});
|
||||
@ -767,7 +755,7 @@ describe('recognize', () => {
|
||||
checkRecognize(
|
||||
[{path: 'a', component: ComponentA, children: [{matcher, component: ComponentB}]}] as any,
|
||||
'a', (s: RouterStateSnapshot) => {
|
||||
const a = (s as any).root.firstChild !;
|
||||
const a = (s as any).root.firstChild!;
|
||||
checkActivatedRoute(a, 'a', {}, ComponentA);
|
||||
});
|
||||
});
|
||||
@ -800,8 +788,9 @@ describe('recognize', () => {
|
||||
describe('fragment', () => {
|
||||
it('should support fragment', () => {
|
||||
const config = [{path: 'a', component: ComponentA}];
|
||||
checkRecognize(
|
||||
config, 'a#f1', (s: RouterStateSnapshot) => { expect(s.root.fragment).toEqual('f1'); });
|
||||
checkRecognize(config, 'a#f1', (s: RouterStateSnapshot) => {
|
||||
expect(s.root.fragment).toEqual('f1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -825,9 +814,11 @@ describe('recognize', () => {
|
||||
|
||||
function checkRecognize(
|
||||
config: Routes, url: string, callback: any,
|
||||
paramsInheritanceStrategy?: 'emptyOnly' | 'always'): void {
|
||||
paramsInheritanceStrategy?: 'emptyOnly'|'always'): void {
|
||||
recognize(RootComponent, config, tree(url), url, paramsInheritanceStrategy)
|
||||
.subscribe(callback, e => { throw e; });
|
||||
.subscribe(callback, e => {
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
function checkActivatedRoute(
|
||||
|
Reference in New Issue
Block a user