fix(router): add segmentPath to the link DSL
This commit is contained in:
@ -13,7 +13,7 @@ import {ActivatedRoute, ActivatedRouteSnapshot, advanceActivatedRoute} from '../
|
||||
import {PRIMARY_OUTLET, Params} from '../src/shared';
|
||||
import {DefaultUrlSerializer, UrlSegment, UrlSegmentGroup, UrlTree} from '../src/url_tree';
|
||||
|
||||
describe('createUrlTree', () => {
|
||||
fdescribe('createUrlTree', () => {
|
||||
const serializer = new DefaultUrlSerializer();
|
||||
|
||||
it('should navigate to the root', () => {
|
||||
@ -42,6 +42,12 @@ describe('createUrlTree', () => {
|
||||
expect(params[1].path).toEqual('11');
|
||||
});
|
||||
|
||||
it('should support first segments contaings slashes', () => {
|
||||
const p = serializer.parse('/');
|
||||
const t = createRoot(p, [{segmentPath: '/one'}, 'two/three']);
|
||||
expect(serializer.serialize(t)).toEqual('/%2Fone/two%2Fthree');
|
||||
});
|
||||
|
||||
it('should preserve secondary segments', () => {
|
||||
const p = serializer.parse('/a/11/b(right:c)');
|
||||
const t = createRoot(p, ['/a', 11, 'd']);
|
||||
@ -98,7 +104,7 @@ describe('createUrlTree', () => {
|
||||
|
||||
it('should create matrix parameters together with other segments', () => {
|
||||
const p = serializer.parse('/a');
|
||||
const t = createRoot(p, ['/a', '/b', {aa: 22, bb: 33}]);
|
||||
const t = createRoot(p, ['/a', 'b', {aa: 22, bb: 33}]);
|
||||
expect(serializer.serialize(t)).toEqual('/a/b;aa=22;bb=33');
|
||||
});
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {PRIMARY_OUTLET} from '../src/shared';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, serializePath} from '../src/url_tree';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, decode, encode, serializePath} from '../src/url_tree';
|
||||
|
||||
describe('url serializer', () => {
|
||||
const url = new DefaultUrlSerializer();
|
||||
@ -181,7 +181,7 @@ describe('url serializer', () => {
|
||||
describe('encoding/decoding', () => {
|
||||
it('should encode/decode path segments and parameters', () => {
|
||||
const u =
|
||||
`/${encodeURIComponent("one two")};${encodeURIComponent("p 1")}=${encodeURIComponent("v 1")};${encodeURIComponent("p 2")}=${encodeURIComponent("v 2")}`;
|
||||
`/${encode("one two")};${encode("p 1")}=${encode("v 1")};${encode("p 2")}=${encode("v 2")}`;
|
||||
const tree = url.parse(u);
|
||||
|
||||
expect(tree.root.children[PRIMARY_OUTLET].segments[0].path).toEqual('one two');
|
||||
@ -190,9 +190,16 @@ describe('url serializer', () => {
|
||||
expect(url.serialize(tree)).toEqual(u);
|
||||
});
|
||||
|
||||
it('should encode/decode "slash" in path segments and parameters', () => {
|
||||
const u = `/${encode("one/two")};${encode("p/1")}=${encode("v/1")}/three`;
|
||||
const tree = url.parse(u);
|
||||
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'});
|
||||
expect(url.serialize(tree)).toEqual(u);
|
||||
});
|
||||
|
||||
it('should encode/decode query params', () => {
|
||||
const u =
|
||||
`/one?${encodeURIComponent("p 1")}=${encodeURIComponent("v 1")}&${encodeURIComponent("p 2")}=${encodeURIComponent("v 2")}`;
|
||||
const u = `/one?${encode("p 1")}=${encode("v 1")}&${encode("p 2")}=${encode("v 2")}`;
|
||||
const tree = url.parse(u);
|
||||
|
||||
expect(tree.queryParams).toEqual({['p 1']: 'v 1', ['p 2']: 'v 2'});
|
||||
@ -200,7 +207,7 @@ describe('url serializer', () => {
|
||||
});
|
||||
|
||||
it('should encode/decode fragment', () => {
|
||||
const u = `/one#${encodeURIComponent("one two")}`;
|
||||
const u = `/one#${encode("one two")}`;
|
||||
const tree = url.parse(u);
|
||||
|
||||
expect(tree.fragment).toEqual('one two');
|
||||
|
Reference in New Issue
Block a user