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