feat(router): rename UrlPathWithParams into UrlSegment
BREAKING CHANGE: UrlPathWithParams => UrlSegment UrlSegment => UrlSegmentGroup
This commit is contained in:
@ -12,7 +12,7 @@ import {of } from 'rxjs/observable/of';
|
||||
import {applyRedirects} from '../src/apply_redirects';
|
||||
import {Routes} from '../src/config';
|
||||
import {LoadedRouterConfig} from '../src/router_config_loader';
|
||||
import {DefaultUrlSerializer, UrlSegment, UrlTree, equalPathsWithParams} from '../src/url_tree';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, UrlTree, equalSegments} from '../src/url_tree';
|
||||
|
||||
describe('applyRedirects', () => {
|
||||
|
||||
@ -367,10 +367,9 @@ function compareTrees(actual: UrlTree, expected: UrlTree): void {
|
||||
compareSegments(actual.root, expected.root, error);
|
||||
}
|
||||
|
||||
function compareSegments(actual: UrlSegment, expected: UrlSegment, error: string): void {
|
||||
function compareSegments(actual: UrlSegmentGroup, expected: UrlSegmentGroup, error: string): void {
|
||||
expect(actual).toBeDefined(error);
|
||||
expect(equalPathsWithParams(actual.pathsWithParams, expected.pathsWithParams))
|
||||
.toEqual(true, error);
|
||||
expect(equalSegments(actual.segments, expected.segments)).toEqual(true, error);
|
||||
|
||||
expect(Object.keys(actual.children).length).toEqual(Object.keys(expected.children).length, error);
|
||||
|
||||
|
@ -11,12 +11,12 @@ import {createRouterState} from '../src/create_router_state';
|
||||
import {recognize} from '../src/recognize';
|
||||
import {ActivatedRoute, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState} from '../src/router_state';
|
||||
import {PRIMARY_OUTLET, Params} from '../src/shared';
|
||||
import {DefaultUrlSerializer, UrlSegment, UrlTree} from '../src/url_tree';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, UrlTree} from '../src/url_tree';
|
||||
import {TreeNode} from '../src/utils/tree';
|
||||
|
||||
describe('create router state', () => {
|
||||
const emptyState = () =>
|
||||
createEmptyState(new UrlTree(new UrlSegment([], {}), {}, null), RootComponent);
|
||||
createEmptyState(new UrlTree(new UrlSegmentGroup([], {}), {}, null), RootComponent);
|
||||
|
||||
it('should work create new state', () => {
|
||||
const state = createRouterState(
|
||||
|
@ -11,7 +11,7 @@ import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
import {createUrlTree} from '../src/create_url_tree';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, advanceActivatedRoute} from '../src/router_state';
|
||||
import {PRIMARY_OUTLET, Params} from '../src/shared';
|
||||
import {DefaultUrlSerializer, UrlPathWithParams, UrlSegment, UrlTree} from '../src/url_tree';
|
||||
import {DefaultUrlSerializer, UrlSegment, UrlSegmentGroup, UrlTree} from '../src/url_tree';
|
||||
|
||||
describe('createUrlTree', () => {
|
||||
const serializer = new DefaultUrlSerializer();
|
||||
@ -37,7 +37,7 @@ describe('createUrlTree', () => {
|
||||
it('should stringify positional parameters', () => {
|
||||
const p = serializer.parse('/a/b');
|
||||
const t = createRoot(p, ['/one', 11]);
|
||||
const params = t.root.children[PRIMARY_OUTLET].pathsWithParams;
|
||||
const params = t.root.children[PRIMARY_OUTLET].segments;
|
||||
expect(params[0].path).toEqual('one');
|
||||
expect(params[1].path).toEqual('11');
|
||||
});
|
||||
@ -209,8 +209,8 @@ function createRoot(tree: UrlTree, commands: any[], queryParams?: Params, fragme
|
||||
}
|
||||
|
||||
function create(
|
||||
segment: UrlSegment, startIndex: number, tree: UrlTree, commands: any[], queryParams?: Params,
|
||||
fragment?: string) {
|
||||
segment: UrlSegmentGroup, startIndex: number, tree: UrlTree, commands: any[],
|
||||
queryParams?: Params, fragment?: string) {
|
||||
if (!segment) {
|
||||
expect(segment).toBeDefined();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {Routes} from '../src/config';
|
||||
import {recognize} from '../src/recognize';
|
||||
import {resolve} from '../src/resolve';
|
||||
import {RouterStateSnapshot} from '../src/router_state';
|
||||
import {DefaultUrlSerializer, UrlSegment, UrlTree} from '../src/url_tree';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, UrlTree} from '../src/url_tree';
|
||||
|
||||
describe('resolve', () => {
|
||||
it('should resolve components', () => {
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {PRIMARY_OUTLET} from '../src/shared';
|
||||
import {DefaultUrlSerializer, UrlSegment, serializePath} from '../src/url_tree';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, serializePath} from '../src/url_tree';
|
||||
|
||||
describe('url serializer', () => {
|
||||
const url = new DefaultUrlSerializer();
|
||||
@ -174,8 +174,8 @@ describe('url serializer', () => {
|
||||
`/${encodeURIComponent("one two")};${encodeURIComponent("p 1")}=${encodeURIComponent("v 1")};${encodeURIComponent("p 2")}=${encodeURIComponent("v 2")}`;
|
||||
const tree = url.parse(u);
|
||||
|
||||
expect(tree.root.children[PRIMARY_OUTLET].pathsWithParams[0].path).toEqual('one two');
|
||||
expect(tree.root.children[PRIMARY_OUTLET].pathsWithParams[0].parameters)
|
||||
expect(tree.root.children[PRIMARY_OUTLET].segments[0].path).toEqual('one two');
|
||||
expect(tree.root.children[PRIMARY_OUTLET].segments[0].parameters)
|
||||
.toEqual({['p 1']: 'v 1', ['p 2']: 'v 2'});
|
||||
expect(url.serialize(tree)).toEqual(u);
|
||||
});
|
||||
@ -210,11 +210,12 @@ describe('url serializer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function expectSegment(segment: UrlSegment, expected: string, hasChildren: boolean = false): void {
|
||||
if (segment.pathsWithParams.filter(s => s.path === '').length > 0) {
|
||||
throw new Error(`UrlPathWithParams cannot be empty ${segment.pathsWithParams}`);
|
||||
function expectSegment(
|
||||
segment: UrlSegmentGroup, expected: string, hasChildren: boolean = false): void {
|
||||
if (segment.segments.filter(s => s.path === '').length > 0) {
|
||||
throw new Error(`UrlSegments cannot be empty ${segment.segments}`);
|
||||
}
|
||||
const p = segment.pathsWithParams.map(p => serializePath(p)).join('/');
|
||||
const p = segment.segments.map(p => serializePath(p)).join('/');
|
||||
expect(p).toEqual(expected);
|
||||
expect(Object.keys(segment.children).length > 0).toEqual(hasChildren);
|
||||
}
|
||||
|
Reference in New Issue
Block a user