This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
/
Copy pathrouteParamsSpec.js
121 lines (95 loc) · 3.65 KB
/
routeParamsSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
describe('$routeParams', function() {
beforeEach(module('ngRoute'));
it('should publish the params into a service', function() {
module(function($routeProvider) {
$routeProvider.when('/foo', {});
$routeProvider.when('/bar/:barId', {});
});
inject(function($rootScope, $route, $location, $routeParams) {
$location.path('/foo').search('a=b');
$rootScope.$digest();
expect($routeParams).toEqual({a:'b'});
$location.path('/bar/123').search('x=abc');
$rootScope.$digest();
expect($routeParams).toEqual({barId:'123', x:'abc'});
});
});
it('should correctly extract the params when a param name is part of the route', function() {
module(function($routeProvider) {
$routeProvider.when('/bar/:foo/:bar', {});
});
inject(function($rootScope, $route, $location, $routeParams) {
$location.path('/bar/foovalue/barvalue');
$rootScope.$digest();
expect($routeParams).toEqual({bar:'barvalue', foo:'foovalue'});
});
});
it('should support route params not preceded by slashes', function() {
module(function($routeProvider) {
$routeProvider.when('/bar:barId/foo:fooId/', {});
});
inject(function($rootScope, $route, $location, $routeParams) {
$location.path('/barbarvalue/foofoovalue/');
$rootScope.$digest();
expect($routeParams).toEqual({barId: 'barvalue', fooId: 'foovalue'});
});
});
it('should correctly extract the params when an optional param name is part of the route', function() {
module(function($routeProvider) {
$routeProvider.when('/bar/:foo?', {});
$routeProvider.when('/baz/:foo?/edit', {});
$routeProvider.when('/qux/:bar?/:baz?', {});
});
inject(function($rootScope, $route, $location, $routeParams) {
$location.path('/bar');
$rootScope.$digest();
expect($routeParams).toEqual({});
$location.path('/bar/fooValue');
$rootScope.$digest();
expect($routeParams).toEqual({foo: 'fooValue'});
$location.path('/baz/fooValue/edit');
$rootScope.$digest();
expect($routeParams).toEqual({foo: 'fooValue'});
$location.path('/baz/edit');
$rootScope.$digest();
expect($routeParams).toEqual({});
$location.path('/qux//bazValue');
$rootScope.$digest();
expect($routeParams).toEqual({baz: 'bazValue'});
});
});
it('should correctly extract path params containing hashes and/or question marks', function() {
module(function($routeProvider) {
$routeProvider.when('/foo/:bar', {});
$routeProvider.when('/zoo/:bar/:baz/:qux', {});
});
inject(function($location, $rootScope, $routeParams) {
$location.path('/foo/bar?baz');
$rootScope.$digest();
expect($routeParams).toEqual({bar: 'bar?baz'});
$location.path('/foo/bar?baz=val');
$rootScope.$digest();
expect($routeParams).toEqual({bar: 'bar?baz=val'});
$location.path('/foo/bar#baz');
$rootScope.$digest();
expect($routeParams).toEqual({bar: 'bar#baz'});
$location.path('/foo/bar?baz#qux');
$rootScope.$digest();
expect($routeParams).toEqual({bar: 'bar?baz#qux'});
$location.path('/foo/bar?baz=val#qux');
$rootScope.$digest();
expect($routeParams).toEqual({bar: 'bar?baz=val#qux'});
$location.path('/foo/bar#baz?qux');
$rootScope.$digest();
expect($routeParams).toEqual({bar: 'bar#baz?qux'});
$location.path('/zoo/bar?p1=v1#h1/baz?p2=v2#h2/qux?p3=v3#h3');
$rootScope.$digest();
expect($routeParams).toEqual({
bar: 'bar?p1=v1#h1',
baz: 'baz?p2=v2#h2',
qux: 'qux?p3=v3#h3'
});
});
});
});