@angular-wave/angular.ts 0.0.22 → 0.0.23
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 +6 -2
- package/package.json +1 -1
- package/src/filters/order-by.js +8 -8
- package/src/router/directives/viewDirective.js +3 -11
- package/src/router/stateProvider.js +8 -0
- package/src/router/templateFactory.js +13 -7
- package/src/router/transition/transition.js +5 -1
- package/src/router/url/urlRule.js +9 -1
- package/src/services/browser.js +3 -18
- package/test/router/ng-state-builder.spec.js +81 -0
- package/test/router/services.spec.js +0 -1
- package/test/router/state-directives.spec.js +867 -893
- package/test/router/template-factory.spec.js +146 -0
- package/test/router/url-matcher-factory.spec.js +1313 -0
- package/test/router/view-directive.spec.js +2013 -0
- package/test/router/view-hook.spec.js +217 -0
- package/test/router/view-scroll.spec.js +77 -0
- package/test/router/view.spec.js +117 -0
|
@@ -0,0 +1,1313 @@
|
|
|
1
|
+
import { dealoc, jqLite } from "../../src/jqLite";
|
|
2
|
+
import { Angular } from "../../src/loader";
|
|
3
|
+
import { publishExternalAPI } from "../../src/public";
|
|
4
|
+
import { map, find } from "../../src/shared/common";
|
|
5
|
+
|
|
6
|
+
describe("UrlMatcher", () => {
|
|
7
|
+
let router;
|
|
8
|
+
let $umf;
|
|
9
|
+
let $url;
|
|
10
|
+
let $injector;
|
|
11
|
+
let $location;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
dealoc(document.getElementById("dummy"));
|
|
15
|
+
window.angular = new Angular();
|
|
16
|
+
publishExternalAPI();
|
|
17
|
+
window.angular.module("defaultModule", ["ui.router"]);
|
|
18
|
+
$injector = window.angular.bootstrap(document.getElementById("dummy"), [
|
|
19
|
+
"defaultModule",
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
$injector.invoke(
|
|
23
|
+
($router, $urlMatcherFactory, $urlService, _$location_) => {
|
|
24
|
+
router = $router;
|
|
25
|
+
$umf = $urlMatcherFactory;
|
|
26
|
+
$url = $urlService;
|
|
27
|
+
$location = _$location_;
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("provider", () => {
|
|
33
|
+
it("should factory matchers with correct configuration", () => {
|
|
34
|
+
$umf.caseInsensitive(false);
|
|
35
|
+
expect($umf.compile("/hello").exec("/HELLO")).toBeNull();
|
|
36
|
+
|
|
37
|
+
$umf.caseInsensitive(true);
|
|
38
|
+
expect($umf.compile("/hello").exec("/HELLO")).toEqual({});
|
|
39
|
+
|
|
40
|
+
$umf.strictMode(true);
|
|
41
|
+
expect($umf.compile("/hello").exec("/hello/")).toBeNull();
|
|
42
|
+
|
|
43
|
+
$umf.strictMode(false);
|
|
44
|
+
expect($umf.compile("/hello").exec("/hello/")).toEqual({});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should correctly validate UrlMatcher interface", () => {
|
|
48
|
+
let m = $umf.compile("/");
|
|
49
|
+
expect($umf.isMatcher(m)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should match static URLs", () => {
|
|
54
|
+
expect($umf.compile("/hello/world").exec("/hello/world")).toEqual({});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should match static case insensitive URLs", () => {
|
|
58
|
+
expect(
|
|
59
|
+
$umf
|
|
60
|
+
.compile("/hello/world", { caseInsensitive: true })
|
|
61
|
+
.exec("/heLLo/World"),
|
|
62
|
+
).toEqual({});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should match against the entire path", () => {
|
|
66
|
+
const matcher = $umf.compile("/hello/world", { strict: true });
|
|
67
|
+
expect(matcher.exec("/hello/world/")).toBeNull();
|
|
68
|
+
expect(matcher.exec("/hello/world/suffix")).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should parse parameter placeholders", () => {
|
|
72
|
+
const matcher = $umf.compile(
|
|
73
|
+
"/users/:id/details/{type}/{repeat:[0-9]+}?from&to",
|
|
74
|
+
);
|
|
75
|
+
expect(matcher.parameters().map((x) => x.id)).toEqual([
|
|
76
|
+
"id",
|
|
77
|
+
"type",
|
|
78
|
+
"repeat",
|
|
79
|
+
"from",
|
|
80
|
+
"to",
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should encode and decode duplicate query string values as array", () => {
|
|
85
|
+
const matcher = $umf.compile("/?foo"),
|
|
86
|
+
array = { foo: ["bar", "baz"] };
|
|
87
|
+
expect(matcher.exec("/", array)).toEqual(array);
|
|
88
|
+
expect(matcher.format(array)).toBe("/?foo=bar&foo=baz");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should encode and decode slashes in parameter values as ~2F", () => {
|
|
92
|
+
const matcher1 = $umf.compile("/:foo");
|
|
93
|
+
|
|
94
|
+
expect(matcher1.format({ foo: "/" })).toBe("/~2F");
|
|
95
|
+
expect(matcher1.format({ foo: "//" })).toBe("/~2F~2F");
|
|
96
|
+
|
|
97
|
+
expect(matcher1.exec("/")).toBeTruthy();
|
|
98
|
+
expect(matcher1.exec("//")).not.toBeTruthy();
|
|
99
|
+
|
|
100
|
+
expect(matcher1.exec("/").foo).toBe("");
|
|
101
|
+
expect(matcher1.exec("/123").foo).toBe("123");
|
|
102
|
+
expect(matcher1.exec("/~2F").foo).toBe("/");
|
|
103
|
+
expect(matcher1.exec("/123~2F").foo).toBe("123/");
|
|
104
|
+
|
|
105
|
+
// param :foo should match between two slashes
|
|
106
|
+
const matcher2 = $umf.compile("/:foo/");
|
|
107
|
+
|
|
108
|
+
expect(matcher2.exec("/")).not.toBeTruthy();
|
|
109
|
+
expect(matcher2.exec("//")).toBeTruthy();
|
|
110
|
+
|
|
111
|
+
expect(matcher2.exec("//").foo).toBe("");
|
|
112
|
+
expect(matcher2.exec("/123/").foo).toBe("123");
|
|
113
|
+
expect(matcher2.exec("/~2F/").foo).toBe("/");
|
|
114
|
+
expect(matcher2.exec("/123~2F/").foo).toBe("123/");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should encode and decode tildes in parameter values as ~~", () => {
|
|
118
|
+
const matcher1 = $umf.compile("/:foo");
|
|
119
|
+
|
|
120
|
+
expect(matcher1.format({ foo: "abc" })).toBe("/abc");
|
|
121
|
+
expect(matcher1.format({ foo: "~abc" })).toBe("/~~abc");
|
|
122
|
+
expect(matcher1.format({ foo: "~2F" })).toBe("/~~2F");
|
|
123
|
+
|
|
124
|
+
expect(matcher1.exec("/abc").foo).toBe("abc");
|
|
125
|
+
expect(matcher1.exec("/~~abc").foo).toBe("~abc");
|
|
126
|
+
expect(matcher1.exec("/~~2F").foo).toBe("~2F");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("snake-case parameters", () => {
|
|
130
|
+
it("should match if properly formatted", () => {
|
|
131
|
+
const matcher = $umf.compile(
|
|
132
|
+
"/users/?from&to&snake-case&snake-case-triple",
|
|
133
|
+
);
|
|
134
|
+
expect(matcher.parameters().map((x) => x.id)).toEqual([
|
|
135
|
+
"from",
|
|
136
|
+
"to",
|
|
137
|
+
"snake-case",
|
|
138
|
+
"snake-case-triple",
|
|
139
|
+
]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should not match if invalid", () => {
|
|
143
|
+
let err =
|
|
144
|
+
"Invalid parameter name '-snake' in pattern '/users/?from&to&-snake'";
|
|
145
|
+
expect(() => {
|
|
146
|
+
$umf.compile("/users/?from&to&-snake");
|
|
147
|
+
}).toThrowError(err);
|
|
148
|
+
|
|
149
|
+
err =
|
|
150
|
+
"Invalid parameter name 'snake-' in pattern '/users/?from&to&snake-'";
|
|
151
|
+
expect(() => {
|
|
152
|
+
$umf.compile("/users/?from&to&snake-");
|
|
153
|
+
}).toThrowError(err);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("parameters containing periods", () => {
|
|
158
|
+
it("should match if properly formatted", () => {
|
|
159
|
+
const matcher = $umf.compile(
|
|
160
|
+
"/users/?from&to&with.periods&with.periods.also",
|
|
161
|
+
);
|
|
162
|
+
const params = matcher.parameters().map(function (p) {
|
|
163
|
+
return p.id;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
expect(params.sort()).toEqual([
|
|
167
|
+
"from",
|
|
168
|
+
"to",
|
|
169
|
+
"with.periods",
|
|
170
|
+
"with.periods.also",
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should not match if invalid", () => {
|
|
175
|
+
let err = new Error(
|
|
176
|
+
"Invalid parameter name '.periods' in pattern '/users/?from&to&.periods'",
|
|
177
|
+
);
|
|
178
|
+
expect(() => {
|
|
179
|
+
$umf.compile("/users/?from&to&.periods");
|
|
180
|
+
}).toThrow(err);
|
|
181
|
+
|
|
182
|
+
err = new Error(
|
|
183
|
+
"Invalid parameter name 'periods.' in pattern '/users/?from&to&periods.'",
|
|
184
|
+
);
|
|
185
|
+
expect(() => {
|
|
186
|
+
$umf.compile("/users/?from&to&periods.");
|
|
187
|
+
}).toThrow(err);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe(".exec()", () => {
|
|
192
|
+
it("should capture parameter values", () => {
|
|
193
|
+
const m = $umf.compile(
|
|
194
|
+
"/users/:id/details/{type}/{repeat:[0-9]+}?from&to",
|
|
195
|
+
{ strict: false },
|
|
196
|
+
);
|
|
197
|
+
expect(m.exec("/users/123/details//0", {})).toEqual({
|
|
198
|
+
id: "123",
|
|
199
|
+
type: "",
|
|
200
|
+
repeat: "0",
|
|
201
|
+
to: undefined,
|
|
202
|
+
from: undefined,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("should capture catch-all parameters", () => {
|
|
207
|
+
const m = $umf.compile("/document/*path");
|
|
208
|
+
expect(m.exec("/document/a/b/c", {})).toEqual({ path: "a/b/c" });
|
|
209
|
+
expect(m.exec("/document/", {})).toEqual({ path: "" });
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("should use the optional regexp with curly brace placeholders", () => {
|
|
213
|
+
const m = $umf.compile(
|
|
214
|
+
"/users/:id/details/{type}/{repeat:[0-9]+}?from&to",
|
|
215
|
+
);
|
|
216
|
+
expect(
|
|
217
|
+
m.exec("/users/123/details/what/thisShouldBeDigits", {}),
|
|
218
|
+
).toBeNull();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should not use optional regexp for '/'", () => {
|
|
222
|
+
const m = $umf.compile("/{language:(?:fr|en|de)}");
|
|
223
|
+
expect(m.exec("/", {})).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("should work with empty default value", () => {
|
|
227
|
+
const m = $umf.compile("/foo/:str", {
|
|
228
|
+
state: { params: { str: { value: "" } } },
|
|
229
|
+
});
|
|
230
|
+
expect(m.exec("/foo/", {})).toEqual({ str: "" });
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("should work with empty default value for regex", () => {
|
|
234
|
+
const m = $umf.compile("/foo/{param:(?:foo|bar|)}", {
|
|
235
|
+
state: { params: { param: { value: "" } } },
|
|
236
|
+
});
|
|
237
|
+
expect(m.exec("/foo/", {})).toEqual({ param: "" });
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("should treat the URL as already decoded and does not decode it further", () => {
|
|
241
|
+
expect($umf.compile("/users/:id").exec("/users/100%25", {})).toEqual({
|
|
242
|
+
id: "100%25",
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
xit("should allow embedded capture groups", () => {
|
|
247
|
+
const shouldPass = {
|
|
248
|
+
"/url/{matchedParam:([a-z]+)}/child/{childParam}":
|
|
249
|
+
"/url/someword/child/childParam",
|
|
250
|
+
"/url/{matchedParam:([a-z]+)}/child/{childParam}?foo":
|
|
251
|
+
"/url/someword/child/childParam",
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
angular.forEach(shouldPass, function (url, route) {
|
|
255
|
+
expect($umf.compile(route).exec(url, {})).toEqual({
|
|
256
|
+
childParam: "childParam",
|
|
257
|
+
matchedParam: "someword",
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("should throw on unbalanced capture list", () => {
|
|
263
|
+
const shouldThrow = {
|
|
264
|
+
"/url/{matchedParam:([a-z]+)}/child/{childParam}":
|
|
265
|
+
"/url/someword/child/childParam",
|
|
266
|
+
"/url/{matchedParam:([a-z]+)}/child/{childParam}?foo":
|
|
267
|
+
"/url/someword/child/childParam",
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
angular.forEach(shouldThrow, function (url, route) {
|
|
271
|
+
expect(() => {
|
|
272
|
+
$umf.compile(route).exec(url, {});
|
|
273
|
+
}).toThrowError("Unbalanced capture group in route '" + route + "'");
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const shouldPass = {
|
|
277
|
+
"/url/{matchedParam:[a-z]+}/child/{childParam}":
|
|
278
|
+
"/url/someword/child/childParam",
|
|
279
|
+
"/url/{matchedParam:[a-z]+}/child/{childParam}?foo":
|
|
280
|
+
"/url/someword/child/childParam",
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
angular.forEach(shouldPass, function (url, route) {
|
|
284
|
+
expect(() => {
|
|
285
|
+
$umf.compile(route).exec(url, {});
|
|
286
|
+
}).not.toThrow();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe(".format()", () => {
|
|
292
|
+
it("should reconstitute the URL", () => {
|
|
293
|
+
const m = $umf.compile("/users/:id/details/{type}/{repeat:[0-9]+}?from"),
|
|
294
|
+
params = {
|
|
295
|
+
id: "123",
|
|
296
|
+
type: "default",
|
|
297
|
+
repeat: 444,
|
|
298
|
+
ignored: "value",
|
|
299
|
+
from: "1970",
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
expect(m.format(params)).toEqual(
|
|
303
|
+
"/users/123/details/default/444?from=1970",
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("should encode URL parameters", () => {
|
|
308
|
+
expect($umf.compile("/users/:id").format({ id: "100%" })).toEqual(
|
|
309
|
+
"/users/100%25",
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("encodes URL parameters with hashes", () => {
|
|
314
|
+
const m = $umf.compile("/users/:id#:section");
|
|
315
|
+
expect(m.format({ id: "bob", section: "contact-details" })).toEqual(
|
|
316
|
+
"/users/bob#contact-details",
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("should trim trailing slashes when the terminal value is optional", () => {
|
|
321
|
+
const config = {
|
|
322
|
+
state: { params: { id: { squash: true, value: "123" } } },
|
|
323
|
+
},
|
|
324
|
+
m = $umf.compile("/users/:id", config),
|
|
325
|
+
params = { id: "123" };
|
|
326
|
+
|
|
327
|
+
expect(m.format(params)).toEqual("/users");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("should format query parameters from parent, child, grandchild matchers", () => {
|
|
331
|
+
const m = $umf.compile("/parent?qParent");
|
|
332
|
+
const m2 = m.append($umf.compile("/child?qChild"));
|
|
333
|
+
const m3 = m2.append($umf.compile("/grandchild?qGrandchild"));
|
|
334
|
+
|
|
335
|
+
const params = {
|
|
336
|
+
qParent: "parent",
|
|
337
|
+
qChild: "child",
|
|
338
|
+
qGrandchild: "grandchild",
|
|
339
|
+
};
|
|
340
|
+
const url =
|
|
341
|
+
"/parent/child/grandchild?qParent=parent&qChild=child&qGrandchild=grandchild";
|
|
342
|
+
|
|
343
|
+
const formatted = m3.format(params);
|
|
344
|
+
expect(formatted).toBe(url);
|
|
345
|
+
expect(m3.exec(url.split("?")[0], params)).toEqual(params);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe(".append()", () => {
|
|
350
|
+
it("should append matchers", () => {
|
|
351
|
+
const matcher = $umf
|
|
352
|
+
.compile("/users/:id/details/{type}?from")
|
|
353
|
+
.append($umf.compile("/{repeat:[0-9]+}?to"));
|
|
354
|
+
const params = matcher.parameters();
|
|
355
|
+
expect(params.map((x) => x.id)).toEqual([
|
|
356
|
+
"id",
|
|
357
|
+
"type",
|
|
358
|
+
"from",
|
|
359
|
+
"repeat",
|
|
360
|
+
"to",
|
|
361
|
+
]);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("should return a new matcher", () => {
|
|
365
|
+
const base = $umf.compile("/users/:id/details/{type}?from");
|
|
366
|
+
const matcher = base.append($umf.compile("/{repeat:[0-9]+}?to"));
|
|
367
|
+
expect(matcher).not.toBe(base);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("should respect $urlMatcherFactoryProvider.strictMode", () => {
|
|
371
|
+
let m = $umf.compile("/");
|
|
372
|
+
$umf.strictMode(false);
|
|
373
|
+
m = m.append($umf.compile("foo"));
|
|
374
|
+
expect(m.exec("/foo")).toEqual({});
|
|
375
|
+
expect(m.exec("/foo/")).toEqual({});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("should respect $urlMatcherFactoryProvider.caseInsensitive", () => {
|
|
379
|
+
let m = $umf.compile("/");
|
|
380
|
+
$umf.caseInsensitive(true);
|
|
381
|
+
m = m.append($umf.compile("foo"));
|
|
382
|
+
expect(m.exec("/foo")).toEqual({});
|
|
383
|
+
expect(m.exec("/FOO")).toEqual({});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("should respect $urlMatcherFactoryProvider.caseInsensitive when validating regex params", () => {
|
|
387
|
+
let m = $umf.compile("/");
|
|
388
|
+
$umf.caseInsensitive(true);
|
|
389
|
+
m = m.append($umf.compile("foo/{param:bar}"));
|
|
390
|
+
expect(m.validates({ param: "BAR" })).toEqual(true);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("should generate/match params in the proper order", () => {
|
|
394
|
+
let m = $umf.compile("/foo?queryparam");
|
|
395
|
+
m = m.append($umf.compile("/bar/:pathparam"));
|
|
396
|
+
expect(m.exec("/foo/bar/pathval", { queryparam: "queryval" })).toEqual({
|
|
397
|
+
pathparam: "pathval",
|
|
398
|
+
queryparam: "queryval",
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
describe("multivalue-query-parameters", () => {
|
|
404
|
+
it("should handle .is() for an array of values", () => {
|
|
405
|
+
const m = $umf.compile("/foo?{param1:int}"),
|
|
406
|
+
param = m.parameter("param1");
|
|
407
|
+
expect(param.type.is([1, 2, 3])).toBe(true);
|
|
408
|
+
expect(param.type.is([1, "2", 3])).toBe(false);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("should handle .equals() for two arrays of values", () => {
|
|
412
|
+
const m = $umf.compile("/foo?{param1:int}&{param2:date}"),
|
|
413
|
+
param1 = m.parameter("param1"),
|
|
414
|
+
param2 = m.parameter("param2");
|
|
415
|
+
|
|
416
|
+
expect(param1.type.equals([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
417
|
+
expect(param1.type.equals([1, 2, 3], [1, 2])).toBe(false);
|
|
418
|
+
expect(
|
|
419
|
+
param2.type.equals(
|
|
420
|
+
[new Date(2014, 11, 15), new Date(2014, 10, 15)],
|
|
421
|
+
[new Date(2014, 11, 15), new Date(2014, 10, 15)],
|
|
422
|
+
),
|
|
423
|
+
).toBe(true);
|
|
424
|
+
expect(
|
|
425
|
+
param2.type.equals(
|
|
426
|
+
[new Date(2014, 11, 15), new Date(2014, 9, 15)],
|
|
427
|
+
[new Date(2014, 11, 15), new Date(2014, 10, 15)],
|
|
428
|
+
),
|
|
429
|
+
).toBe(false);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("should conditionally be wrapped in an array by default", () => {
|
|
433
|
+
const m = $umf.compile("/foo?param1");
|
|
434
|
+
|
|
435
|
+
// empty array [] is treated like "undefined"
|
|
436
|
+
expect(m.format({ param1: undefined })).toBe("/foo");
|
|
437
|
+
expect(m.format({ param1: [] })).toBe("/foo");
|
|
438
|
+
expect(m.format({ param1: "" })).toBe("/foo");
|
|
439
|
+
expect(m.format({ param1: "1" })).toBe("/foo?param1=1");
|
|
440
|
+
expect(m.format({ param1: ["1"] })).toBe("/foo?param1=1");
|
|
441
|
+
expect(m.format({ param1: ["1", "2"] })).toBe("/foo?param1=1¶m1=2");
|
|
442
|
+
|
|
443
|
+
expect(m.exec("/foo")).toEqual({ param1: undefined });
|
|
444
|
+
expect(m.exec("/foo", {})).toEqual({ param1: undefined });
|
|
445
|
+
expect(m.exec("/foo", { param1: "" })).toEqual({ param1: undefined });
|
|
446
|
+
expect(m.exec("/foo", { param1: "1" })).toEqual({ param1: "1" }); // auto unwrap single values
|
|
447
|
+
expect(m.exec("/foo", { param1: ["1", "2"] })).toEqual({
|
|
448
|
+
param1: ["1", "2"],
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
$url.url("/foo");
|
|
452
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: undefined });
|
|
453
|
+
$url.url("/foo?param1=bar");
|
|
454
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: "bar" }); // auto unwrap
|
|
455
|
+
$url.url("/foo?param1=");
|
|
456
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: undefined });
|
|
457
|
+
$url.url("/foo?param1=bar¶m1=baz");
|
|
458
|
+
if (Array.isArray($url.search()))
|
|
459
|
+
// conditional for angular 1.0.8
|
|
460
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
461
|
+
param1: ["bar", "baz"],
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
expect(m.format({})).toBe("/foo");
|
|
465
|
+
expect(m.format({ param1: undefined })).toBe("/foo");
|
|
466
|
+
expect(m.format({ param1: "" })).toBe("/foo");
|
|
467
|
+
expect(m.format({ param1: "bar" })).toBe("/foo?param1=bar");
|
|
468
|
+
expect(m.format({ param1: ["bar"] })).toBe("/foo?param1=bar");
|
|
469
|
+
expect(m.format({ param1: ["bar", "baz"] })).toBe(
|
|
470
|
+
"/foo?param1=bar¶m1=baz",
|
|
471
|
+
);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it("should be wrapped in an array if array: true", () => {
|
|
475
|
+
const m = $umf.compile("/foo?param1", {
|
|
476
|
+
state: { params: { param1: { array: true } } },
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// empty array [] is treated like "undefined"
|
|
480
|
+
expect(m.format({ param1: undefined })).toBe("/foo");
|
|
481
|
+
expect(m.format({ param1: [] })).toBe("/foo");
|
|
482
|
+
expect(m.format({ param1: "" })).toBe("/foo");
|
|
483
|
+
expect(m.format({ param1: "1" })).toBe("/foo?param1=1");
|
|
484
|
+
expect(m.format({ param1: ["1"] })).toBe("/foo?param1=1");
|
|
485
|
+
expect(m.format({ param1: ["1", "2"] })).toBe("/foo?param1=1¶m1=2");
|
|
486
|
+
|
|
487
|
+
expect(m.exec("/foo")).toEqual({ param1: undefined });
|
|
488
|
+
expect(m.exec("/foo", {})).toEqual({ param1: undefined });
|
|
489
|
+
expect(m.exec("/foo", { param1: "" })).toEqual({ param1: undefined });
|
|
490
|
+
expect(m.exec("/foo", { param1: "1" })).toEqual({ param1: ["1"] });
|
|
491
|
+
expect(m.exec("/foo", { param1: ["1", "2"] })).toEqual({
|
|
492
|
+
param1: ["1", "2"],
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
$url.url("/foo");
|
|
496
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: undefined });
|
|
497
|
+
$url.url("/foo?param1=");
|
|
498
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: undefined });
|
|
499
|
+
$url.url("/foo?param1=bar");
|
|
500
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: ["bar"] });
|
|
501
|
+
$url.url("/foo?param1=bar¶m1=baz");
|
|
502
|
+
if (Array.isArray($url.search()))
|
|
503
|
+
// conditional for angular 1.0.8
|
|
504
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
505
|
+
param1: ["bar", "baz"],
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
expect(m.format({})).toBe("/foo");
|
|
509
|
+
expect(m.format({ param1: undefined })).toBe("/foo");
|
|
510
|
+
expect(m.format({ param1: "" })).toBe("/foo");
|
|
511
|
+
expect(m.format({ param1: "bar" })).toBe("/foo?param1=bar");
|
|
512
|
+
expect(m.format({ param1: ["bar"] })).toBe("/foo?param1=bar");
|
|
513
|
+
expect(m.format({ param1: ["bar", "baz"] })).toBe(
|
|
514
|
+
"/foo?param1=bar¶m1=baz",
|
|
515
|
+
);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it("should be wrapped in an array if paramname looks like param[]", () => {
|
|
519
|
+
const m = $umf.compile("/foo?param1[]");
|
|
520
|
+
expect(m.exec("/foo")).toEqual({ "param1[]": undefined });
|
|
521
|
+
|
|
522
|
+
$url.url("/foo?param1[]=bar");
|
|
523
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
524
|
+
"param1[]": ["bar"],
|
|
525
|
+
});
|
|
526
|
+
expect(m.format({ "param1[]": "bar" })).toBe("/foo?param1[]=bar");
|
|
527
|
+
expect(m.format({ "param1[]": ["bar"] })).toBe("/foo?param1[]=bar");
|
|
528
|
+
|
|
529
|
+
$url.url("/foo?param1[]=bar¶m1[]=baz");
|
|
530
|
+
if (Array.isArray($url.search()))
|
|
531
|
+
// conditional for angular 1.0.8
|
|
532
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
533
|
+
"param1[]": ["bar", "baz"],
|
|
534
|
+
});
|
|
535
|
+
expect(m.format({ "param1[]": ["bar", "baz"] })).toBe(
|
|
536
|
+
"/foo?param1[]=bar¶m1[]=baz",
|
|
537
|
+
);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
// Test for issue #2222
|
|
541
|
+
it("should return default value, if query param is missing.", () => {
|
|
542
|
+
const m = $umf.compile("/state?param1¶m2¶m3¶m5", {
|
|
543
|
+
state: {
|
|
544
|
+
params: {
|
|
545
|
+
param1: "value1",
|
|
546
|
+
param2: { array: true, value: ["value2"] },
|
|
547
|
+
param3: { array: true, value: [] },
|
|
548
|
+
param5: {
|
|
549
|
+
array: true,
|
|
550
|
+
value: () => {
|
|
551
|
+
return [];
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
const expected = {
|
|
559
|
+
param1: "value1",
|
|
560
|
+
param2: ["value2"],
|
|
561
|
+
param3: [],
|
|
562
|
+
param5: [],
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// Parse url to get Param.value()
|
|
566
|
+
const parsed = m.exec("/state");
|
|
567
|
+
expect(parsed).toEqual(expected);
|
|
568
|
+
|
|
569
|
+
// Pass again through Param.value() for normalization (like transitionTo)
|
|
570
|
+
const paramDefs = m.parameters();
|
|
571
|
+
const values = map(parsed, function (val, key) {
|
|
572
|
+
return find(paramDefs, function (def) {
|
|
573
|
+
return def.id === key;
|
|
574
|
+
}).value(val);
|
|
575
|
+
});
|
|
576
|
+
expect(values).toEqual(expected);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("should not be wrapped by ui-router into an array if array: false", () => {
|
|
580
|
+
const m = $umf.compile("/foo?param1", {
|
|
581
|
+
state: { params: { param1: { array: false } } },
|
|
582
|
+
});
|
|
583
|
+
expect(m.exec("/foo")).toEqual({ param1: undefined });
|
|
584
|
+
|
|
585
|
+
$url.url("/foo?param1=bar");
|
|
586
|
+
expect(m.exec($url.path(), $url.search())).toEqual({ param1: "bar" });
|
|
587
|
+
expect(m.format({ param1: "bar" })).toBe("/foo?param1=bar");
|
|
588
|
+
expect(m.format({ param1: ["bar"] })).toBe("/foo?param1=bar");
|
|
589
|
+
|
|
590
|
+
$url.url("/foo?param1=bar¶m1=baz");
|
|
591
|
+
if (Array.isArray($url.search()))
|
|
592
|
+
// conditional for angular 1.0.8
|
|
593
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
594
|
+
param1: "bar,baz",
|
|
595
|
+
}); // coerced to string
|
|
596
|
+
expect(m.format({ param1: ["bar", "baz"] })).toBe(
|
|
597
|
+
"/foo?param1=bar%2Cbaz",
|
|
598
|
+
); // coerced to string
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
describe("multivalue-path-parameters", () => {
|
|
603
|
+
it("should behave as a single-value by default", () => {
|
|
604
|
+
const m = $umf.compile("/foo/:param1");
|
|
605
|
+
|
|
606
|
+
expect(m.exec("/foo/")).toEqual({ param1: "" });
|
|
607
|
+
|
|
608
|
+
expect(m.exec("/foo/bar")).toEqual({ param1: "bar" });
|
|
609
|
+
expect(m.format({ param1: "bar" })).toBe("/foo/bar");
|
|
610
|
+
expect(m.format({ param1: ["bar", "baz"] })).toBe("/foo/bar%2Cbaz"); // coerced to string
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("should be split on - in url and wrapped in an array if array: true", () => {
|
|
614
|
+
const m = $umf.compile("/foo/:param1", {
|
|
615
|
+
state: { params: { param1: { array: true } } },
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
expect(m.exec("/foo/")).toEqual({ param1: undefined });
|
|
619
|
+
expect(m.exec("/foo/bar")).toEqual({ param1: ["bar"] });
|
|
620
|
+
$url.url("/foo/bar-baz");
|
|
621
|
+
expect(m.exec($location.url())).toEqual({ param1: ["bar", "baz"] });
|
|
622
|
+
|
|
623
|
+
expect(m.format({ param1: [] })).toEqual("/foo/");
|
|
624
|
+
expect(m.format({ param1: ["bar"] })).toEqual("/foo/bar");
|
|
625
|
+
expect(m.format({ param1: ["bar", "baz"] })).toEqual("/foo/bar-baz");
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
it("should behave similar to multi-value query params", () => {
|
|
629
|
+
const m = $umf.compile("/foo/:param1[]");
|
|
630
|
+
|
|
631
|
+
// empty array [] is treated like "undefined"
|
|
632
|
+
expect(m.format({ "param1[]": undefined })).toBe("/foo/");
|
|
633
|
+
expect(m.format({ "param1[]": [] })).toBe("/foo/");
|
|
634
|
+
expect(m.format({ "param1[]": "" })).toBe("/foo/");
|
|
635
|
+
expect(m.format({ "param1[]": "1" })).toBe("/foo/1");
|
|
636
|
+
expect(m.format({ "param1[]": ["1"] })).toBe("/foo/1");
|
|
637
|
+
expect(m.format({ "param1[]": ["1", "2"] })).toBe("/foo/1-2");
|
|
638
|
+
|
|
639
|
+
expect(m.exec("/foo/")).toEqual({ "param1[]": undefined });
|
|
640
|
+
expect(m.exec("/foo/1")).toEqual({ "param1[]": ["1"] });
|
|
641
|
+
expect(m.exec("/foo/1-2")).toEqual({ "param1[]": ["1", "2"] });
|
|
642
|
+
|
|
643
|
+
$url.url("/foo/");
|
|
644
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
645
|
+
"param1[]": undefined,
|
|
646
|
+
});
|
|
647
|
+
$url.url("/foo/bar");
|
|
648
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
649
|
+
"param1[]": ["bar"],
|
|
650
|
+
});
|
|
651
|
+
$url.url("/foo/bar-baz");
|
|
652
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
653
|
+
"param1[]": ["bar", "baz"],
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
expect(m.format({})).toBe("/foo/");
|
|
657
|
+
expect(m.format({ "param1[]": undefined })).toBe("/foo/");
|
|
658
|
+
expect(m.format({ "param1[]": "" })).toBe("/foo/");
|
|
659
|
+
expect(m.format({ "param1[]": "bar" })).toBe("/foo/bar");
|
|
660
|
+
expect(m.format({ "param1[]": ["bar"] })).toBe("/foo/bar");
|
|
661
|
+
expect(m.format({ "param1[]": ["bar", "baz"] })).toBe("/foo/bar-baz");
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it("should be split on - in url and wrapped in an array if paramname looks like param[]", () => {
|
|
665
|
+
const m = $umf.compile("/foo/:param1[]");
|
|
666
|
+
|
|
667
|
+
expect(m.exec("/foo/")).toEqual({ "param1[]": undefined });
|
|
668
|
+
expect(m.exec("/foo/bar")).toEqual({ "param1[]": ["bar"] });
|
|
669
|
+
expect(m.exec("/foo/bar-baz")).toEqual({ "param1[]": ["bar", "baz"] });
|
|
670
|
+
|
|
671
|
+
expect(m.format({ "param1[]": [] })).toEqual("/foo/");
|
|
672
|
+
expect(m.format({ "param1[]": ["bar"] })).toEqual("/foo/bar");
|
|
673
|
+
expect(m.format({ "param1[]": ["bar", "baz"] })).toEqual("/foo/bar-baz");
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
it("should allow path param arrays with '-' in the values", () => {
|
|
677
|
+
const m = $umf.compile("/foo/:param1[]");
|
|
678
|
+
|
|
679
|
+
expect(m.exec("/foo/")).toEqual({ "param1[]": undefined });
|
|
680
|
+
expect(m.exec("/foo/bar\\-")).toEqual({ "param1[]": ["bar-"] });
|
|
681
|
+
expect(m.exec("/foo/bar\\--\\-baz")).toEqual({
|
|
682
|
+
"param1[]": ["bar-", "-baz"],
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
expect(m.format({ "param1[]": [] })).toEqual("/foo/");
|
|
686
|
+
expect(m.format({ "param1[]": ["bar-"] })).toEqual("/foo/bar%5C%2D");
|
|
687
|
+
expect(m.format({ "param1[]": ["bar-", "-baz"] })).toEqual(
|
|
688
|
+
"/foo/bar%5C%2D-%5C%2Dbaz",
|
|
689
|
+
);
|
|
690
|
+
expect(
|
|
691
|
+
m.format({ "param1[]": ["bar-bar-bar-", "-baz-baz-baz"] }),
|
|
692
|
+
).toEqual("/foo/bar%5C%2Dbar%5C%2Dbar%5C%2D-%5C%2Dbaz%5C%2Dbaz%5C%2Dbaz");
|
|
693
|
+
|
|
694
|
+
// check that we handle $location.url decodes correctly
|
|
695
|
+
$url.url(m.format({ "param1[]": ["bar-", "-baz"] }));
|
|
696
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
697
|
+
"param1[]": ["bar-", "-baz"],
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
// check that we handle $location.url decodes correctly for multiple hyphens
|
|
701
|
+
$url.url(m.format({ "param1[]": ["bar-bar-bar-", "-baz-baz-baz"] }));
|
|
702
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
703
|
+
"param1[]": ["bar-bar-bar-", "-baz-baz-baz"],
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
// check that pre-encoded values are passed correctly
|
|
707
|
+
$url.url(m.format({ "param1[]": ["%2C%20%5C%2C", "-baz"] }));
|
|
708
|
+
expect(m.exec($url.path(), $url.search())).toEqual({
|
|
709
|
+
"param1[]": ["%2C%20%5C%2C", "-baz"],
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
// describe("urlMatcherFactoryProvider", ( ) => {
|
|
716
|
+
// describe(".type()", ( ) => {
|
|
717
|
+
// let $umf;
|
|
718
|
+
// beforeEach(
|
|
719
|
+
// module("ui.router.util", function ($urlMatcherFactoryProvider) {
|
|
720
|
+
// $umf = $urlMatcherFactoryProvider;
|
|
721
|
+
// $urlMatcherFactoryProvider.type("myType", {}, ( ) => {
|
|
722
|
+
// return {
|
|
723
|
+
// decode: ( ) => {
|
|
724
|
+
// return { status: "decoded" };
|
|
725
|
+
// },
|
|
726
|
+
// is: angular.isObject,
|
|
727
|
+
// };
|
|
728
|
+
// });
|
|
729
|
+
// }),
|
|
730
|
+
// );
|
|
731
|
+
|
|
732
|
+
// it("should handle arrays properly with config-time custom type definitions", function (
|
|
733
|
+
// $stateParams,
|
|
734
|
+
// ) {
|
|
735
|
+
// const m = $umf.compile("/test?{foo:myType}");
|
|
736
|
+
// expect(m.exec("/test", { foo: "1" })).toEqual({
|
|
737
|
+
// foo: { status: "decoded" },
|
|
738
|
+
// });
|
|
739
|
+
// expect(m.exec("/test", { foo: ["1", "2"] })).toEqual({
|
|
740
|
+
// foo: [{ status: "decoded" }, { status: "decoded" }],
|
|
741
|
+
// });
|
|
742
|
+
// });
|
|
743
|
+
// });
|
|
744
|
+
|
|
745
|
+
// // TODO: Fix object pollution between tests for urlMatcherConfig
|
|
746
|
+
// afterEach(function ($urlMatcherFactory) {
|
|
747
|
+
// $urlMatcherFactory.caseInsensitive(false);
|
|
748
|
+
// });
|
|
749
|
+
// });
|
|
750
|
+
|
|
751
|
+
// describe("urlMatcherFactory", ( ) => {
|
|
752
|
+
// let $umf;
|
|
753
|
+
// let $url;
|
|
754
|
+
|
|
755
|
+
// beforeEach(function ($urlMatcherFactory, $urlService) {
|
|
756
|
+
// $umf = $urlMatcherFactory;
|
|
757
|
+
// $url = $urlService;
|
|
758
|
+
// });
|
|
759
|
+
|
|
760
|
+
// it("compiles patterns", ( ) => {
|
|
761
|
+
// const matcher = $umf.compile("/hello/world");
|
|
762
|
+
// expect(matcher instanceof UrlMatcher).toBe(true);
|
|
763
|
+
// });
|
|
764
|
+
|
|
765
|
+
// it("recognizes matchers", ( ) => {
|
|
766
|
+
// expect($umf.isMatcher($umf.compile("/"))).toBe(true);
|
|
767
|
+
|
|
768
|
+
// const custom = {
|
|
769
|
+
// format: angular.noop,
|
|
770
|
+
// exec: angular.noop,
|
|
771
|
+
// append: angular.noop,
|
|
772
|
+
// isRoot: angular.noop,
|
|
773
|
+
// validates: angular.noop,
|
|
774
|
+
// parameters: angular.noop,
|
|
775
|
+
// parameter: angular.noop,
|
|
776
|
+
// _getDecodedParamValue: angular.noop,
|
|
777
|
+
// };
|
|
778
|
+
// expect($umf.isMatcher(custom)).toBe(true);
|
|
779
|
+
// });
|
|
780
|
+
|
|
781
|
+
// it("should handle case sensitive URL by default", ( ) => {
|
|
782
|
+
// expect($umf.compile("/hello/world").exec("/heLLo/WORLD")).toBeNull();
|
|
783
|
+
// });
|
|
784
|
+
|
|
785
|
+
// it("should handle case insensitive URL", ( ) => {
|
|
786
|
+
// $umf.caseInsensitive(true);
|
|
787
|
+
// expect($umf.compile("/hello/world").exec("/heLLo/WORLD")).toEqual({});
|
|
788
|
+
// });
|
|
789
|
+
|
|
790
|
+
// describe("typed parameters", ( ) => {
|
|
791
|
+
// it("should accept object definitions", ( ) => {
|
|
792
|
+
// const type = { encode: ( ) => {}, decode: ( ) => {} };
|
|
793
|
+
// $umf.type("myType1", type);
|
|
794
|
+
// expect($umf.type("myType1").encode).toBe(type.encode);
|
|
795
|
+
// });
|
|
796
|
+
|
|
797
|
+
// it("should reject duplicate definitions", ( ) => {
|
|
798
|
+
// $umf.type("myType2", { encode: ( ) => {}, decode: ( ) => {} });
|
|
799
|
+
// expect(( ) => {
|
|
800
|
+
// $umf.type("myType2", {});
|
|
801
|
+
// }).toThrowError("A type named 'myType2' has already been defined.");
|
|
802
|
+
// });
|
|
803
|
+
|
|
804
|
+
// it("should accept injected function definitions", function (
|
|
805
|
+
// $stateParams,
|
|
806
|
+
// ) {
|
|
807
|
+
// $umf.type("myType3", {}, function ($stateParams) {
|
|
808
|
+
// return {
|
|
809
|
+
// decode: ( ) => {
|
|
810
|
+
// return $stateParams;
|
|
811
|
+
// },
|
|
812
|
+
// };
|
|
813
|
+
// });
|
|
814
|
+
// expect($umf.type("myType3").decode()).toBe($stateParams);
|
|
815
|
+
// });
|
|
816
|
+
|
|
817
|
+
// it("should accept annotated function definitions", function (
|
|
818
|
+
// $stateParams,
|
|
819
|
+
// ) {
|
|
820
|
+
// $umf.type("myAnnotatedType", {}, [
|
|
821
|
+
// "$stateParams",
|
|
822
|
+
// function (s) {
|
|
823
|
+
// return {
|
|
824
|
+
// decode: ( ) => {
|
|
825
|
+
// return s;
|
|
826
|
+
// },
|
|
827
|
+
// };
|
|
828
|
+
// },
|
|
829
|
+
// ]);
|
|
830
|
+
// expect($umf.type("myAnnotatedType").decode()).toBe($stateParams);
|
|
831
|
+
// });
|
|
832
|
+
|
|
833
|
+
// it("should match built-in types", ( ) => {
|
|
834
|
+
// const m = $umf.compile("/{foo:int}/{flag:bool}");
|
|
835
|
+
// expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
|
|
836
|
+
// expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
|
|
837
|
+
|
|
838
|
+
// expect(m.exec("/-1138/1")).toEqual({ foo: -1138, flag: true });
|
|
839
|
+
// expect(m.format({ foo: -5, flag: true })).toBe("/-5/1");
|
|
840
|
+
// });
|
|
841
|
+
|
|
842
|
+
// it("should match built-in types with spaces", ( ) => {
|
|
843
|
+
// const m = $umf.compile("/{foo: int}/{flag: bool}");
|
|
844
|
+
// expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
|
|
845
|
+
// expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
|
|
846
|
+
// });
|
|
847
|
+
|
|
848
|
+
// it("should match types named only in params", ( ) => {
|
|
849
|
+
// const m = $umf.compile("/{foo}/{flag}", {
|
|
850
|
+
// state: {
|
|
851
|
+
// params: {
|
|
852
|
+
// foo: { type: "int" },
|
|
853
|
+
// flag: { type: "bool" },
|
|
854
|
+
// },
|
|
855
|
+
// },
|
|
856
|
+
// });
|
|
857
|
+
// expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
|
|
858
|
+
// expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
|
|
859
|
+
// });
|
|
860
|
+
|
|
861
|
+
// it("should throw an error if a param type is declared twice", ( ) => {
|
|
862
|
+
// expect(( ) => {
|
|
863
|
+
// $umf.compile("/{foo:int}", {
|
|
864
|
+
// state: {
|
|
865
|
+
// params: {
|
|
866
|
+
// foo: { type: "int" },
|
|
867
|
+
// },
|
|
868
|
+
// },
|
|
869
|
+
// });
|
|
870
|
+
// }).toThrow(new Error("Param 'foo' has two type configurations."));
|
|
871
|
+
// });
|
|
872
|
+
|
|
873
|
+
// it("should encode/decode dates", ( ) => {
|
|
874
|
+
// const m = $umf.compile("/calendar/{date:date}"),
|
|
875
|
+
// result = m.exec("/calendar/2014-03-26");
|
|
876
|
+
// const date = new Date(2014, 2, 26);
|
|
877
|
+
|
|
878
|
+
// expect(result.date instanceof Date).toBe(true);
|
|
879
|
+
// expect(result.date.toUTCString()).toEqual(date.toUTCString());
|
|
880
|
+
// expect(m.format({ date: date })).toBe("/calendar/2014-03-26");
|
|
881
|
+
// });
|
|
882
|
+
|
|
883
|
+
// it("should encode/decode arbitrary objects to json", ( ) => {
|
|
884
|
+
// const m = $umf.compile("/state/{param1:json}/{param2:json}");
|
|
885
|
+
|
|
886
|
+
// const params = {
|
|
887
|
+
// param1: { foo: "huh", count: 3 },
|
|
888
|
+
// param2: { foo: "wha", count: 5 },
|
|
889
|
+
// };
|
|
890
|
+
|
|
891
|
+
// const json1 = '{"foo":"huh","count":3}';
|
|
892
|
+
// const json2 = '{"foo":"wha","count":5}';
|
|
893
|
+
|
|
894
|
+
// expect(m.format(params)).toBe(
|
|
895
|
+
// "/state/" + encodeURIComponent(json1) + "/" + encodeURIComponent(json2),
|
|
896
|
+
// );
|
|
897
|
+
// expect(m.exec("/state/" + json1 + "/" + json2)).toEqual(params);
|
|
898
|
+
// });
|
|
899
|
+
|
|
900
|
+
// it("should not match invalid typed parameter values", ( ) => {
|
|
901
|
+
// const m = $umf.compile("/users/{id:int}");
|
|
902
|
+
|
|
903
|
+
// expect(m.exec("/users/1138").id).toBe(1138);
|
|
904
|
+
// expect(m.exec("/users/alpha")).toBeNull();
|
|
905
|
+
|
|
906
|
+
// expect(m.format({ id: 1138 })).toBe("/users/1138");
|
|
907
|
+
// expect(m.format({ id: "alpha" })).toBeNull();
|
|
908
|
+
// });
|
|
909
|
+
|
|
910
|
+
// it("should automatically handle multiple search param values", ( ) => {
|
|
911
|
+
// const m = $umf.compile("/foo/{fooid:int}?{bar:int}");
|
|
912
|
+
|
|
913
|
+
// $url.url("/foo/5?bar=1");
|
|
914
|
+
// expect(m.exec($url.path(), $url.search())).toEqual({ fooid: 5, bar: 1 });
|
|
915
|
+
// expect(m.format({ fooid: 5, bar: 1 })).toEqual("/foo/5?bar=1");
|
|
916
|
+
|
|
917
|
+
// $url.url("/foo/5?bar=1&bar=2&bar=3");
|
|
918
|
+
// if (Array.isArray($url.search()))
|
|
919
|
+
// // conditional for angular 1.0.8
|
|
920
|
+
// expect(m.exec($url.path(), $url.search())).toEqual({
|
|
921
|
+
// fooid: 5,
|
|
922
|
+
// bar: [1, 2, 3],
|
|
923
|
+
// });
|
|
924
|
+
// expect(m.format({ fooid: 5, bar: [1, 2, 3] })).toEqual(
|
|
925
|
+
// "/foo/5?bar=1&bar=2&bar=3",
|
|
926
|
+
// );
|
|
927
|
+
|
|
928
|
+
// m.format();
|
|
929
|
+
// });
|
|
930
|
+
|
|
931
|
+
// it("should allow custom types to handle multiple search param values manually", ( ) => {
|
|
932
|
+
// $umf.type("custArray", {
|
|
933
|
+
// encode: function (array) {
|
|
934
|
+
// return array.join("-");
|
|
935
|
+
// },
|
|
936
|
+
// decode: function (val) {
|
|
937
|
+
// return Array.isArray(val) ? val : val.split(/-/);
|
|
938
|
+
// },
|
|
939
|
+
// equals: angular.equals,
|
|
940
|
+
// is: Array.isArray,
|
|
941
|
+
// });
|
|
942
|
+
|
|
943
|
+
// const m = $umf.compile("/foo?{bar:custArray}", {
|
|
944
|
+
// state: { params: { bar: { array: false } } },
|
|
945
|
+
// });
|
|
946
|
+
|
|
947
|
+
// $url.url("/foo?bar=fox");
|
|
948
|
+
// expect(m.exec($url.path(), $url.search())).toEqual({ bar: ["fox"] });
|
|
949
|
+
// expect(m.format({ bar: ["fox"] })).toEqual("/foo?bar=fox");
|
|
950
|
+
|
|
951
|
+
// $url.url("/foo?bar=quick-brown-fox");
|
|
952
|
+
// expect(m.exec($url.path(), $url.search())).toEqual({
|
|
953
|
+
// bar: ["quick", "brown", "fox"],
|
|
954
|
+
// });
|
|
955
|
+
// expect(m.format({ bar: ["quick", "brown", "fox"] })).toEqual(
|
|
956
|
+
// "/foo?bar=quick-brown-fox",
|
|
957
|
+
// );
|
|
958
|
+
// });
|
|
959
|
+
// });
|
|
960
|
+
|
|
961
|
+
// describe("optional parameters", ( ) => {
|
|
962
|
+
// it("should match with or without values", ( ) => {
|
|
963
|
+
// const m = $umf.compile("/users/{id:int}", {
|
|
964
|
+
// state: {
|
|
965
|
+
// params: { id: { value: null, squash: true } },
|
|
966
|
+
// },
|
|
967
|
+
// });
|
|
968
|
+
// expect(m.exec("/users/1138")).toEqual({ id: 1138 });
|
|
969
|
+
// expect(m.exec("/users1138")).toBeNull();
|
|
970
|
+
// expect(m.exec("/users/").id).toBeNull();
|
|
971
|
+
// expect(m.exec("/users").id).toBeNull();
|
|
972
|
+
// });
|
|
973
|
+
|
|
974
|
+
// it("should correctly match multiple", ( ) => {
|
|
975
|
+
// const m = $umf.compile("/users/{id:int}/{state:[A-Z]+}", {
|
|
976
|
+
// state: {
|
|
977
|
+
// params: {
|
|
978
|
+
// id: { value: null, squash: true },
|
|
979
|
+
// state: { value: null, squash: true },
|
|
980
|
+
// },
|
|
981
|
+
// },
|
|
982
|
+
// });
|
|
983
|
+
// expect(m.exec("/users/1138")).toEqual({ id: 1138, state: null });
|
|
984
|
+
// expect(m.exec("/users/1138/NY")).toEqual({ id: 1138, state: "NY" });
|
|
985
|
+
|
|
986
|
+
// expect(m.exec("/users/").id).toBeNull();
|
|
987
|
+
// expect(m.exec("/users/").state).toBeNull();
|
|
988
|
+
|
|
989
|
+
// expect(m.exec("/users").id).toBeNull();
|
|
990
|
+
// expect(m.exec("/users").state).toBeNull();
|
|
991
|
+
|
|
992
|
+
// expect(m.exec("/users/NY").state).toBe("NY");
|
|
993
|
+
// expect(m.exec("/users/NY").id).toBeNull();
|
|
994
|
+
// });
|
|
995
|
+
|
|
996
|
+
// it("should correctly format with or without values", ( ) => {
|
|
997
|
+
// const m = $umf.compile("/users/{id:int}", {
|
|
998
|
+
// state: {
|
|
999
|
+
// params: { id: { value: null } },
|
|
1000
|
+
// },
|
|
1001
|
+
// });
|
|
1002
|
+
// expect(m.format()).toBe("/users/");
|
|
1003
|
+
// expect(m.format({ id: 1138 })).toBe("/users/1138");
|
|
1004
|
+
// });
|
|
1005
|
+
|
|
1006
|
+
// it("should correctly format multiple", ( ) => {
|
|
1007
|
+
// const m = $umf.compile("/users/{id:int}/{state:[A-Z]+}", {
|
|
1008
|
+
// state: {
|
|
1009
|
+
// params: {
|
|
1010
|
+
// id: { value: null, squash: true },
|
|
1011
|
+
// state: { value: null, squash: true },
|
|
1012
|
+
// },
|
|
1013
|
+
// },
|
|
1014
|
+
// });
|
|
1015
|
+
|
|
1016
|
+
// expect(m.format()).toBe("/users");
|
|
1017
|
+
// expect(m.format({ id: 1138 })).toBe("/users/1138");
|
|
1018
|
+
// expect(m.format({ state: "NY" })).toBe("/users/NY");
|
|
1019
|
+
// expect(m.format({ id: 1138, state: "NY" })).toBe("/users/1138/NY");
|
|
1020
|
+
// });
|
|
1021
|
+
|
|
1022
|
+
// it("should match in between static segments", ( ) => {
|
|
1023
|
+
// const m = $umf.compile("/users/{user:int}/photos", {
|
|
1024
|
+
// state: {
|
|
1025
|
+
// params: { user: { value: 5, squash: true } },
|
|
1026
|
+
// },
|
|
1027
|
+
// });
|
|
1028
|
+
// expect(m.exec("/users/photos").user).toBe(5);
|
|
1029
|
+
// expect(m.exec("/users/6/photos").user).toBe(6);
|
|
1030
|
+
// expect(m.format()).toBe("/users/photos");
|
|
1031
|
+
// expect(m.format({ user: 1138 })).toBe("/users/1138/photos");
|
|
1032
|
+
// });
|
|
1033
|
+
|
|
1034
|
+
// it("should correctly format with an optional followed by a required parameter", ( ) => {
|
|
1035
|
+
// const m = $umf.compile("/home/:user/gallery/photos/:photo", {
|
|
1036
|
+
// state: {
|
|
1037
|
+
// params: {
|
|
1038
|
+
// user: { value: null, squash: true },
|
|
1039
|
+
// photo: undefined,
|
|
1040
|
+
// },
|
|
1041
|
+
// },
|
|
1042
|
+
// });
|
|
1043
|
+
// expect(m.format({ photo: 12 })).toBe("/home/gallery/photos/12");
|
|
1044
|
+
// expect(m.format({ user: 1138, photo: 13 })).toBe(
|
|
1045
|
+
// "/home/1138/gallery/photos/13",
|
|
1046
|
+
// );
|
|
1047
|
+
// });
|
|
1048
|
+
|
|
1049
|
+
// describe("default values", ( ) => {
|
|
1050
|
+
// it("should populate if not supplied in URL", ( ) => {
|
|
1051
|
+
// const m = $umf.compile("/users/{id:int}/{test}", {
|
|
1052
|
+
// state: {
|
|
1053
|
+
// params: {
|
|
1054
|
+
// id: { value: 0, squash: true },
|
|
1055
|
+
// test: { value: "foo", squash: true },
|
|
1056
|
+
// },
|
|
1057
|
+
// },
|
|
1058
|
+
// });
|
|
1059
|
+
// expect(m.exec("/users")).toEqual({ id: 0, test: "foo" });
|
|
1060
|
+
// expect(m.exec("/users/2")).toEqual({ id: 2, test: "foo" });
|
|
1061
|
+
// expect(m.exec("/users/bar")).toEqual({ id: 0, test: "bar" });
|
|
1062
|
+
// expect(m.exec("/users/2/bar")).toEqual({ id: 2, test: "bar" });
|
|
1063
|
+
// expect(m.exec("/users/bar/2")).toBeNull();
|
|
1064
|
+
// });
|
|
1065
|
+
|
|
1066
|
+
// it("should populate even if the regexp requires 1 or more chars", ( ) => {
|
|
1067
|
+
// const m = $umf.compile(
|
|
1068
|
+
// "/record/{appId}/{recordId:[0-9a-fA-F]{10,24}}",
|
|
1069
|
+
// {
|
|
1070
|
+
// state: {
|
|
1071
|
+
// params: { appId: null, recordId: null },
|
|
1072
|
+
// },
|
|
1073
|
+
// },
|
|
1074
|
+
// );
|
|
1075
|
+
// expect(m.exec("/record/546a3e4dd273c60780e35df3/")).toEqual({
|
|
1076
|
+
// appId: "546a3e4dd273c60780e35df3",
|
|
1077
|
+
// recordId: null,
|
|
1078
|
+
// });
|
|
1079
|
+
// });
|
|
1080
|
+
|
|
1081
|
+
// it("should allow shorthand definitions", ( ) => {
|
|
1082
|
+
// const m = $umf.compile("/foo/:foo", {
|
|
1083
|
+
// state: {
|
|
1084
|
+
// params: { foo: "bar" },
|
|
1085
|
+
// },
|
|
1086
|
+
// });
|
|
1087
|
+
// expect(m.exec("/foo/")).toEqual({ foo: "bar" });
|
|
1088
|
+
// });
|
|
1089
|
+
|
|
1090
|
+
// it("should populate query params", ( ) => {
|
|
1091
|
+
// const defaults = { order: "name", limit: 25, page: 1 };
|
|
1092
|
+
// const m = $umf.compile("/foo?order&{limit:int}&{page:int}", {
|
|
1093
|
+
// state: {
|
|
1094
|
+
// params: defaults,
|
|
1095
|
+
// },
|
|
1096
|
+
// });
|
|
1097
|
+
// expect(m.exec("/foo")).toEqual(defaults);
|
|
1098
|
+
// });
|
|
1099
|
+
|
|
1100
|
+
// it("should allow function-calculated values", ( ) => {
|
|
1101
|
+
// function barFn() {
|
|
1102
|
+
// return "Value from bar()";
|
|
1103
|
+
// }
|
|
1104
|
+
// let m = $umf.compile("/foo/:bar", {
|
|
1105
|
+
// state: {
|
|
1106
|
+
// params: { bar: barFn },
|
|
1107
|
+
// },
|
|
1108
|
+
// });
|
|
1109
|
+
// expect(m.exec("/foo/").bar).toBe("Value from bar()");
|
|
1110
|
+
|
|
1111
|
+
// m = $umf.compile("/foo/:bar", {
|
|
1112
|
+
// state: {
|
|
1113
|
+
// params: { bar: { value: barFn, squash: true } },
|
|
1114
|
+
// },
|
|
1115
|
+
// });
|
|
1116
|
+
// expect(m.exec("/foo").bar).toBe("Value from bar()");
|
|
1117
|
+
|
|
1118
|
+
// m = $umf.compile("/foo?bar", {
|
|
1119
|
+
// state: {
|
|
1120
|
+
// params: { bar: barFn },
|
|
1121
|
+
// },
|
|
1122
|
+
// });
|
|
1123
|
+
// expect(m.exec("/foo").bar).toBe("Value from bar()");
|
|
1124
|
+
// });
|
|
1125
|
+
|
|
1126
|
+
// it("should allow injectable functions", function ($stateParams) {
|
|
1127
|
+
// const m = $umf.compile("/users/{user:json}", {
|
|
1128
|
+
// state: {
|
|
1129
|
+
// params: {
|
|
1130
|
+
// user: function ($stateParams) {
|
|
1131
|
+
// return $stateParams.user;
|
|
1132
|
+
// },
|
|
1133
|
+
// },
|
|
1134
|
+
// },
|
|
1135
|
+
// });
|
|
1136
|
+
// const user = { name: "Bob" };
|
|
1137
|
+
|
|
1138
|
+
// $stateParams.user = user;
|
|
1139
|
+
// expect(m.exec("/users/").user).toBe(user);
|
|
1140
|
+
// });
|
|
1141
|
+
|
|
1142
|
+
// xit("should match when used as prefix", ( ) => {
|
|
1143
|
+
// const m = $umf.compile("/{lang:[a-z]{2}}/foo", {
|
|
1144
|
+
// state: {
|
|
1145
|
+
// params: { lang: "de" },
|
|
1146
|
+
// },
|
|
1147
|
+
// });
|
|
1148
|
+
// expect(m.exec("/de/foo")).toEqual({ lang: "de" });
|
|
1149
|
+
// expect(m.exec("/foo")).toEqual({ lang: "de" });
|
|
1150
|
+
// });
|
|
1151
|
+
|
|
1152
|
+
// describe("squash policy", ( ) => {
|
|
1153
|
+
// const Session = { username: "loggedinuser" };
|
|
1154
|
+
// function getMatcher(squash) {
|
|
1155
|
+
// return $umf.compile(
|
|
1156
|
+
// "/user/:userid/gallery/:galleryid/photo/:photoid",
|
|
1157
|
+
// {
|
|
1158
|
+
// state: {
|
|
1159
|
+
// params: {
|
|
1160
|
+
// userid: {
|
|
1161
|
+
// squash: squash,
|
|
1162
|
+
// value: ( ) => {
|
|
1163
|
+
// return Session.username;
|
|
1164
|
+
// },
|
|
1165
|
+
// },
|
|
1166
|
+
// galleryid: { squash: squash, value: "favorites" },
|
|
1167
|
+
// },
|
|
1168
|
+
// },
|
|
1169
|
+
// },
|
|
1170
|
+
// );
|
|
1171
|
+
// }
|
|
1172
|
+
|
|
1173
|
+
// it(": true should squash the default value and one slash", function (
|
|
1174
|
+
// $stateParams,
|
|
1175
|
+
// ) {
|
|
1176
|
+
// const m = getMatcher(true);
|
|
1177
|
+
|
|
1178
|
+
// const defaultParams = {
|
|
1179
|
+
// userid: "loggedinuser",
|
|
1180
|
+
// galleryid: "favorites",
|
|
1181
|
+
// photoid: "123",
|
|
1182
|
+
// };
|
|
1183
|
+
// expect(m.exec("/user/gallery/photo/123")).toEqual(defaultParams);
|
|
1184
|
+
// expect(m.exec("/user//gallery//photo/123")).toEqual(defaultParams);
|
|
1185
|
+
// expect(m.format(defaultParams)).toBe("/user/gallery/photo/123");
|
|
1186
|
+
|
|
1187
|
+
// const nonDefaultParams = {
|
|
1188
|
+
// userid: "otheruser",
|
|
1189
|
+
// galleryid: "travel",
|
|
1190
|
+
// photoid: "987",
|
|
1191
|
+
// };
|
|
1192
|
+
// expect(m.exec("/user/otheruser/gallery/travel/photo/987")).toEqual(
|
|
1193
|
+
// nonDefaultParams,
|
|
1194
|
+
// );
|
|
1195
|
+
// expect(m.format(nonDefaultParams)).toBe(
|
|
1196
|
+
// "/user/otheruser/gallery/travel/photo/987",
|
|
1197
|
+
// );
|
|
1198
|
+
// });
|
|
1199
|
+
|
|
1200
|
+
// it(": false should not squash default values", function (
|
|
1201
|
+
// $stateParams,
|
|
1202
|
+
// ) {
|
|
1203
|
+
// const m = getMatcher(false);
|
|
1204
|
+
|
|
1205
|
+
// const defaultParams = {
|
|
1206
|
+
// userid: "loggedinuser",
|
|
1207
|
+
// galleryid: "favorites",
|
|
1208
|
+
// photoid: "123",
|
|
1209
|
+
// };
|
|
1210
|
+
// expect(
|
|
1211
|
+
// m.exec("/user/loggedinuser/gallery/favorites/photo/123"),
|
|
1212
|
+
// ).toEqual(defaultParams);
|
|
1213
|
+
// expect(m.format(defaultParams)).toBe(
|
|
1214
|
+
// "/user/loggedinuser/gallery/favorites/photo/123",
|
|
1215
|
+
// );
|
|
1216
|
+
|
|
1217
|
+
// const nonDefaultParams = {
|
|
1218
|
+
// userid: "otheruser",
|
|
1219
|
+
// galleryid: "travel",
|
|
1220
|
+
// photoid: "987",
|
|
1221
|
+
// };
|
|
1222
|
+
// expect(m.exec("/user/otheruser/gallery/travel/photo/987")).toEqual(
|
|
1223
|
+
// nonDefaultParams,
|
|
1224
|
+
// );
|
|
1225
|
+
// expect(m.format(nonDefaultParams)).toBe(
|
|
1226
|
+
// "/user/otheruser/gallery/travel/photo/987",
|
|
1227
|
+
// );
|
|
1228
|
+
// });
|
|
1229
|
+
|
|
1230
|
+
// it(": '' should squash the default value to an empty string", function (
|
|
1231
|
+
// $stateParams,
|
|
1232
|
+
// ) {
|
|
1233
|
+
// const m = getMatcher("");
|
|
1234
|
+
|
|
1235
|
+
// const defaultParams = {
|
|
1236
|
+
// userid: "loggedinuser",
|
|
1237
|
+
// galleryid: "favorites",
|
|
1238
|
+
// photoid: "123",
|
|
1239
|
+
// };
|
|
1240
|
+
// expect(m.exec("/user//gallery//photo/123")).toEqual(defaultParams);
|
|
1241
|
+
// expect(m.format(defaultParams)).toBe("/user//gallery//photo/123");
|
|
1242
|
+
|
|
1243
|
+
// const nonDefaultParams = {
|
|
1244
|
+
// userid: "otheruser",
|
|
1245
|
+
// galleryid: "travel",
|
|
1246
|
+
// photoid: "987",
|
|
1247
|
+
// };
|
|
1248
|
+
// expect(m.exec("/user/otheruser/gallery/travel/photo/987")).toEqual(
|
|
1249
|
+
// nonDefaultParams,
|
|
1250
|
+
// );
|
|
1251
|
+
// expect(m.format(nonDefaultParams)).toBe(
|
|
1252
|
+
// "/user/otheruser/gallery/travel/photo/987",
|
|
1253
|
+
// );
|
|
1254
|
+
// });
|
|
1255
|
+
|
|
1256
|
+
// it(": '~' should squash the default value and replace it with '~'", function (
|
|
1257
|
+
// $stateParams,
|
|
1258
|
+
// ) {
|
|
1259
|
+
// const m = getMatcher("~");
|
|
1260
|
+
|
|
1261
|
+
// const defaultParams = {
|
|
1262
|
+
// userid: "loggedinuser",
|
|
1263
|
+
// galleryid: "favorites",
|
|
1264
|
+
// photoid: "123",
|
|
1265
|
+
// };
|
|
1266
|
+
// expect(m.exec("/user//gallery//photo/123")).toEqual(defaultParams);
|
|
1267
|
+
// expect(m.exec("/user/~/gallery/~/photo/123")).toEqual(defaultParams);
|
|
1268
|
+
// expect(m.format(defaultParams)).toBe("/user/~/gallery/~/photo/123");
|
|
1269
|
+
|
|
1270
|
+
// const nonDefaultParams = {
|
|
1271
|
+
// userid: "otheruser",
|
|
1272
|
+
// galleryid: "travel",
|
|
1273
|
+
// photoid: "987",
|
|
1274
|
+
// };
|
|
1275
|
+
// expect(m.exec("/user/otheruser/gallery/travel/photo/987")).toEqual(
|
|
1276
|
+
// nonDefaultParams,
|
|
1277
|
+
// );
|
|
1278
|
+
// expect(m.format(nonDefaultParams)).toBe(
|
|
1279
|
+
// "/user/otheruser/gallery/travel/photo/987",
|
|
1280
|
+
// );
|
|
1281
|
+
// });
|
|
1282
|
+
// });
|
|
1283
|
+
// });
|
|
1284
|
+
// });
|
|
1285
|
+
|
|
1286
|
+
// describe("strict matching", ( ) => {
|
|
1287
|
+
// it("should match with or without trailing slash", ( ) => {
|
|
1288
|
+
// const m = $umf.compile("/users", { strict: false });
|
|
1289
|
+
// expect(m.exec("/users")).toEqual({});
|
|
1290
|
+
// expect(m.exec("/users/")).toEqual({});
|
|
1291
|
+
// });
|
|
1292
|
+
|
|
1293
|
+
// it("should not match multiple trailing slashes", ( ) => {
|
|
1294
|
+
// const m = $umf.compile("/users", { strict: false });
|
|
1295
|
+
// expect(m.exec("/users//")).toBeNull();
|
|
1296
|
+
// });
|
|
1297
|
+
|
|
1298
|
+
// it("should match when defined with parameters", ( ) => {
|
|
1299
|
+
// const m = $umf.compile("/users/{name}", {
|
|
1300
|
+
// strict: false,
|
|
1301
|
+
// state: {
|
|
1302
|
+
// params: {
|
|
1303
|
+
// name: { value: null },
|
|
1304
|
+
// },
|
|
1305
|
+
// },
|
|
1306
|
+
// });
|
|
1307
|
+
// expect(m.exec("/users/")).toEqual({ name: null });
|
|
1308
|
+
// expect(m.exec("/users/bob")).toEqual({ name: "bob" });
|
|
1309
|
+
// expect(m.exec("/users/bob/")).toEqual({ name: "bob" });
|
|
1310
|
+
// expect(m.exec("/users/bob//")).toBeNull();
|
|
1311
|
+
// });
|
|
1312
|
+
// });
|
|
1313
|
+
// });
|