@angular-wave/angular.ts 0.0.29 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/index.html +5 -6
- package/package.json +1 -1
- package/src/core/controller.js +3 -0
- package/src/directive/controller.js +0 -56
- package/src/directive/controller.md +46 -0
- package/src/router/common/trace.js +1 -1
- package/src/router/directives/state-directives.js +1 -1
- package/src/router/hooks/update-globals.js +1 -1
- package/src/router/hooks/url.js +4 -4
- package/src/router/index.js +0 -6
- package/src/router/injectables.js +9 -60
- package/src/router/resolve/resolve-context.js +1 -1
- package/src/router/router.js +3 -95
- package/src/router/services.js +2 -58
- package/src/router/state/state-builder.js +7 -6
- package/src/router/state/state-object.js +1 -1
- package/src/router/state/state-registry.js +6 -5
- package/src/router/state/state-service.js +4 -5
- package/src/router/state/target-state.js +1 -1
- package/src/router/state/views.js +1 -1
- package/src/router/url/url-config.js +25 -2
- package/src/router/url/url-matcher.js +0 -8
- package/src/router/url/url-service.js +138 -8
- package/src/router/view/view.js +3 -1
- package/src/shared/common.js +2 -2
- package/test/router/services.spec.js +8 -17
- package/test/router/{url-matcher-factory.spec.js → url-service.spec.js} +126 -130
- package/test/router/view.spec.js +4 -11
- package/types/router/core/common/coreservices.d.ts +2 -2
- package/types/router/core/common/trace.d.ts +7 -7
- package/types/router/core/globals.d.ts +2 -1
- package/types/router/core/interface.d.ts +3 -10
- package/types/router/core/params/interface.d.ts +5 -5
- package/types/router/core/resolve/resolveContext.d.ts +4 -4
- package/types/router/core/router.d.ts +5 -51
- package/types/router/core/state/interface.d.ts +6 -6
- package/types/router/core/state/stateObject.d.ts +1 -1
- package/types/router/core/state/stateQueueManager.d.ts +2 -2
- package/types/router/core/state/stateRegistry.d.ts +4 -4
- package/types/router/core/state/stateService.d.ts +9 -9
- package/types/router/core/state/targetState.d.ts +1 -1
- package/types/router/core/transition/interface.d.ts +1 -1
- package/types/router/core/transition/transition.d.ts +12 -12
- package/types/router/core/transition/transitionService.d.ts +5 -5
- package/types/router/core/url/interface.d.ts +3 -3
- package/types/router/core/url/urlConfig.d.ts +3 -3
- package/types/router/core/url/urlMatcherFactory.d.ts +4 -4
- package/types/router/core/url/urlRouter.d.ts +2 -2
- package/types/router/core/url/urlRule.d.ts +6 -6
- package/types/router/core/url/urlRules.d.ts +6 -6
- package/types/router/core/url/urlService.d.ts +8 -8
- package/types/router/core/view/interface.d.ts +1 -1
- package/types/router/core/view/view.d.ts +15 -15
- package/types/router/directives/viewDirective.d.ts +4 -4
- package/types/router/interface.d.ts +4 -4
- package/types/router/locationServices.d.ts +3 -3
- package/types/router/services.d.ts +1 -1
- package/types/router/stateProvider.d.ts +2 -2
- package/types/router/viewScroll.d.ts +1 -1
- package/src/router/url/url-matcher-factory.js +0 -77
- package/src/router/url/url-router.js +0 -101
|
@@ -5,7 +5,6 @@ import { map, find } from "../../src/shared/common";
|
|
|
5
5
|
|
|
6
6
|
describe("UrlMatcher", () => {
|
|
7
7
|
let router;
|
|
8
|
-
let $umf;
|
|
9
8
|
let $url;
|
|
10
9
|
let $injector;
|
|
11
10
|
let $location;
|
|
@@ -19,57 +18,54 @@ describe("UrlMatcher", () => {
|
|
|
19
18
|
"defaultModule",
|
|
20
19
|
]);
|
|
21
20
|
|
|
22
|
-
$injector.invoke(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
$location = _$location_;
|
|
28
|
-
},
|
|
29
|
-
);
|
|
21
|
+
$injector.invoke(($router, $urlService, _$location_) => {
|
|
22
|
+
router = $router;
|
|
23
|
+
$url = $urlService;
|
|
24
|
+
$location = _$location_;
|
|
25
|
+
});
|
|
30
26
|
});
|
|
31
27
|
|
|
32
28
|
describe("provider", () => {
|
|
33
29
|
it("should factory matchers with correct configuration", () => {
|
|
34
|
-
$
|
|
35
|
-
expect($
|
|
30
|
+
$url.config.caseInsensitive(false);
|
|
31
|
+
expect($url.compile("/hello").exec("/HELLO")).toBeNull();
|
|
36
32
|
|
|
37
|
-
$
|
|
38
|
-
expect($
|
|
33
|
+
$url.config.caseInsensitive(true);
|
|
34
|
+
expect($url.compile("/hello").exec("/HELLO")).toEqual({});
|
|
39
35
|
|
|
40
|
-
$
|
|
41
|
-
expect($
|
|
36
|
+
$url.config.strictMode(true);
|
|
37
|
+
expect($url.compile("/hello").exec("/hello/")).toBeNull();
|
|
42
38
|
|
|
43
|
-
$
|
|
44
|
-
expect($
|
|
39
|
+
$url.config.strictMode(false);
|
|
40
|
+
expect($url.compile("/hello").exec("/hello/")).toEqual({});
|
|
45
41
|
});
|
|
46
42
|
|
|
47
43
|
it("should correctly validate UrlMatcher interface", () => {
|
|
48
|
-
let m = $
|
|
49
|
-
expect($
|
|
44
|
+
let m = $url.compile("/");
|
|
45
|
+
expect($url.isMatcher(m)).toBe(true);
|
|
50
46
|
});
|
|
51
47
|
});
|
|
52
48
|
|
|
53
49
|
it("should match static URLs", () => {
|
|
54
|
-
expect($
|
|
50
|
+
expect($url.compile("/hello/world").exec("/hello/world")).toEqual({});
|
|
55
51
|
});
|
|
56
52
|
|
|
57
53
|
it("should match static case insensitive URLs", () => {
|
|
58
54
|
expect(
|
|
59
|
-
$
|
|
55
|
+
$url
|
|
60
56
|
.compile("/hello/world", { caseInsensitive: true })
|
|
61
57
|
.exec("/heLLo/World"),
|
|
62
58
|
).toEqual({});
|
|
63
59
|
});
|
|
64
60
|
|
|
65
61
|
it("should match against the entire path", () => {
|
|
66
|
-
const matcher = $
|
|
62
|
+
const matcher = $url.compile("/hello/world", { strict: true });
|
|
67
63
|
expect(matcher.exec("/hello/world/")).toBeNull();
|
|
68
64
|
expect(matcher.exec("/hello/world/suffix")).toBeNull();
|
|
69
65
|
});
|
|
70
66
|
|
|
71
67
|
it("should parse parameter placeholders", () => {
|
|
72
|
-
const matcher = $
|
|
68
|
+
const matcher = $url.compile(
|
|
73
69
|
"/users/:id/details/{type}/{repeat:[0-9]+}?from&to",
|
|
74
70
|
);
|
|
75
71
|
expect(matcher.parameters().map((x) => x.id)).toEqual([
|
|
@@ -82,14 +78,14 @@ describe("UrlMatcher", () => {
|
|
|
82
78
|
});
|
|
83
79
|
|
|
84
80
|
it("should encode and decode duplicate query string values as array", () => {
|
|
85
|
-
const matcher = $
|
|
81
|
+
const matcher = $url.compile("/?foo"),
|
|
86
82
|
array = { foo: ["bar", "baz"] };
|
|
87
83
|
expect(matcher.exec("/", array)).toEqual(array);
|
|
88
84
|
expect(matcher.format(array)).toBe("/?foo=bar&foo=baz");
|
|
89
85
|
});
|
|
90
86
|
|
|
91
87
|
it("should encode and decode slashes in parameter values as ~2F", () => {
|
|
92
|
-
const matcher1 = $
|
|
88
|
+
const matcher1 = $url.compile("/:foo");
|
|
93
89
|
|
|
94
90
|
expect(matcher1.format({ foo: "/" })).toBe("/~2F");
|
|
95
91
|
expect(matcher1.format({ foo: "//" })).toBe("/~2F~2F");
|
|
@@ -103,7 +99,7 @@ describe("UrlMatcher", () => {
|
|
|
103
99
|
expect(matcher1.exec("/123~2F").foo).toBe("123/");
|
|
104
100
|
|
|
105
101
|
// param :foo should match between two slashes
|
|
106
|
-
const matcher2 = $
|
|
102
|
+
const matcher2 = $url.compile("/:foo/");
|
|
107
103
|
|
|
108
104
|
expect(matcher2.exec("/")).not.toBeTruthy();
|
|
109
105
|
expect(matcher2.exec("//")).toBeTruthy();
|
|
@@ -115,7 +111,7 @@ describe("UrlMatcher", () => {
|
|
|
115
111
|
});
|
|
116
112
|
|
|
117
113
|
it("should encode and decode tildes in parameter values as ~~", () => {
|
|
118
|
-
const matcher1 = $
|
|
114
|
+
const matcher1 = $url.compile("/:foo");
|
|
119
115
|
|
|
120
116
|
expect(matcher1.format({ foo: "abc" })).toBe("/abc");
|
|
121
117
|
expect(matcher1.format({ foo: "~abc" })).toBe("/~~abc");
|
|
@@ -128,7 +124,7 @@ describe("UrlMatcher", () => {
|
|
|
128
124
|
|
|
129
125
|
describe("snake-case parameters", () => {
|
|
130
126
|
it("should match if properly formatted", () => {
|
|
131
|
-
const matcher = $
|
|
127
|
+
const matcher = $url.compile(
|
|
132
128
|
"/users/?from&to&snake-case&snake-case-triple",
|
|
133
129
|
);
|
|
134
130
|
expect(matcher.parameters().map((x) => x.id)).toEqual([
|
|
@@ -143,20 +139,20 @@ describe("UrlMatcher", () => {
|
|
|
143
139
|
let err =
|
|
144
140
|
"Invalid parameter name '-snake' in pattern '/users/?from&to&-snake'";
|
|
145
141
|
expect(() => {
|
|
146
|
-
$
|
|
142
|
+
$url.compile("/users/?from&to&-snake");
|
|
147
143
|
}).toThrowError(err);
|
|
148
144
|
|
|
149
145
|
err =
|
|
150
146
|
"Invalid parameter name 'snake-' in pattern '/users/?from&to&snake-'";
|
|
151
147
|
expect(() => {
|
|
152
|
-
$
|
|
148
|
+
$url.compile("/users/?from&to&snake-");
|
|
153
149
|
}).toThrowError(err);
|
|
154
150
|
});
|
|
155
151
|
});
|
|
156
152
|
|
|
157
153
|
describe("parameters containing periods", () => {
|
|
158
154
|
it("should match if properly formatted", () => {
|
|
159
|
-
const matcher = $
|
|
155
|
+
const matcher = $url.compile(
|
|
160
156
|
"/users/?from&to&with.periods&with.periods.also",
|
|
161
157
|
);
|
|
162
158
|
const params = matcher.parameters().map(function (p) {
|
|
@@ -176,21 +172,21 @@ describe("UrlMatcher", () => {
|
|
|
176
172
|
"Invalid parameter name '.periods' in pattern '/users/?from&to&.periods'",
|
|
177
173
|
);
|
|
178
174
|
expect(() => {
|
|
179
|
-
$
|
|
175
|
+
$url.compile("/users/?from&to&.periods");
|
|
180
176
|
}).toThrow(err);
|
|
181
177
|
|
|
182
178
|
err = new Error(
|
|
183
179
|
"Invalid parameter name 'periods.' in pattern '/users/?from&to&periods.'",
|
|
184
180
|
);
|
|
185
181
|
expect(() => {
|
|
186
|
-
$
|
|
182
|
+
$url.compile("/users/?from&to&periods.");
|
|
187
183
|
}).toThrow(err);
|
|
188
184
|
});
|
|
189
185
|
});
|
|
190
186
|
|
|
191
187
|
describe(".exec()", () => {
|
|
192
188
|
it("should capture parameter values", () => {
|
|
193
|
-
const m = $
|
|
189
|
+
const m = $url.compile(
|
|
194
190
|
"/users/:id/details/{type}/{repeat:[0-9]+}?from&to",
|
|
195
191
|
{ strict: false },
|
|
196
192
|
);
|
|
@@ -204,13 +200,13 @@ describe("UrlMatcher", () => {
|
|
|
204
200
|
});
|
|
205
201
|
|
|
206
202
|
it("should capture catch-all parameters", () => {
|
|
207
|
-
const m = $
|
|
203
|
+
const m = $url.compile("/document/*path");
|
|
208
204
|
expect(m.exec("/document/a/b/c", {})).toEqual({ path: "a/b/c" });
|
|
209
205
|
expect(m.exec("/document/", {})).toEqual({ path: "" });
|
|
210
206
|
});
|
|
211
207
|
|
|
212
208
|
it("should use the optional regexp with curly brace placeholders", () => {
|
|
213
|
-
const m = $
|
|
209
|
+
const m = $url.compile(
|
|
214
210
|
"/users/:id/details/{type}/{repeat:[0-9]+}?from&to",
|
|
215
211
|
);
|
|
216
212
|
expect(
|
|
@@ -219,26 +215,26 @@ describe("UrlMatcher", () => {
|
|
|
219
215
|
});
|
|
220
216
|
|
|
221
217
|
it("should not use optional regexp for '/'", () => {
|
|
222
|
-
const m = $
|
|
218
|
+
const m = $url.compile("/{language:(?:fr|en|de)}");
|
|
223
219
|
expect(m.exec("/", {})).toBeNull();
|
|
224
220
|
});
|
|
225
221
|
|
|
226
222
|
it("should work with empty default value", () => {
|
|
227
|
-
const m = $
|
|
223
|
+
const m = $url.compile("/foo/:str", {
|
|
228
224
|
state: { params: { str: { value: "" } } },
|
|
229
225
|
});
|
|
230
226
|
expect(m.exec("/foo/", {})).toEqual({ str: "" });
|
|
231
227
|
});
|
|
232
228
|
|
|
233
229
|
it("should work with empty default value for regex", () => {
|
|
234
|
-
const m = $
|
|
230
|
+
const m = $url.compile("/foo/{param:(?:foo|bar|)}", {
|
|
235
231
|
state: { params: { param: { value: "" } } },
|
|
236
232
|
});
|
|
237
233
|
expect(m.exec("/foo/", {})).toEqual({ param: "" });
|
|
238
234
|
});
|
|
239
235
|
|
|
240
236
|
it("should treat the URL as already decoded and does not decode it further", () => {
|
|
241
|
-
expect($
|
|
237
|
+
expect($url.compile("/users/:id").exec("/users/100%25", {})).toEqual({
|
|
242
238
|
id: "100%25",
|
|
243
239
|
});
|
|
244
240
|
});
|
|
@@ -252,7 +248,7 @@ describe("UrlMatcher", () => {
|
|
|
252
248
|
};
|
|
253
249
|
|
|
254
250
|
angular.forEach(shouldPass, function (url, route) {
|
|
255
|
-
expect($
|
|
251
|
+
expect($url.compile(route).exec(url, {})).toEqual({
|
|
256
252
|
childParam: "childParam",
|
|
257
253
|
matchedParam: "someword",
|
|
258
254
|
});
|
|
@@ -269,7 +265,7 @@ describe("UrlMatcher", () => {
|
|
|
269
265
|
|
|
270
266
|
angular.forEach(shouldThrow, function (url, route) {
|
|
271
267
|
expect(() => {
|
|
272
|
-
$
|
|
268
|
+
$url.compile(route).exec(url, {});
|
|
273
269
|
}).toThrowError("Unbalanced capture group in route '" + route + "'");
|
|
274
270
|
});
|
|
275
271
|
|
|
@@ -282,7 +278,7 @@ describe("UrlMatcher", () => {
|
|
|
282
278
|
|
|
283
279
|
angular.forEach(shouldPass, function (url, route) {
|
|
284
280
|
expect(() => {
|
|
285
|
-
$
|
|
281
|
+
$url.compile(route).exec(url, {});
|
|
286
282
|
}).not.toThrow();
|
|
287
283
|
});
|
|
288
284
|
});
|
|
@@ -290,7 +286,7 @@ describe("UrlMatcher", () => {
|
|
|
290
286
|
|
|
291
287
|
describe(".format()", () => {
|
|
292
288
|
it("should reconstitute the URL", () => {
|
|
293
|
-
const m = $
|
|
289
|
+
const m = $url.compile("/users/:id/details/{type}/{repeat:[0-9]+}?from"),
|
|
294
290
|
params = {
|
|
295
291
|
id: "123",
|
|
296
292
|
type: "default",
|
|
@@ -305,13 +301,13 @@ describe("UrlMatcher", () => {
|
|
|
305
301
|
});
|
|
306
302
|
|
|
307
303
|
it("should encode URL parameters", () => {
|
|
308
|
-
expect($
|
|
304
|
+
expect($url.compile("/users/:id").format({ id: "100%" })).toEqual(
|
|
309
305
|
"/users/100%25",
|
|
310
306
|
);
|
|
311
307
|
});
|
|
312
308
|
|
|
313
309
|
it("encodes URL parameters with hashes", () => {
|
|
314
|
-
const m = $
|
|
310
|
+
const m = $url.compile("/users/:id#:section");
|
|
315
311
|
expect(m.format({ id: "bob", section: "contact-details" })).toEqual(
|
|
316
312
|
"/users/bob#contact-details",
|
|
317
313
|
);
|
|
@@ -321,16 +317,16 @@ describe("UrlMatcher", () => {
|
|
|
321
317
|
const config = {
|
|
322
318
|
state: { params: { id: { squash: true, value: "123" } } },
|
|
323
319
|
},
|
|
324
|
-
m = $
|
|
320
|
+
m = $url.compile("/users/:id", config),
|
|
325
321
|
params = { id: "123" };
|
|
326
322
|
|
|
327
323
|
expect(m.format(params)).toEqual("/users");
|
|
328
324
|
});
|
|
329
325
|
|
|
330
326
|
it("should format query parameters from parent, child, grandchild matchers", () => {
|
|
331
|
-
const m = $
|
|
332
|
-
const m2 = m.append($
|
|
333
|
-
const m3 = m2.append($
|
|
327
|
+
const m = $url.compile("/parent?qParent");
|
|
328
|
+
const m2 = m.append($url.compile("/child?qChild"));
|
|
329
|
+
const m3 = m2.append($url.compile("/grandchild?qGrandchild"));
|
|
334
330
|
|
|
335
331
|
const params = {
|
|
336
332
|
qParent: "parent",
|
|
@@ -348,9 +344,9 @@ describe("UrlMatcher", () => {
|
|
|
348
344
|
|
|
349
345
|
describe(".append()", () => {
|
|
350
346
|
it("should append matchers", () => {
|
|
351
|
-
const matcher = $
|
|
347
|
+
const matcher = $url
|
|
352
348
|
.compile("/users/:id/details/{type}?from")
|
|
353
|
-
.append($
|
|
349
|
+
.append($url.compile("/{repeat:[0-9]+}?to"));
|
|
354
350
|
const params = matcher.parameters();
|
|
355
351
|
expect(params.map((x) => x.id)).toEqual([
|
|
356
352
|
"id",
|
|
@@ -362,37 +358,37 @@ describe("UrlMatcher", () => {
|
|
|
362
358
|
});
|
|
363
359
|
|
|
364
360
|
it("should return a new matcher", () => {
|
|
365
|
-
const base = $
|
|
366
|
-
const matcher = base.append($
|
|
361
|
+
const base = $url.compile("/users/:id/details/{type}?from");
|
|
362
|
+
const matcher = base.append($url.compile("/{repeat:[0-9]+}?to"));
|
|
367
363
|
expect(matcher).not.toBe(base);
|
|
368
364
|
});
|
|
369
365
|
|
|
370
|
-
it("should respect $
|
|
371
|
-
let m = $
|
|
372
|
-
$
|
|
373
|
-
m = m.append($
|
|
366
|
+
it("should respect $urlServiceProvider.strictMode", () => {
|
|
367
|
+
let m = $url.compile("/");
|
|
368
|
+
$url.config.strictMode(false);
|
|
369
|
+
m = m.append($url.compile("foo"));
|
|
374
370
|
expect(m.exec("/foo")).toEqual({});
|
|
375
371
|
expect(m.exec("/foo/")).toEqual({});
|
|
376
372
|
});
|
|
377
373
|
|
|
378
|
-
it("should respect $
|
|
379
|
-
let m = $
|
|
380
|
-
$
|
|
381
|
-
m = m.append($
|
|
374
|
+
it("should respect $urlServiceProvider.caseInsensitive", () => {
|
|
375
|
+
let m = $url.compile("/");
|
|
376
|
+
$url.caseInsensitive(true);
|
|
377
|
+
m = m.append($url.compile("foo"));
|
|
382
378
|
expect(m.exec("/foo")).toEqual({});
|
|
383
379
|
expect(m.exec("/FOO")).toEqual({});
|
|
384
380
|
});
|
|
385
381
|
|
|
386
|
-
it("should respect $
|
|
387
|
-
let m = $
|
|
388
|
-
$
|
|
389
|
-
m = m.append($
|
|
382
|
+
it("should respect $urlServiceProvider.caseInsensitive when validating regex params", () => {
|
|
383
|
+
let m = $url.compile("/");
|
|
384
|
+
$url.config.caseInsensitive(true);
|
|
385
|
+
m = m.append($url.compile("foo/{param:bar}"));
|
|
390
386
|
expect(m.validates({ param: "BAR" })).toEqual(true);
|
|
391
387
|
});
|
|
392
388
|
|
|
393
389
|
it("should generate/match params in the proper order", () => {
|
|
394
|
-
let m = $
|
|
395
|
-
m = m.append($
|
|
390
|
+
let m = $url.compile("/foo?queryparam");
|
|
391
|
+
m = m.append($url.compile("/bar/:pathparam"));
|
|
396
392
|
expect(m.exec("/foo/bar/pathval", { queryparam: "queryval" })).toEqual({
|
|
397
393
|
pathparam: "pathval",
|
|
398
394
|
queryparam: "queryval",
|
|
@@ -402,14 +398,14 @@ describe("UrlMatcher", () => {
|
|
|
402
398
|
|
|
403
399
|
describe("multivalue-query-parameters", () => {
|
|
404
400
|
it("should handle .is() for an array of values", () => {
|
|
405
|
-
const m = $
|
|
401
|
+
const m = $url.compile("/foo?{param1:int}"),
|
|
406
402
|
param = m.parameter("param1");
|
|
407
403
|
expect(param.type.is([1, 2, 3])).toBe(true);
|
|
408
404
|
expect(param.type.is([1, "2", 3])).toBe(false);
|
|
409
405
|
});
|
|
410
406
|
|
|
411
407
|
it("should handle .equals() for two arrays of values", () => {
|
|
412
|
-
const m = $
|
|
408
|
+
const m = $url.compile("/foo?{param1:int}&{param2:date}"),
|
|
413
409
|
param1 = m.parameter("param1"),
|
|
414
410
|
param2 = m.parameter("param2");
|
|
415
411
|
|
|
@@ -430,7 +426,7 @@ describe("UrlMatcher", () => {
|
|
|
430
426
|
});
|
|
431
427
|
|
|
432
428
|
it("should conditionally be wrapped in an array by default", () => {
|
|
433
|
-
const m = $
|
|
429
|
+
const m = $url.compile("/foo?param1");
|
|
434
430
|
|
|
435
431
|
// empty array [] is treated like "undefined"
|
|
436
432
|
expect(m.format({ param1: undefined })).toBe("/foo");
|
|
@@ -472,7 +468,7 @@ describe("UrlMatcher", () => {
|
|
|
472
468
|
});
|
|
473
469
|
|
|
474
470
|
it("should be wrapped in an array if array: true", () => {
|
|
475
|
-
const m = $
|
|
471
|
+
const m = $url.compile("/foo?param1", {
|
|
476
472
|
state: { params: { param1: { array: true } } },
|
|
477
473
|
});
|
|
478
474
|
|
|
@@ -516,7 +512,7 @@ describe("UrlMatcher", () => {
|
|
|
516
512
|
});
|
|
517
513
|
|
|
518
514
|
it("should be wrapped in an array if paramname looks like param[]", () => {
|
|
519
|
-
const m = $
|
|
515
|
+
const m = $url.compile("/foo?param1[]");
|
|
520
516
|
expect(m.exec("/foo")).toEqual({ "param1[]": undefined });
|
|
521
517
|
|
|
522
518
|
$url.url("/foo?param1[]=bar");
|
|
@@ -539,7 +535,7 @@ describe("UrlMatcher", () => {
|
|
|
539
535
|
|
|
540
536
|
// Test for issue #2222
|
|
541
537
|
it("should return default value, if query param is missing.", () => {
|
|
542
|
-
const m = $
|
|
538
|
+
const m = $url.compile("/state?param1¶m2¶m3¶m5", {
|
|
543
539
|
state: {
|
|
544
540
|
params: {
|
|
545
541
|
param1: "value1",
|
|
@@ -577,7 +573,7 @@ describe("UrlMatcher", () => {
|
|
|
577
573
|
});
|
|
578
574
|
|
|
579
575
|
it("should not be wrapped by ui-router into an array if array: false", () => {
|
|
580
|
-
const m = $
|
|
576
|
+
const m = $url.compile("/foo?param1", {
|
|
581
577
|
state: { params: { param1: { array: false } } },
|
|
582
578
|
});
|
|
583
579
|
expect(m.exec("/foo")).toEqual({ param1: undefined });
|
|
@@ -601,7 +597,7 @@ describe("UrlMatcher", () => {
|
|
|
601
597
|
|
|
602
598
|
describe("multivalue-path-parameters", () => {
|
|
603
599
|
it("should behave as a single-value by default", () => {
|
|
604
|
-
const m = $
|
|
600
|
+
const m = $url.compile("/foo/:param1");
|
|
605
601
|
|
|
606
602
|
expect(m.exec("/foo/")).toEqual({ param1: "" });
|
|
607
603
|
|
|
@@ -611,7 +607,7 @@ describe("UrlMatcher", () => {
|
|
|
611
607
|
});
|
|
612
608
|
|
|
613
609
|
it("should be split on - in url and wrapped in an array if array: true", () => {
|
|
614
|
-
const m = $
|
|
610
|
+
const m = $url.compile("/foo/:param1", {
|
|
615
611
|
state: { params: { param1: { array: true } } },
|
|
616
612
|
});
|
|
617
613
|
|
|
@@ -626,7 +622,7 @@ describe("UrlMatcher", () => {
|
|
|
626
622
|
});
|
|
627
623
|
|
|
628
624
|
it("should behave similar to multi-value query params", () => {
|
|
629
|
-
const m = $
|
|
625
|
+
const m = $url.compile("/foo/:param1[]");
|
|
630
626
|
|
|
631
627
|
// empty array [] is treated like "undefined"
|
|
632
628
|
expect(m.format({ "param1[]": undefined })).toBe("/foo/");
|
|
@@ -662,7 +658,7 @@ describe("UrlMatcher", () => {
|
|
|
662
658
|
});
|
|
663
659
|
|
|
664
660
|
it("should be split on - in url and wrapped in an array if paramname looks like param[]", () => {
|
|
665
|
-
const m = $
|
|
661
|
+
const m = $url.compile("/foo/:param1[]");
|
|
666
662
|
|
|
667
663
|
expect(m.exec("/foo/")).toEqual({ "param1[]": undefined });
|
|
668
664
|
expect(m.exec("/foo/bar")).toEqual({ "param1[]": ["bar"] });
|
|
@@ -674,7 +670,7 @@ describe("UrlMatcher", () => {
|
|
|
674
670
|
});
|
|
675
671
|
|
|
676
672
|
it("should allow path param arrays with '-' in the values", () => {
|
|
677
|
-
const m = $
|
|
673
|
+
const m = $url.compile("/foo/:param1[]");
|
|
678
674
|
|
|
679
675
|
expect(m.exec("/foo/")).toEqual({ "param1[]": undefined });
|
|
680
676
|
expect(m.exec("/foo/bar\\-")).toEqual({ "param1[]": ["bar-"] });
|
|
@@ -714,11 +710,11 @@ describe("UrlMatcher", () => {
|
|
|
714
710
|
|
|
715
711
|
// describe("urlMatcherFactoryProvider", ( ) => {
|
|
716
712
|
// describe(".type()", ( ) => {
|
|
717
|
-
// let $
|
|
713
|
+
// let $url;
|
|
718
714
|
// beforeEach(
|
|
719
|
-
// module("ng.router.util", function ($
|
|
720
|
-
// $
|
|
721
|
-
// $
|
|
715
|
+
// module("ng.router.util", function ($urlServiceProvider) {
|
|
716
|
+
// $url = $urlServiceProvider;
|
|
717
|
+
// $urlServiceProvider.type("myType", {}, ( ) => {
|
|
722
718
|
// return {
|
|
723
719
|
// decode: ( ) => {
|
|
724
720
|
// return { status: "decoded" };
|
|
@@ -732,7 +728,7 @@ describe("UrlMatcher", () => {
|
|
|
732
728
|
// it("should handle arrays properly with config-time custom type definitions", function (
|
|
733
729
|
// $stateParams,
|
|
734
730
|
// ) {
|
|
735
|
-
// const m = $
|
|
731
|
+
// const m = $url.compile("/test?{foo:myType}");
|
|
736
732
|
// expect(m.exec("/test", { foo: "1" })).toEqual({
|
|
737
733
|
// foo: { status: "decoded" },
|
|
738
734
|
// });
|
|
@@ -749,21 +745,21 @@ describe("UrlMatcher", () => {
|
|
|
749
745
|
// });
|
|
750
746
|
|
|
751
747
|
// describe("urlMatcherFactory", ( ) => {
|
|
752
|
-
// let $
|
|
748
|
+
// let $url;
|
|
753
749
|
// let $url;
|
|
754
750
|
|
|
755
751
|
// beforeEach(function ($urlMatcherFactory, $urlService) {
|
|
756
|
-
// $
|
|
752
|
+
// $url = $urlMatcherFactory;
|
|
757
753
|
// $url = $urlService;
|
|
758
754
|
// });
|
|
759
755
|
|
|
760
756
|
// it("compiles patterns", ( ) => {
|
|
761
|
-
// const matcher = $
|
|
757
|
+
// const matcher = $url.compile("/hello/world");
|
|
762
758
|
// expect(matcher instanceof UrlMatcher).toBe(true);
|
|
763
759
|
// });
|
|
764
760
|
|
|
765
761
|
// it("recognizes matchers", ( ) => {
|
|
766
|
-
// expect($
|
|
762
|
+
// expect($url.isMatcher($url.compile("/"))).toBe(true);
|
|
767
763
|
|
|
768
764
|
// const custom = {
|
|
769
765
|
// format: angular.noop,
|
|
@@ -775,49 +771,49 @@ describe("UrlMatcher", () => {
|
|
|
775
771
|
// parameter: angular.noop,
|
|
776
772
|
// _getDecodedParamValue: angular.noop,
|
|
777
773
|
// };
|
|
778
|
-
// expect($
|
|
774
|
+
// expect($url.isMatcher(custom)).toBe(true);
|
|
779
775
|
// });
|
|
780
776
|
|
|
781
777
|
// it("should handle case sensitive URL by default", ( ) => {
|
|
782
|
-
// expect($
|
|
778
|
+
// expect($url.compile("/hello/world").exec("/heLLo/WORLD")).toBeNull();
|
|
783
779
|
// });
|
|
784
780
|
|
|
785
781
|
// it("should handle case insensitive URL", ( ) => {
|
|
786
|
-
// $
|
|
787
|
-
// expect($
|
|
782
|
+
// $url.caseInsensitive(true);
|
|
783
|
+
// expect($url.compile("/hello/world").exec("/heLLo/WORLD")).toEqual({});
|
|
788
784
|
// });
|
|
789
785
|
|
|
790
786
|
// describe("typed parameters", ( ) => {
|
|
791
787
|
// it("should accept object definitions", ( ) => {
|
|
792
788
|
// const type = { encode: ( ) => {}, decode: ( ) => {} };
|
|
793
|
-
// $
|
|
794
|
-
// expect($
|
|
789
|
+
// $url.type("myType1", type);
|
|
790
|
+
// expect($url.type("myType1").encode).toBe(type.encode);
|
|
795
791
|
// });
|
|
796
792
|
|
|
797
793
|
// it("should reject duplicate definitions", ( ) => {
|
|
798
|
-
// $
|
|
794
|
+
// $url.type("myType2", { encode: ( ) => {}, decode: ( ) => {} });
|
|
799
795
|
// expect(( ) => {
|
|
800
|
-
// $
|
|
796
|
+
// $url.type("myType2", {});
|
|
801
797
|
// }).toThrowError("A type named 'myType2' has already been defined.");
|
|
802
798
|
// });
|
|
803
799
|
|
|
804
800
|
// it("should accept injected function definitions", function (
|
|
805
801
|
// $stateParams,
|
|
806
802
|
// ) {
|
|
807
|
-
// $
|
|
803
|
+
// $url.type("myType3", {}, function ($stateParams) {
|
|
808
804
|
// return {
|
|
809
805
|
// decode: ( ) => {
|
|
810
806
|
// return $stateParams;
|
|
811
807
|
// },
|
|
812
808
|
// };
|
|
813
809
|
// });
|
|
814
|
-
// expect($
|
|
810
|
+
// expect($url.type("myType3").decode()).toBe($stateParams);
|
|
815
811
|
// });
|
|
816
812
|
|
|
817
813
|
// it("should accept annotated function definitions", function (
|
|
818
814
|
// $stateParams,
|
|
819
815
|
// ) {
|
|
820
|
-
// $
|
|
816
|
+
// $url.type("myAnnotatedType", {}, [
|
|
821
817
|
// "$stateParams",
|
|
822
818
|
// function (s) {
|
|
823
819
|
// return {
|
|
@@ -827,11 +823,11 @@ describe("UrlMatcher", () => {
|
|
|
827
823
|
// };
|
|
828
824
|
// },
|
|
829
825
|
// ]);
|
|
830
|
-
// expect($
|
|
826
|
+
// expect($url.type("myAnnotatedType").decode()).toBe($stateParams);
|
|
831
827
|
// });
|
|
832
828
|
|
|
833
829
|
// it("should match built-in types", ( ) => {
|
|
834
|
-
// const m = $
|
|
830
|
+
// const m = $url.compile("/{foo:int}/{flag:bool}");
|
|
835
831
|
// expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
|
|
836
832
|
// expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
|
|
837
833
|
|
|
@@ -840,13 +836,13 @@ describe("UrlMatcher", () => {
|
|
|
840
836
|
// });
|
|
841
837
|
|
|
842
838
|
// it("should match built-in types with spaces", ( ) => {
|
|
843
|
-
// const m = $
|
|
839
|
+
// const m = $url.compile("/{foo: int}/{flag: bool}");
|
|
844
840
|
// expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
|
|
845
841
|
// expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
|
|
846
842
|
// });
|
|
847
843
|
|
|
848
844
|
// it("should match types named only in params", ( ) => {
|
|
849
|
-
// const m = $
|
|
845
|
+
// const m = $url.compile("/{foo}/{flag}", {
|
|
850
846
|
// state: {
|
|
851
847
|
// params: {
|
|
852
848
|
// foo: { type: "int" },
|
|
@@ -860,7 +856,7 @@ describe("UrlMatcher", () => {
|
|
|
860
856
|
|
|
861
857
|
// it("should throw an error if a param type is declared twice", ( ) => {
|
|
862
858
|
// expect(( ) => {
|
|
863
|
-
// $
|
|
859
|
+
// $url.compile("/{foo:int}", {
|
|
864
860
|
// state: {
|
|
865
861
|
// params: {
|
|
866
862
|
// foo: { type: "int" },
|
|
@@ -871,7 +867,7 @@ describe("UrlMatcher", () => {
|
|
|
871
867
|
// });
|
|
872
868
|
|
|
873
869
|
// it("should encode/decode dates", ( ) => {
|
|
874
|
-
// const m = $
|
|
870
|
+
// const m = $url.compile("/calendar/{date:date}"),
|
|
875
871
|
// result = m.exec("/calendar/2014-03-26");
|
|
876
872
|
// const date = new Date(2014, 2, 26);
|
|
877
873
|
|
|
@@ -881,7 +877,7 @@ describe("UrlMatcher", () => {
|
|
|
881
877
|
// });
|
|
882
878
|
|
|
883
879
|
// it("should encode/decode arbitrary objects to json", ( ) => {
|
|
884
|
-
// const m = $
|
|
880
|
+
// const m = $url.compile("/state/{param1:json}/{param2:json}");
|
|
885
881
|
|
|
886
882
|
// const params = {
|
|
887
883
|
// param1: { foo: "huh", count: 3 },
|
|
@@ -898,7 +894,7 @@ describe("UrlMatcher", () => {
|
|
|
898
894
|
// });
|
|
899
895
|
|
|
900
896
|
// it("should not match invalid typed parameter values", ( ) => {
|
|
901
|
-
// const m = $
|
|
897
|
+
// const m = $url.compile("/users/{id:int}");
|
|
902
898
|
|
|
903
899
|
// expect(m.exec("/users/1138").id).toBe(1138);
|
|
904
900
|
// expect(m.exec("/users/alpha")).toBeNull();
|
|
@@ -908,7 +904,7 @@ describe("UrlMatcher", () => {
|
|
|
908
904
|
// });
|
|
909
905
|
|
|
910
906
|
// it("should automatically handle multiple search param values", ( ) => {
|
|
911
|
-
// const m = $
|
|
907
|
+
// const m = $url.compile("/foo/{fooid:int}?{bar:int}");
|
|
912
908
|
|
|
913
909
|
// $url.url("/foo/5?bar=1");
|
|
914
910
|
// expect(m.exec($url.path(), $url.search())).toEqual({ fooid: 5, bar: 1 });
|
|
@@ -929,7 +925,7 @@ describe("UrlMatcher", () => {
|
|
|
929
925
|
// });
|
|
930
926
|
|
|
931
927
|
// it("should allow custom types to handle multiple search param values manually", ( ) => {
|
|
932
|
-
// $
|
|
928
|
+
// $url.type("custArray", {
|
|
933
929
|
// encode: function (array) {
|
|
934
930
|
// return array.join("-");
|
|
935
931
|
// },
|
|
@@ -940,7 +936,7 @@ describe("UrlMatcher", () => {
|
|
|
940
936
|
// is: Array.isArray,
|
|
941
937
|
// });
|
|
942
938
|
|
|
943
|
-
// const m = $
|
|
939
|
+
// const m = $url.compile("/foo?{bar:custArray}", {
|
|
944
940
|
// state: { params: { bar: { array: false } } },
|
|
945
941
|
// });
|
|
946
942
|
|
|
@@ -960,7 +956,7 @@ describe("UrlMatcher", () => {
|
|
|
960
956
|
|
|
961
957
|
// describe("optional parameters", ( ) => {
|
|
962
958
|
// it("should match with or without values", ( ) => {
|
|
963
|
-
// const m = $
|
|
959
|
+
// const m = $url.compile("/users/{id:int}", {
|
|
964
960
|
// state: {
|
|
965
961
|
// params: { id: { value: null, squash: true } },
|
|
966
962
|
// },
|
|
@@ -972,7 +968,7 @@ describe("UrlMatcher", () => {
|
|
|
972
968
|
// });
|
|
973
969
|
|
|
974
970
|
// it("should correctly match multiple", ( ) => {
|
|
975
|
-
// const m = $
|
|
971
|
+
// const m = $url.compile("/users/{id:int}/{state:[A-Z]+}", {
|
|
976
972
|
// state: {
|
|
977
973
|
// params: {
|
|
978
974
|
// id: { value: null, squash: true },
|
|
@@ -994,7 +990,7 @@ describe("UrlMatcher", () => {
|
|
|
994
990
|
// });
|
|
995
991
|
|
|
996
992
|
// it("should correctly format with or without values", ( ) => {
|
|
997
|
-
// const m = $
|
|
993
|
+
// const m = $url.compile("/users/{id:int}", {
|
|
998
994
|
// state: {
|
|
999
995
|
// params: { id: { value: null } },
|
|
1000
996
|
// },
|
|
@@ -1004,7 +1000,7 @@ describe("UrlMatcher", () => {
|
|
|
1004
1000
|
// });
|
|
1005
1001
|
|
|
1006
1002
|
// it("should correctly format multiple", ( ) => {
|
|
1007
|
-
// const m = $
|
|
1003
|
+
// const m = $url.compile("/users/{id:int}/{state:[A-Z]+}", {
|
|
1008
1004
|
// state: {
|
|
1009
1005
|
// params: {
|
|
1010
1006
|
// id: { value: null, squash: true },
|
|
@@ -1020,7 +1016,7 @@ describe("UrlMatcher", () => {
|
|
|
1020
1016
|
// });
|
|
1021
1017
|
|
|
1022
1018
|
// it("should match in between static segments", ( ) => {
|
|
1023
|
-
// const m = $
|
|
1019
|
+
// const m = $url.compile("/users/{user:int}/photos", {
|
|
1024
1020
|
// state: {
|
|
1025
1021
|
// params: { user: { value: 5, squash: true } },
|
|
1026
1022
|
// },
|
|
@@ -1032,7 +1028,7 @@ describe("UrlMatcher", () => {
|
|
|
1032
1028
|
// });
|
|
1033
1029
|
|
|
1034
1030
|
// it("should correctly format with an optional followed by a required parameter", ( ) => {
|
|
1035
|
-
// const m = $
|
|
1031
|
+
// const m = $url.compile("/home/:user/gallery/photos/:photo", {
|
|
1036
1032
|
// state: {
|
|
1037
1033
|
// params: {
|
|
1038
1034
|
// user: { value: null, squash: true },
|
|
@@ -1048,7 +1044,7 @@ describe("UrlMatcher", () => {
|
|
|
1048
1044
|
|
|
1049
1045
|
// describe("default values", ( ) => {
|
|
1050
1046
|
// it("should populate if not supplied in URL", ( ) => {
|
|
1051
|
-
// const m = $
|
|
1047
|
+
// const m = $url.compile("/users/{id:int}/{test}", {
|
|
1052
1048
|
// state: {
|
|
1053
1049
|
// params: {
|
|
1054
1050
|
// id: { value: 0, squash: true },
|
|
@@ -1064,7 +1060,7 @@ describe("UrlMatcher", () => {
|
|
|
1064
1060
|
// });
|
|
1065
1061
|
|
|
1066
1062
|
// it("should populate even if the regexp requires 1 or more chars", ( ) => {
|
|
1067
|
-
// const m = $
|
|
1063
|
+
// const m = $url.compile(
|
|
1068
1064
|
// "/record/{appId}/{recordId:[0-9a-fA-F]{10,24}}",
|
|
1069
1065
|
// {
|
|
1070
1066
|
// state: {
|
|
@@ -1079,7 +1075,7 @@ describe("UrlMatcher", () => {
|
|
|
1079
1075
|
// });
|
|
1080
1076
|
|
|
1081
1077
|
// it("should allow shorthand definitions", ( ) => {
|
|
1082
|
-
// const m = $
|
|
1078
|
+
// const m = $url.compile("/foo/:foo", {
|
|
1083
1079
|
// state: {
|
|
1084
1080
|
// params: { foo: "bar" },
|
|
1085
1081
|
// },
|
|
@@ -1089,7 +1085,7 @@ describe("UrlMatcher", () => {
|
|
|
1089
1085
|
|
|
1090
1086
|
// it("should populate query params", ( ) => {
|
|
1091
1087
|
// const defaults = { order: "name", limit: 25, page: 1 };
|
|
1092
|
-
// const m = $
|
|
1088
|
+
// const m = $url.compile("/foo?order&{limit:int}&{page:int}", {
|
|
1093
1089
|
// state: {
|
|
1094
1090
|
// params: defaults,
|
|
1095
1091
|
// },
|
|
@@ -1101,21 +1097,21 @@ describe("UrlMatcher", () => {
|
|
|
1101
1097
|
// function barFn() {
|
|
1102
1098
|
// return "Value from bar()";
|
|
1103
1099
|
// }
|
|
1104
|
-
// let m = $
|
|
1100
|
+
// let m = $url.compile("/foo/:bar", {
|
|
1105
1101
|
// state: {
|
|
1106
1102
|
// params: { bar: barFn },
|
|
1107
1103
|
// },
|
|
1108
1104
|
// });
|
|
1109
1105
|
// expect(m.exec("/foo/").bar).toBe("Value from bar()");
|
|
1110
1106
|
|
|
1111
|
-
// m = $
|
|
1107
|
+
// m = $url.compile("/foo/:bar", {
|
|
1112
1108
|
// state: {
|
|
1113
1109
|
// params: { bar: { value: barFn, squash: true } },
|
|
1114
1110
|
// },
|
|
1115
1111
|
// });
|
|
1116
1112
|
// expect(m.exec("/foo").bar).toBe("Value from bar()");
|
|
1117
1113
|
|
|
1118
|
-
// m = $
|
|
1114
|
+
// m = $url.compile("/foo?bar", {
|
|
1119
1115
|
// state: {
|
|
1120
1116
|
// params: { bar: barFn },
|
|
1121
1117
|
// },
|
|
@@ -1124,7 +1120,7 @@ describe("UrlMatcher", () => {
|
|
|
1124
1120
|
// });
|
|
1125
1121
|
|
|
1126
1122
|
// it("should allow injectable functions", function ($stateParams) {
|
|
1127
|
-
// const m = $
|
|
1123
|
+
// const m = $url.compile("/users/{user:json}", {
|
|
1128
1124
|
// state: {
|
|
1129
1125
|
// params: {
|
|
1130
1126
|
// user: function ($stateParams) {
|
|
@@ -1140,7 +1136,7 @@ describe("UrlMatcher", () => {
|
|
|
1140
1136
|
// });
|
|
1141
1137
|
|
|
1142
1138
|
// xit("should match when used as prefix", ( ) => {
|
|
1143
|
-
// const m = $
|
|
1139
|
+
// const m = $url.compile("/{lang:[a-z]{2}}/foo", {
|
|
1144
1140
|
// state: {
|
|
1145
1141
|
// params: { lang: "de" },
|
|
1146
1142
|
// },
|
|
@@ -1152,7 +1148,7 @@ describe("UrlMatcher", () => {
|
|
|
1152
1148
|
// describe("squash policy", ( ) => {
|
|
1153
1149
|
// const Session = { username: "loggedinuser" };
|
|
1154
1150
|
// function getMatcher(squash) {
|
|
1155
|
-
// return $
|
|
1151
|
+
// return $url.compile(
|
|
1156
1152
|
// "/user/:userid/gallery/:galleryid/photo/:photoid",
|
|
1157
1153
|
// {
|
|
1158
1154
|
// state: {
|
|
@@ -1285,18 +1281,18 @@ describe("UrlMatcher", () => {
|
|
|
1285
1281
|
|
|
1286
1282
|
// describe("strict matching", ( ) => {
|
|
1287
1283
|
// it("should match with or without trailing slash", ( ) => {
|
|
1288
|
-
// const m = $
|
|
1284
|
+
// const m = $url.compile("/users", { strict: false });
|
|
1289
1285
|
// expect(m.exec("/users")).toEqual({});
|
|
1290
1286
|
// expect(m.exec("/users/")).toEqual({});
|
|
1291
1287
|
// });
|
|
1292
1288
|
|
|
1293
1289
|
// it("should not match multiple trailing slashes", ( ) => {
|
|
1294
|
-
// const m = $
|
|
1290
|
+
// const m = $url.compile("/users", { strict: false });
|
|
1295
1291
|
// expect(m.exec("/users//")).toBeNull();
|
|
1296
1292
|
// });
|
|
1297
1293
|
|
|
1298
1294
|
// it("should match when defined with parameters", ( ) => {
|
|
1299
|
-
// const m = $
|
|
1295
|
+
// const m = $url.compile("/users/{name}", {
|
|
1300
1296
|
// strict: false,
|
|
1301
1297
|
// state: {
|
|
1302
1298
|
// params: {
|