@angular-wave/angular.ts 0.0.22 → 0.0.24
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/core/compile.js +2 -3
- package/src/core/parser/parse.js +2 -3
- package/src/filters/order-by.js +8 -8
- package/src/router/directives/{stateDirectives.js → state-directives.js} +1 -2
- package/src/router/directives/{viewDirective.js → view-directive.js} +4 -12
- package/src/router/globals.js +1 -1
- package/src/router/hooks/{ignoredTransition.js → ignored-transition.js} +1 -1
- package/src/router/hooks/{redirectTo.js → redirect-to.js} +1 -1
- package/src/router/hooks/resolve.js +1 -1
- package/src/router/index.js +6 -8
- package/src/router/params/{paramTypes.js → param-types.js} +3 -4
- package/src/router/params/param.js +1 -1
- package/src/router/path/{pathUtils.js → path-utils.js} +2 -2
- package/src/router/resolve/resolvable.js +2 -2
- package/src/router/resolve/{resolveContext.js → resolve-context.js} +1 -1
- package/src/router/router.js +8 -8
- package/src/router/services.js +3 -3
- package/src/router/state/{stateBuilder.js → state-builder.js} +2 -3
- package/src/router/state/{stateQueueManager.js → state-queue-manager.js} +2 -1
- package/src/router/state/{stateRegistry.js → state-registry.js} +3 -3
- package/src/router/state/{stateService.js → state-service.js} +7 -7
- package/src/router/state/views.js +1 -1
- package/src/router/{stateProvider.js → state-provider.js} +8 -0
- package/src/router/{templateFactory.js → template-factory.js} +93 -51
- package/src/router/transition/{hookBuilder.js → hook-builder.js} +3 -3
- package/src/router/transition/{transitionEventType.js → transition-event-type.js} +1 -1
- package/src/router/transition/{transitionHook.js → transition-hook.js} +2 -2
- package/src/router/transition/{transitionService.js → transition-service.js} +10 -10
- package/src/router/transition/transition.js +12 -9
- package/src/router/url/{urlConfig.js → url-config.js} +1 -1
- package/src/router/url/{urlMatcherFactory.js → url-matcher-factory.js} +1 -1
- package/src/router/url/{urlMatcher.js → url-matcher.js} +0 -2
- package/src/router/url/{urlRouter.js → url-router.js} +1 -1
- package/src/router/url/{urlRule.js → url-rule.js} +13 -5
- package/src/router/url/{urlRules.js → url-rules.js} +3 -3
- package/src/router/url/{urlService.js → url-service.js} +6 -6
- package/src/services/browser.js +3 -18
- package/src/shared/strings.js +2 -2
- 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
- package/test/test-utils.js +9 -0
- package/types/router/legacy/resolveService.d.ts +1 -1
- package/types/router/statebuilders/onEnterExitRetain.d.ts +1 -1
- package/types/router/statebuilders/views.d.ts +1 -2
- /package/src/router/hooks/{coreResolvables.js → core-resolvables.js} +0 -0
- /package/src/router/hooks/{invalidTransition.js → invalid-transition.js} +0 -0
- /package/src/router/hooks/{lazyLoad.js → lazy-load.js} +0 -0
- /package/src/router/hooks/{onEnterExitRetain.js → on-enter-exit-retain.js} +0 -0
- /package/src/router/hooks/{updateGlobals.js → update-globals.js} +0 -0
- /package/src/router/{locationServices.js → location-services.js} +0 -0
- /package/src/router/params/{paramType.js → param-type.js} +0 -0
- /package/src/router/params/{stateParams.js → state-params.js} +0 -0
- /package/src/router/path/{pathNode.js → path-node.js} +0 -0
- /package/src/router/state/{stateMatcher.js → state-matcher.js} +0 -0
- /package/src/router/state/{stateObject.js → state-object.js} +0 -0
- /package/src/router/state/{targetState.js → target-state.js} +0 -0
- /package/src/router/{stateFilters.js → state-filters.js} +0 -0
- /package/src/router/transition/{hookRegistry.js → hook-registry.js} +0 -0
- /package/src/router/transition/{rejectFactory.js → reject-factory.js} +0 -0
- /package/src/router/{viewScroll.js → view-scroll.js} +0 -0
|
@@ -3,7 +3,8 @@ import { Angular } from "../../src/loader";
|
|
|
3
3
|
import { publishExternalAPI } from "../../src/public";
|
|
4
4
|
import { browserTrigger, wait } from "../test-utils";
|
|
5
5
|
|
|
6
|
-
describe("uiStateRef",
|
|
6
|
+
describe("uiStateRef", () => {
|
|
7
|
+
window.location.hash = "#!";
|
|
7
8
|
let el,
|
|
8
9
|
el2,
|
|
9
10
|
template,
|
|
@@ -59,7 +60,7 @@ describe("uiStateRef", function () {
|
|
|
59
60
|
|
|
60
61
|
afterEach(() => (window.location.hash = "#!"));
|
|
61
62
|
|
|
62
|
-
describe("links with promises",
|
|
63
|
+
describe("links with promises", () => {
|
|
63
64
|
it("should update the href when promises on parameters change before scope is applied", async () => {
|
|
64
65
|
const defer = $q.defer();
|
|
65
66
|
el = jqLite(
|
|
@@ -77,6 +78,7 @@ describe("uiStateRef", function () {
|
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
function buildDOM() {
|
|
81
|
+
window.location.hash = "#";
|
|
80
82
|
el = jqLite(
|
|
81
83
|
'<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>',
|
|
82
84
|
);
|
|
@@ -90,16 +92,16 @@ describe("uiStateRef", function () {
|
|
|
90
92
|
scope.$digest();
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
describe("links",
|
|
95
|
+
describe("links", () => {
|
|
94
96
|
beforeEach(() => buildDOM());
|
|
95
97
|
afterEach(() => (window.location.hash = ""));
|
|
96
98
|
|
|
97
|
-
it("should generate the correct href",
|
|
99
|
+
it("should generate the correct href", () => {
|
|
98
100
|
expect(el.attr("href")).toBe("#/contacts/5");
|
|
99
101
|
expect(el2.attr("href")).toBe("#");
|
|
100
102
|
});
|
|
101
103
|
|
|
102
|
-
it("should update the href when parameters change",
|
|
104
|
+
it("should update the href when parameters change", () => {
|
|
103
105
|
expect(el.attr("href")).toBe("#/contacts/5");
|
|
104
106
|
scope.contact.id = 6;
|
|
105
107
|
scope.$apply();
|
|
@@ -151,6 +153,7 @@ describe("uiStateRef", function () {
|
|
|
151
153
|
expect($stateParams.id).toBeUndefined();
|
|
152
154
|
});
|
|
153
155
|
|
|
156
|
+
// TODO investigate further why this fails
|
|
154
157
|
xit("should not transition states when alt-clicked", async () => {
|
|
155
158
|
expect($state.current.name).toEqual("");
|
|
156
159
|
|
|
@@ -186,83 +189,86 @@ describe("uiStateRef", function () {
|
|
|
186
189
|
});
|
|
187
190
|
|
|
188
191
|
// // Test for #1031
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// el = jqLite('<a ui-sref="{id: $index}">Details</a>');
|
|
195
|
-
// $compile(el)($rootScope);
|
|
196
|
-
// $rootScope.$digest();
|
|
197
|
-
|
|
198
|
-
// expect($state.current.name).toBe('other');
|
|
199
|
-
// expect($state.params).toEqual(expect.objectContaining({ id: 'abc' });
|
|
200
|
-
// expect(el.attr('href')).toBe('#/other/def');
|
|
192
|
+
it("should allow passing params to current state", async () => {
|
|
193
|
+
$state.go("other", { id: "abc" });
|
|
194
|
+
$rootScope.$index = "def";
|
|
195
|
+
$rootScope.$digest();
|
|
201
196
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
197
|
+
el = jqLite('<a ui-sref="{id: $index}">Details</a>');
|
|
198
|
+
$compile(el)($rootScope);
|
|
199
|
+
$rootScope.$digest();
|
|
205
200
|
|
|
206
|
-
|
|
207
|
-
|
|
201
|
+
expect($state.current.name).toBe("other");
|
|
202
|
+
expect($state.params.id).toEqual("abc");
|
|
203
|
+
expect(el.attr("href")).toBe("#/other/def");
|
|
208
204
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
205
|
+
browserTrigger(el, "click");
|
|
206
|
+
await wait(100);
|
|
207
|
+
expect($state.current.name).toBe("other");
|
|
208
|
+
expect($state.params.id).toEqual("def");
|
|
212
209
|
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
$rootScope.$index = "ghi";
|
|
211
|
+
$state.go("other.detail");
|
|
212
|
+
$rootScope.$digest();
|
|
215
213
|
|
|
216
|
-
|
|
214
|
+
expect($state.current.name).toBe("other.detail");
|
|
215
|
+
expect($state.params.id).toEqual("def");
|
|
217
216
|
|
|
218
|
-
|
|
219
|
-
// timeoutFlush();
|
|
220
|
-
// $q.flush();
|
|
217
|
+
expect(el.attr("href")).toBe("#/other/ghi/detail");
|
|
221
218
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
browserTrigger(el, "click");
|
|
220
|
+
await wait(100);
|
|
221
|
+
expect($state.current.name).toBe("other.detail");
|
|
222
|
+
expect($state.params.id).toEqual("ghi");
|
|
223
|
+
});
|
|
225
224
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
it("should allow multi-line attribute values when passing params to current state", async () => {
|
|
226
|
+
$state.go("contacts.item.detail", { id: "123" });
|
|
227
|
+
$rootScope.$digest();
|
|
229
228
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
el = jqLite('<a ui-sref="{\n\tid: $index\n}">Details</a>');
|
|
230
|
+
$rootScope.$index = 3;
|
|
231
|
+
$rootScope.$apply();
|
|
233
232
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
$compile(el)($rootScope);
|
|
234
|
+
$rootScope.$digest();
|
|
235
|
+
expect(el.attr("href")).toBe("#/contacts/3");
|
|
236
|
+
});
|
|
238
237
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
it("should take an object as a parameter and update properly on digest churns", async () => {
|
|
239
|
+
el = jqLite(
|
|
240
|
+
'<div><a ui-sref="contacts.item.detail(urlParams)">Contacts</a></div>',
|
|
241
|
+
);
|
|
242
|
+
template = $compile(el)($rootScope);
|
|
242
243
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
$rootScope.urlParams = { id: 1 };
|
|
245
|
+
$rootScope.$digest();
|
|
246
|
+
expect(jqLite(template[0].querySelector("a")).attr("href")).toBe(
|
|
247
|
+
"#/contacts/1",
|
|
248
|
+
);
|
|
246
249
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
$rootScope.urlParams.id = 2;
|
|
251
|
+
$rootScope.$digest();
|
|
252
|
+
expect(jqLite(template[0].querySelector("a")).attr("href")).toBe(
|
|
253
|
+
"#/contacts/2",
|
|
254
|
+
);
|
|
255
|
+
});
|
|
251
256
|
});
|
|
252
257
|
|
|
253
|
-
//
|
|
254
|
-
//
|
|
258
|
+
// TODO: Since this is HTML5 mode, we would want to test this with actual backend
|
|
259
|
+
// describe('links in html5 mode', () => {
|
|
260
|
+
// beforeEach(() => {
|
|
255
261
|
// _locationProvider.html5Mode(true);
|
|
256
262
|
// });
|
|
257
263
|
|
|
258
264
|
// beforeEach(inject(buildDOM));
|
|
259
265
|
|
|
260
|
-
// it('should generate the correct href',
|
|
266
|
+
// it('should generate the correct href', () => {
|
|
261
267
|
// expect(el.attr('href')).toBe('/contacts/5');
|
|
262
268
|
// expect(el2.attr('href')).toBe('');
|
|
263
269
|
// });
|
|
264
270
|
|
|
265
|
-
// it('should update the href when parameters change',
|
|
271
|
+
// it('should update the href when parameters change', () => {
|
|
266
272
|
// expect(el.attr('href')).toBe('/contacts/5');
|
|
267
273
|
// scope.contact.id = 6;
|
|
268
274
|
// scope.$apply();
|
|
@@ -275,934 +281,902 @@ describe("uiStateRef", function () {
|
|
|
275
281
|
|
|
276
282
|
// triggerClick(el2);
|
|
277
283
|
// timeoutFlush();
|
|
278
|
-
//
|
|
284
|
+
// await wait(10);
|
|
279
285
|
|
|
280
286
|
// expect($state.current.name).toEqual('top');
|
|
281
287
|
// expect(obj($stateParams)).toEqual({});
|
|
282
288
|
// });
|
|
283
289
|
// });
|
|
284
290
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
// beforeEach(inject(function ($rootScope, $compile, _$state_) {
|
|
289
|
-
// $state = _$state_;
|
|
290
|
-
// el = jqLite(
|
|
291
|
-
// '<a ui-sref-active="active" ui-sref-active-eq="activeeq" ui-state="state" ui-state-params="params">state</a>'
|
|
292
|
-
// );
|
|
293
|
-
// scope = $rootScope;
|
|
294
|
-
// angular.extend(scope, { state: 'contacts', params: {} });
|
|
295
|
-
// template = $compile(el)(scope);
|
|
296
|
-
// scope.$digest();
|
|
297
|
-
// });
|
|
291
|
+
describe("links with dynamic state definitions", () => {
|
|
292
|
+
let template;
|
|
298
293
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
294
|
+
beforeEach(() => {
|
|
295
|
+
el = jqLite(
|
|
296
|
+
'<a ui-sref-active="active" ui-sref-active-eq="activeeq" ui-state="state" ui-state-params="params">state</a>',
|
|
297
|
+
);
|
|
298
|
+
scope = $rootScope;
|
|
299
|
+
Object.assign(scope, { state: "contacts", params: {} });
|
|
300
|
+
template = $compile(el)(scope);
|
|
301
|
+
scope.$digest();
|
|
302
|
+
});
|
|
302
303
|
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
it("sets the correct initial href", () => {
|
|
305
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts");
|
|
306
|
+
});
|
|
305
307
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
// scope.$digest();
|
|
309
|
-
// expect(jqLite(template[0]).attr('href')).toBe('#/contacts/5');
|
|
308
|
+
it("updates to the new href", () => {
|
|
309
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts");
|
|
310
310
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
311
|
+
scope.state = "contacts.item";
|
|
312
|
+
scope.params = { id: 5 };
|
|
313
|
+
scope.$digest();
|
|
314
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/5");
|
|
315
315
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
// $timeout.flush();
|
|
321
|
-
// } catch (error) {}
|
|
322
|
-
// }
|
|
323
|
-
// expect(template[0].className).not.toContain('active');
|
|
324
|
-
// expect(template[0].className).not.toContain('activeeq');
|
|
325
|
-
|
|
326
|
-
// $state.go('contacts');
|
|
327
|
-
// tick();
|
|
328
|
-
// expect(template[0].className).toContain('active activeeq');
|
|
329
|
-
|
|
330
|
-
// scope.state = 'contacts.item';
|
|
331
|
-
// scope.params = { id: 5 };
|
|
332
|
-
// tick();
|
|
333
|
-
// expect(template[0].className).not.toContain('active');
|
|
334
|
-
// expect(template[0].className).not.toContain('activeeq');
|
|
335
|
-
|
|
336
|
-
// $state.go('contacts.item', { id: -5 });
|
|
337
|
-
// tick();
|
|
338
|
-
// expect(template[0].className).not.toContain('active');
|
|
339
|
-
// expect(template[0].className).not.toContain('activeeq');
|
|
340
|
-
|
|
341
|
-
// $state.go('contacts.item', { id: 5 });
|
|
342
|
-
// tick();
|
|
343
|
-
// expect(template[0].className).toContain('active activeeq');
|
|
344
|
-
|
|
345
|
-
// scope.state = 'contacts';
|
|
346
|
-
// scope.params = {};
|
|
347
|
-
// tick();
|
|
348
|
-
// expect(template[0].className).toContain('active');
|
|
349
|
-
// expect(template[0].className).not.toContain('activeeq');
|
|
350
|
-
// });
|
|
316
|
+
scope.params.id = 25;
|
|
317
|
+
scope.$digest();
|
|
318
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/25");
|
|
319
|
+
});
|
|
351
320
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
321
|
+
it("updates a linked ui-sref-active", async () => {
|
|
322
|
+
expect(template[0].className).not.toContain("active");
|
|
323
|
+
expect(template[0].className).not.toContain("activeeq");
|
|
324
|
+
|
|
325
|
+
$state.go("contacts");
|
|
326
|
+
scope.$digest();
|
|
327
|
+
await wait(10);
|
|
328
|
+
expect(template[0].className).toContain("active activeeq");
|
|
329
|
+
|
|
330
|
+
scope.state = "contacts.item";
|
|
331
|
+
scope.params = { id: 5 };
|
|
332
|
+
scope.$digest();
|
|
333
|
+
await wait(10);
|
|
334
|
+
expect(template[0].className).not.toContain("active");
|
|
335
|
+
expect(template[0].className).not.toContain("activeeq");
|
|
336
|
+
|
|
337
|
+
$state.go("contacts.item", { id: -5 });
|
|
338
|
+
scope.$digest();
|
|
339
|
+
await wait(10);
|
|
340
|
+
expect(template[0].className).not.toContain("active");
|
|
341
|
+
expect(template[0].className).not.toContain("activeeq");
|
|
342
|
+
|
|
343
|
+
$state.go("contacts.item", { id: 5 });
|
|
344
|
+
scope.$digest();
|
|
345
|
+
await wait(10);
|
|
346
|
+
expect(template[0].className).toContain("active activeeq");
|
|
347
|
+
|
|
348
|
+
scope.state = "contacts";
|
|
349
|
+
scope.params = {};
|
|
350
|
+
scope.$digest();
|
|
351
|
+
await wait(10);
|
|
352
|
+
expect(template[0].className).toContain("active");
|
|
353
|
+
expect(template[0].className).not.toContain("activeeq");
|
|
354
|
+
});
|
|
359
355
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// $state.go('other', { id: 'abc' });
|
|
368
|
-
// $rootScope.$index = 'def';
|
|
369
|
-
// $rootScope.$digest();
|
|
370
|
-
|
|
371
|
-
// el = jqLite('<a ui-state="" ui-state-params="{id: $index}">Details</a>');
|
|
372
|
-
// $compile(el)($rootScope);
|
|
373
|
-
// $rootScope.$digest();
|
|
374
|
-
|
|
375
|
-
// expect($state.current.name).toBe('other');
|
|
376
|
-
// expect($state.params).toEqual(expect.objectContaining({ id: 'abc' });
|
|
377
|
-
// expect(el.attr('href')).toBe('#/other/def');
|
|
378
|
-
|
|
379
|
-
// triggerClick(el);
|
|
380
|
-
// timeoutFlush();
|
|
381
|
-
// $q.flush();
|
|
356
|
+
it("updates to a new href when it points to a new state", () => {
|
|
357
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts");
|
|
358
|
+
scope.state = "other";
|
|
359
|
+
scope.params = { id: "123" };
|
|
360
|
+
scope.$digest();
|
|
361
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/other/123");
|
|
362
|
+
});
|
|
382
363
|
|
|
383
|
-
|
|
384
|
-
|
|
364
|
+
it("should allow passing params to current state using empty ui-state", async () => {
|
|
365
|
+
$state.go("other", { id: "abc" });
|
|
366
|
+
$rootScope.$index = "def";
|
|
367
|
+
$rootScope.$digest();
|
|
385
368
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
369
|
+
el = jqLite('<a ui-state="" ui-state-params="{id: $index}">Details</a>');
|
|
370
|
+
$compile(el)($rootScope);
|
|
371
|
+
$rootScope.$digest();
|
|
389
372
|
|
|
390
|
-
|
|
391
|
-
|
|
373
|
+
expect($state.current.name).toBe("other");
|
|
374
|
+
expect($state.params.id).toEqual("abc");
|
|
375
|
+
expect(el.attr("href")).toBe("#/other/def");
|
|
392
376
|
|
|
393
|
-
|
|
377
|
+
browserTrigger(el, "click");
|
|
378
|
+
await wait(10);
|
|
394
379
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
// $q.flush();
|
|
380
|
+
expect($state.current.name).toBe("other");
|
|
381
|
+
expect($state.params.id).toEqual("def");
|
|
398
382
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
383
|
+
$rootScope.$index = "ghi";
|
|
384
|
+
$state.go("other.detail");
|
|
385
|
+
$rootScope.$digest();
|
|
402
386
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// scope.state = 'nostate';
|
|
406
|
-
// scope.$digest();
|
|
407
|
-
// expect(jqLite(template[0]).attr('href')).toBe('#/contacts');
|
|
408
|
-
// });
|
|
387
|
+
expect($state.current.name).toBe("other.detail");
|
|
388
|
+
expect($state.params.id).toEqual("def");
|
|
409
389
|
|
|
410
|
-
|
|
411
|
-
// scope.state = 'contacts.item';
|
|
412
|
-
// scope.params = { id: 10 };
|
|
413
|
-
// scope.$digest();
|
|
414
|
-
// expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
|
|
415
|
-
// });
|
|
390
|
+
expect(el.attr("href")).toBe("#/other/ghi/detail");
|
|
416
391
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
// scope.params = { id: 10 };
|
|
420
|
-
// scope.$digest();
|
|
421
|
-
// expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
|
|
392
|
+
browserTrigger(el, "click");
|
|
393
|
+
await wait(10);
|
|
422
394
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
// });
|
|
395
|
+
expect($state.current.name).toBe("other.detail");
|
|
396
|
+
expect($state.params.id).toEqual("ghi");
|
|
397
|
+
});
|
|
427
398
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
399
|
+
it("retains the old href if the new points to a non-state", () => {
|
|
400
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts");
|
|
401
|
+
scope.state = "nostate";
|
|
402
|
+
scope.$digest();
|
|
403
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts");
|
|
404
|
+
});
|
|
431
405
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
406
|
+
it("accepts param overrides", () => {
|
|
407
|
+
scope.state = "contacts.item";
|
|
408
|
+
scope.params = { id: 10 };
|
|
409
|
+
scope.$digest();
|
|
410
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/10");
|
|
411
|
+
});
|
|
438
412
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
413
|
+
it("accepts param overrides", () => {
|
|
414
|
+
scope.state = "contacts.item";
|
|
415
|
+
scope.params = { id: 10 };
|
|
416
|
+
scope.$digest();
|
|
417
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/10");
|
|
443
418
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
419
|
+
scope.params.id = 22;
|
|
420
|
+
scope.$digest();
|
|
421
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/22");
|
|
422
|
+
});
|
|
447
423
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
424
|
+
it("watches attributes", () => {
|
|
425
|
+
el = jqLite(
|
|
426
|
+
'<a ui-state="{{exprvar}}" ui-state-params="params">state</a>',
|
|
427
|
+
);
|
|
428
|
+
template = $compile(el)(scope);
|
|
429
|
+
|
|
430
|
+
scope.exprvar = "state1";
|
|
431
|
+
scope.state1 = "contacts.item";
|
|
432
|
+
scope.state2 = "other";
|
|
433
|
+
scope.params = { id: 10 };
|
|
434
|
+
scope.$digest();
|
|
435
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/10");
|
|
436
|
+
|
|
437
|
+
scope.exprvar = "state2";
|
|
438
|
+
scope.$digest();
|
|
439
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/other/10");
|
|
440
|
+
});
|
|
453
441
|
|
|
454
|
-
|
|
455
|
-
|
|
442
|
+
it("allows one-time-binding on ng1.3+", () => {
|
|
443
|
+
el = jqLite('<a ui-state="::state" ui-state-params="::params">state</a>');
|
|
456
444
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
445
|
+
scope.state = "contacts.item";
|
|
446
|
+
scope.params = { id: 10 };
|
|
447
|
+
template = $compile(el)(scope);
|
|
448
|
+
scope.$digest();
|
|
449
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/10");
|
|
461
450
|
|
|
462
|
-
|
|
463
|
-
|
|
451
|
+
scope.state = "other";
|
|
452
|
+
scope.params = { id: 22 };
|
|
464
453
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
// template = $compile(el)(scope);
|
|
469
|
-
// scope.$digest();
|
|
454
|
+
scope.$digest();
|
|
455
|
+
expect(jqLite(template[0]).attr("href")).toBe("#/contacts/10");
|
|
456
|
+
});
|
|
470
457
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
// });
|
|
458
|
+
it("accepts option overrides", async () => {
|
|
459
|
+
let transitionOptions;
|
|
474
460
|
|
|
475
|
-
|
|
476
|
-
|
|
461
|
+
el = jqLite('<a ui-state="state" ui-state-opts="opts">state</a>');
|
|
462
|
+
scope.state = "contacts";
|
|
463
|
+
scope.opts = { reload: true };
|
|
464
|
+
template = $compile(el)(scope);
|
|
465
|
+
scope.$digest();
|
|
477
466
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
467
|
+
spyOn($state, "go").and.callFake(function (state, params, options) {
|
|
468
|
+
transitionOptions = options;
|
|
469
|
+
});
|
|
481
470
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
// expect($state.current.name).toBe('top');
|
|
471
|
+
browserTrigger(template, "click");
|
|
472
|
+
await wait(10);
|
|
485
473
|
|
|
486
|
-
|
|
474
|
+
expect(transitionOptions.reload).toEqual(true);
|
|
475
|
+
expect(transitionOptions.absolute).toBeUndefined();
|
|
476
|
+
});
|
|
487
477
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
478
|
+
describe("option event", () => {
|
|
479
|
+
beforeEach(() => (window.location.hash = ""));
|
|
480
|
+
it("should bind click event by default", async () => {
|
|
481
|
+
expect($state.current.name).toBe("top");
|
|
491
482
|
|
|
492
|
-
|
|
493
|
-
// $timeout.flush();
|
|
483
|
+
el = jqLite('<a ui-state="state"></a>');
|
|
494
484
|
|
|
495
|
-
|
|
496
|
-
|
|
485
|
+
scope.state = "contacts";
|
|
486
|
+
$compile(el)(scope);
|
|
487
|
+
scope.$digest();
|
|
497
488
|
|
|
498
|
-
|
|
499
|
-
|
|
489
|
+
browserTrigger(el, "click");
|
|
490
|
+
await wait(10);
|
|
500
491
|
|
|
501
|
-
|
|
492
|
+
expect($state.current.name).toBe("contacts");
|
|
493
|
+
});
|
|
502
494
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
// scope.$digest();
|
|
495
|
+
it("should bind single HTML events", async () => {
|
|
496
|
+
expect($state.current.name).toEqual("top");
|
|
506
497
|
|
|
507
|
-
|
|
508
|
-
|
|
498
|
+
el = jqLite(
|
|
499
|
+
'<input type="text" ui-state="state" ui-state-opts="{ events: [\'change\'] }">',
|
|
500
|
+
);
|
|
509
501
|
|
|
510
|
-
|
|
511
|
-
|
|
502
|
+
scope.state = "contacts";
|
|
503
|
+
$compile(el)(scope);
|
|
504
|
+
scope.$digest();
|
|
512
505
|
|
|
513
|
-
|
|
514
|
-
|
|
506
|
+
browserTrigger(el, "change");
|
|
507
|
+
await wait(10);
|
|
515
508
|
|
|
516
|
-
|
|
509
|
+
expect($state.current.name).toEqual("contacts");
|
|
510
|
+
});
|
|
517
511
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
// scope.$digest();
|
|
512
|
+
it("should bind multiple HTML events", async () => {
|
|
513
|
+
expect($state.current.name).toEqual("top");
|
|
521
514
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
515
|
+
el = jqLite(
|
|
516
|
+
'<input type="text" ui-state="state" ui-state-opts="{ events: [\'change\', \'blur\'] }">',
|
|
517
|
+
);
|
|
525
518
|
|
|
526
|
-
|
|
527
|
-
|
|
519
|
+
scope.state = "contacts";
|
|
520
|
+
$compile(el)(scope);
|
|
521
|
+
scope.$digest();
|
|
528
522
|
|
|
529
|
-
|
|
523
|
+
browserTrigger(el, "change");
|
|
524
|
+
await wait(10);
|
|
525
|
+
expect($state.current.name).toEqual("contacts");
|
|
530
526
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
// expect($state.current.name).toEqual('contacts');
|
|
534
|
-
// });
|
|
527
|
+
$state.go("top");
|
|
528
|
+
scope.$digest();
|
|
535
529
|
|
|
536
|
-
|
|
537
|
-
// expect($state.current.name).toEqual('top');
|
|
530
|
+
expect($state.current.name).toEqual("top");
|
|
538
531
|
|
|
539
|
-
|
|
532
|
+
browserTrigger(el, "blur");
|
|
533
|
+
await wait(10);
|
|
540
534
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
// scope.$digest();
|
|
535
|
+
expect($state.current.name).toEqual("contacts");
|
|
536
|
+
});
|
|
544
537
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
// expect($state.current.name).toEqual('contacts');
|
|
538
|
+
it("should bind multiple Mouse events", async () => {
|
|
539
|
+
expect($state.current.name).toEqual("top");
|
|
548
540
|
|
|
549
|
-
|
|
550
|
-
|
|
541
|
+
el = jqLite(
|
|
542
|
+
"<a ui-state=\"state\" ui-state-opts=\"{ events: ['mouseover', 'mousedown'] }\">",
|
|
543
|
+
);
|
|
551
544
|
|
|
552
|
-
|
|
545
|
+
scope.state = "contacts";
|
|
546
|
+
$compile(el)(scope);
|
|
547
|
+
scope.$digest();
|
|
553
548
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
// });
|
|
558
|
-
// });
|
|
559
|
-
// });
|
|
549
|
+
browserTrigger(el, "mouseover");
|
|
550
|
+
await wait(10);
|
|
551
|
+
expect($state.current.name).toEqual("contacts");
|
|
560
552
|
|
|
561
|
-
|
|
562
|
-
|
|
553
|
+
$state.go("top");
|
|
554
|
+
scope.$digest();
|
|
563
555
|
|
|
564
|
-
|
|
565
|
-
// el = angular.element('<form ui-sref="contacts.item.detail({ id: contact.id })"></form>');
|
|
566
|
-
// scope = $rootScope;
|
|
567
|
-
// scope.contact = { id: 5 };
|
|
568
|
-
// scope.$apply();
|
|
556
|
+
expect($state.current.name).toEqual("top");
|
|
569
557
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
558
|
+
browserTrigger(el, "mousedown");
|
|
559
|
+
await wait(10);
|
|
560
|
+
expect($state.current.name).toEqual("contacts");
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
});
|
|
573
564
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
// });
|
|
577
|
-
// });
|
|
565
|
+
describe("forms", () => {
|
|
566
|
+
let el, scope;
|
|
578
567
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
568
|
+
beforeEach(() => {
|
|
569
|
+
el = jqLite(
|
|
570
|
+
'<form ui-sref="contacts.item.detail({ id: contact.id })"></form>',
|
|
571
|
+
);
|
|
572
|
+
scope = $rootScope;
|
|
573
|
+
scope.contact = { id: 5 };
|
|
574
|
+
scope.$apply();
|
|
585
575
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
// });
|
|
576
|
+
$compile(el)(scope);
|
|
577
|
+
scope.$digest();
|
|
578
|
+
});
|
|
590
579
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
580
|
+
it("should generate the correct action", () => {
|
|
581
|
+
expect(el.attr("action")).toBe("#/contacts/5");
|
|
582
|
+
});
|
|
583
|
+
});
|
|
595
584
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
585
|
+
describe("relative transitions", () => {
|
|
586
|
+
beforeEach(() => {
|
|
587
|
+
$state.transitionTo("contacts.item", { id: 5 });
|
|
588
|
+
el = jqLite('<a ui-sref=".detail">Details</a>');
|
|
589
|
+
scope = $rootScope;
|
|
590
|
+
scope.$apply();
|
|
599
591
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
592
|
+
$compile(el)(scope);
|
|
593
|
+
template = $compile(jqLite("<div><ui-view></ui-view><div>"))(scope);
|
|
594
|
+
scope.$digest();
|
|
595
|
+
});
|
|
603
596
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
// $q.flush();
|
|
608
|
-
// expect($state.$current.name).toBe('contacts.item');
|
|
597
|
+
it("should work", async () => {
|
|
598
|
+
browserTrigger(el, "click");
|
|
599
|
+
await wait(10);
|
|
609
600
|
|
|
610
|
-
|
|
611
|
-
|
|
601
|
+
expect($state.$current.name).toBe("contacts.item.detail");
|
|
602
|
+
expect($state.params.id).toEqual(5);
|
|
603
|
+
});
|
|
612
604
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
// $q.flush();
|
|
605
|
+
it("should resolve states from parent uiView", async () => {
|
|
606
|
+
$state.transitionTo("contacts");
|
|
616
607
|
|
|
617
|
-
|
|
618
|
-
|
|
608
|
+
const parentToChild = jqLite(template[0].querySelector("a.item"));
|
|
609
|
+
browserTrigger(parentToChild, "click");
|
|
610
|
+
await wait(10);
|
|
619
611
|
|
|
620
|
-
|
|
621
|
-
// $timeout.flush();
|
|
622
|
-
// $q.flush();
|
|
623
|
-
// expect($state.$current.name).toBe('contacts.item');
|
|
612
|
+
expect($state.$current.name).toBe("contacts.item");
|
|
624
613
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
// expect($state.$current.name).toBe('contacts');
|
|
630
|
-
// });
|
|
631
|
-
// });
|
|
614
|
+
const childToGrandchild = jqLite(
|
|
615
|
+
template[0].querySelector("a.item-detail"),
|
|
616
|
+
);
|
|
617
|
+
const childToParent = jqLite(template[0].querySelector("a.item-parent"));
|
|
632
618
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
// el = angular.element('<a ui-sref="contacts"></a>');
|
|
636
|
-
// $compile(el)($rootScope);
|
|
637
|
-
// $rootScope.$digest();
|
|
619
|
+
browserTrigger(childToGrandchild, "click");
|
|
620
|
+
await wait(10);
|
|
638
621
|
|
|
639
|
-
|
|
622
|
+
const grandchildToParent = jqLite(
|
|
623
|
+
template[0].querySelector("a.item-parent2"),
|
|
624
|
+
);
|
|
625
|
+
expect($state.$current.name).toBe("contacts.item.detail");
|
|
640
626
|
|
|
641
|
-
|
|
642
|
-
|
|
627
|
+
browserTrigger(grandchildToParent, "click");
|
|
628
|
+
await wait(10);
|
|
643
629
|
|
|
644
|
-
|
|
645
|
-
// });
|
|
630
|
+
expect($state.$current.name).toBe("contacts.item");
|
|
646
631
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
632
|
+
$state.transitionTo("contacts.item.detail", { id: 3 });
|
|
633
|
+
browserTrigger(childToParent, "click");
|
|
634
|
+
await wait(10);
|
|
635
|
+
expect($state.$current.name).toBe("contacts");
|
|
636
|
+
});
|
|
637
|
+
});
|
|
651
638
|
|
|
652
|
-
|
|
639
|
+
describe("option event", () => {
|
|
640
|
+
beforeEach(() => (window.location.hash = ""));
|
|
641
|
+
it("should bind click event by default", async () => {
|
|
642
|
+
el = jqLite('<a ui-sref="contacts"></a>');
|
|
643
|
+
$compile(el)($rootScope);
|
|
644
|
+
$rootScope.$digest();
|
|
653
645
|
|
|
654
|
-
|
|
655
|
-
// $timeout.flush();
|
|
646
|
+
expect($state.current.name).toEqual("top");
|
|
656
647
|
|
|
657
|
-
|
|
658
|
-
|
|
648
|
+
browserTrigger(el, "click");
|
|
649
|
+
await wait(10);
|
|
659
650
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
// $compile(el)($rootScope);
|
|
663
|
-
// $rootScope.$digest();
|
|
651
|
+
expect($state.current.name).toEqual("contacts");
|
|
652
|
+
});
|
|
664
653
|
|
|
665
|
-
|
|
654
|
+
it("should bind single HTML events", async () => {
|
|
655
|
+
el = jqLite(
|
|
656
|
+
'<input type="text" ui-sref="contacts" ui-sref-opts="{ events: [\'change\'] }">',
|
|
657
|
+
);
|
|
658
|
+
$compile(el)($rootScope);
|
|
659
|
+
$rootScope.$digest();
|
|
666
660
|
|
|
667
|
-
|
|
668
|
-
// $timeout.flush();
|
|
669
|
-
// expect($state.current.name).toEqual('contacts');
|
|
661
|
+
expect($state.current.name).toEqual("top");
|
|
670
662
|
|
|
671
|
-
|
|
672
|
-
|
|
663
|
+
browserTrigger(el, "change");
|
|
664
|
+
await wait(10);
|
|
673
665
|
|
|
674
|
-
|
|
666
|
+
expect($state.current.name).toEqual("contacts");
|
|
667
|
+
});
|
|
675
668
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
669
|
+
it("should bind multiple HTML events", async () => {
|
|
670
|
+
el = jqLite(
|
|
671
|
+
'<input type="text" ui-sref="contacts" ui-sref-opts="{ events: [\'change\', \'blur\'] }">',
|
|
672
|
+
);
|
|
673
|
+
$compile(el)($rootScope);
|
|
674
|
+
$rootScope.$digest();
|
|
680
675
|
|
|
681
|
-
|
|
682
|
-
// el = angular.element('<a ui-sref="contacts" ui-sref-opts="{ events: [\'mouseover\', \'mousedown\'] }">');
|
|
683
|
-
// $compile(el)($rootScope);
|
|
684
|
-
// $rootScope.$digest();
|
|
676
|
+
expect($state.current.name).toEqual("top");
|
|
685
677
|
|
|
686
|
-
|
|
678
|
+
browserTrigger(el, "change");
|
|
679
|
+
await wait(10);
|
|
680
|
+
expect($state.current.name).toEqual("contacts");
|
|
687
681
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
// expect($state.current.name).toEqual('contacts');
|
|
682
|
+
$state.go("top");
|
|
683
|
+
$rootScope.$digest();
|
|
691
684
|
|
|
692
|
-
|
|
693
|
-
// $rootScope.$digest();
|
|
685
|
+
expect($state.current.name).toEqual("top");
|
|
694
686
|
|
|
695
|
-
|
|
687
|
+
browserTrigger(el, "blur");
|
|
688
|
+
await wait(10);
|
|
689
|
+
expect($state.current.name).toEqual("contacts");
|
|
690
|
+
});
|
|
696
691
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
692
|
+
it("should bind multiple Mouse events", async () => {
|
|
693
|
+
el = jqLite(
|
|
694
|
+
"<a ui-sref=\"contacts\" ui-sref-opts=\"{ events: ['mouseover', 'mousedown'] }\">",
|
|
695
|
+
);
|
|
696
|
+
$compile(el)($rootScope);
|
|
697
|
+
$rootScope.$digest();
|
|
698
|
+
|
|
699
|
+
expect($state.current.name).toEqual("top");
|
|
700
|
+
|
|
701
|
+
browserTrigger(el, "mouseover");
|
|
702
|
+
await wait(10);
|
|
703
|
+
expect($state.current.name).toEqual("contacts");
|
|
704
|
+
|
|
705
|
+
$state.go("top");
|
|
706
|
+
$rootScope.$digest();
|
|
707
|
+
|
|
708
|
+
expect($state.current.name).toEqual("top");
|
|
709
|
+
|
|
710
|
+
browserTrigger(el, "mousedown");
|
|
711
|
+
await wait(10);
|
|
712
|
+
expect($state.current.name).toEqual("contacts");
|
|
713
|
+
});
|
|
714
|
+
});
|
|
702
715
|
});
|
|
703
716
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
//
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
//
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
//
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
//
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
// const child = el[0].querySelector('a');
|
|
1171
|
-
// expect(child.className).toMatch(/active/);
|
|
1172
|
-
// });
|
|
1173
|
-
|
|
1174
|
-
// it('should match on state parameters', async () => {
|
|
1175
|
-
// el = $compile('<div ui-sref-active="{active: [\'admin.roles({page: 1})\']}"></div>')($rootScope);
|
|
1176
|
-
// $state.transitionTo('admin.roles', { page: 1 });
|
|
1177
|
-
// $q.flush();
|
|
1178
|
-
// timeoutFlush();
|
|
1179
|
-
// expect(el[0].className).toMatch(/active/);
|
|
1180
|
-
// });
|
|
1181
|
-
|
|
1182
|
-
// it('should support multiple <className, stateOrName> pairs', async () => {
|
|
1183
|
-
// el = $compile(
|
|
1184
|
-
// "<div ui-sref-active=\"{contacts: ['contacts.item', 'contacts.item.detail'], admin: 'admin.roles({page: 1})'}\"></div>"
|
|
1185
|
-
// )($rootScope);
|
|
1186
|
-
// $state.transitionTo('contacts.item.detail', { id: 1, foo: 'bar' });
|
|
1187
|
-
// $q.flush();
|
|
1188
|
-
// timeoutFlush();
|
|
1189
|
-
// expect(el[0].className).toMatch(/contacts/);
|
|
1190
|
-
// expect(el[0].className).not.toMatch(/admin/);
|
|
1191
|
-
// $state.transitionTo('admin.roles', { page: 1 });
|
|
1192
|
-
// $q.flush();
|
|
1193
|
-
// timeoutFlush();
|
|
1194
|
-
// expect(el[0].className).toMatch(/admin/);
|
|
1195
|
-
// expect(el[0].className).not.toMatch(/contacts/);
|
|
1196
|
-
// });
|
|
1197
|
-
|
|
1198
|
-
// it('should update the active classes when compiled', inject(function ($compile, $rootScope, $document, $state, $q) {
|
|
1199
|
-
// $state.transitionTo('admin.roles');
|
|
1200
|
-
// $q.flush();
|
|
1201
|
-
// timeoutFlush();
|
|
1202
|
-
// el = $compile("<div ui-sref-active=\"{active: ['admin.roles', 'admin.someOtherState']}\"/>")($rootScope);
|
|
1203
|
-
// $rootScope.$digest();
|
|
1204
|
-
// timeoutFlush();
|
|
1205
|
-
// expect(el.hasClass('active')).toBeTruthy();
|
|
1206
|
-
// });
|
|
1207
|
-
// });
|
|
1208
|
-
// });
|
|
717
|
+
describe("uiSrefActive", () => {
|
|
718
|
+
window.location.hash = "#!";
|
|
719
|
+
let el,
|
|
720
|
+
el2,
|
|
721
|
+
template,
|
|
722
|
+
scope,
|
|
723
|
+
_locationProvider,
|
|
724
|
+
$rootScope,
|
|
725
|
+
$compile,
|
|
726
|
+
$q,
|
|
727
|
+
$injector,
|
|
728
|
+
$timeout,
|
|
729
|
+
$state,
|
|
730
|
+
$stateParams,
|
|
731
|
+
_stateProvider;
|
|
732
|
+
|
|
733
|
+
beforeEach(() => {
|
|
734
|
+
window.location.hash = "#!";
|
|
735
|
+
window.angular = new Angular();
|
|
736
|
+
publishExternalAPI();
|
|
737
|
+
let module = window.angular.module("defaultModule", ["ui.router"]);
|
|
738
|
+
module.config(function ($stateProvider) {
|
|
739
|
+
_stateProvider = $stateProvider;
|
|
740
|
+
$stateProvider
|
|
741
|
+
.state({ name: "top", url: "" })
|
|
742
|
+
.state({
|
|
743
|
+
name: "contacts",
|
|
744
|
+
url: "/contacts",
|
|
745
|
+
views: {
|
|
746
|
+
$default: {
|
|
747
|
+
template:
|
|
748
|
+
'<a ui-sref=".item({ id: 6 })" ui-sref-active="active">Contacts</a>',
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
})
|
|
752
|
+
.state({ name: "contacts.item", url: "/:id" })
|
|
753
|
+
.state({ name: "contacts.item.detail", url: "/detail/:foo" })
|
|
754
|
+
.state({ name: "contacts.item.edit", url: "/edit" })
|
|
755
|
+
.state({
|
|
756
|
+
name: "admin",
|
|
757
|
+
url: "/admin",
|
|
758
|
+
abstract: true,
|
|
759
|
+
template: "<ui-view/>",
|
|
760
|
+
})
|
|
761
|
+
.state({ name: "admin.roles", url: "/roles?page" })
|
|
762
|
+
.state({
|
|
763
|
+
name: "arrayparam",
|
|
764
|
+
url: "/arrayparam?{foo:int}&bar",
|
|
765
|
+
template: "<div></div>",
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
$injector = window.angular.bootstrap(document.getElementById("dummy"), [
|
|
769
|
+
"defaultModule",
|
|
770
|
+
]);
|
|
771
|
+
$q = $injector.get("$q");
|
|
772
|
+
$rootScope = $injector.get("$rootScope");
|
|
773
|
+
$compile = $injector.get("$compile");
|
|
774
|
+
$timeout = $injector.get("$timeout");
|
|
775
|
+
$state = $injector.get("$state");
|
|
776
|
+
$stateParams = $injector.get("$stateParams");
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it("should update class for sibling uiSref", async () => {
|
|
780
|
+
el = jqLite(
|
|
781
|
+
'<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active">Contacts</a><a ui-sref="contacts.item({ id: 2 })" ui-sref-active="active">Contacts</a></div>',
|
|
782
|
+
);
|
|
783
|
+
template = $compile(el)($rootScope);
|
|
784
|
+
$rootScope.$digest();
|
|
785
|
+
|
|
786
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
787
|
+
$state.transitionTo("contacts.item", { id: 1 });
|
|
788
|
+
await wait(10);
|
|
789
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
790
|
+
|
|
791
|
+
$state.transitionTo("contacts.item", { id: 2 });
|
|
792
|
+
await wait(10);
|
|
793
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
it("should match state's parameters", async () => {
|
|
797
|
+
el = jqLite(
|
|
798
|
+
'<div><a ui-sref="contacts.item.detail({ foo: \'bar\' })" ui-sref-active="active">Contacts</a></div>',
|
|
799
|
+
);
|
|
800
|
+
template = $compile(el)($rootScope);
|
|
801
|
+
$rootScope.$digest();
|
|
802
|
+
|
|
803
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
804
|
+
$state.transitionTo("contacts.item.detail", { id: 5, foo: "bar" });
|
|
805
|
+
await wait(10);
|
|
806
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
807
|
+
|
|
808
|
+
$state.transitionTo("contacts.item.detail", { id: 5, foo: "baz" });
|
|
809
|
+
await wait(10);
|
|
810
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
// Test for #2696
|
|
814
|
+
it("should compare using typed parameters", async () => {
|
|
815
|
+
el = jqLite(
|
|
816
|
+
'<div><a ui-sref="arrayparam({ foo: [1,2,3] })" ui-sref-active="active">foo 123</a></div>',
|
|
817
|
+
);
|
|
818
|
+
template = $compile(el)($rootScope);
|
|
819
|
+
$rootScope.$digest();
|
|
820
|
+
|
|
821
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
822
|
+
|
|
823
|
+
$state.transitionTo("arrayparam", { foo: [1, 2, 3] });
|
|
824
|
+
await wait(10);
|
|
825
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
826
|
+
|
|
827
|
+
$state.transitionTo("arrayparam", { foo: [1, 2, 3], bar: "asdf" });
|
|
828
|
+
await wait(10);
|
|
829
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
830
|
+
|
|
831
|
+
$state.transitionTo("arrayparam", { foo: [1, 2] });
|
|
832
|
+
await wait(10);
|
|
833
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// Test for #3154
|
|
837
|
+
it("should compare ui-sref-active-eq using typed parameters", async () => {
|
|
838
|
+
el = jqLite(
|
|
839
|
+
'<div><a ui-sref="arrayparam({ foo: [1,2,3] })" ui-sref-active-eq="active">foo 123</a></div>',
|
|
840
|
+
);
|
|
841
|
+
template = $compile(el)($rootScope);
|
|
842
|
+
$rootScope.$digest();
|
|
843
|
+
|
|
844
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
845
|
+
|
|
846
|
+
$state.transitionTo("arrayparam", { foo: [1, 2, 3] });
|
|
847
|
+
await wait(10);
|
|
848
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
849
|
+
|
|
850
|
+
$state.transitionTo("arrayparam", { foo: [1, 2, 3], bar: "asdf" });
|
|
851
|
+
await wait(10);
|
|
852
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
853
|
+
|
|
854
|
+
$state.transitionTo("arrayparam", { foo: [1, 2] });
|
|
855
|
+
await wait(10);
|
|
856
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
it("should update in response to ui-sref param expression changes", async () => {
|
|
860
|
+
el = jqLite(
|
|
861
|
+
'<div><a ui-sref="contacts.item.detail({ foo: fooId })" ui-sref-active="active">Contacts</a></div>',
|
|
862
|
+
);
|
|
863
|
+
template = $compile(el)($rootScope);
|
|
864
|
+
$rootScope.fooId = "bar";
|
|
865
|
+
$rootScope.$digest();
|
|
866
|
+
|
|
867
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
868
|
+
$state.transitionTo("contacts.item.detail", { id: 5, foo: "bar" });
|
|
869
|
+
await wait(10);
|
|
870
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
871
|
+
|
|
872
|
+
$rootScope.fooId = "baz";
|
|
873
|
+
$rootScope.$digest();
|
|
874
|
+
await wait(10);
|
|
875
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
it("should match on child states", async () => {
|
|
879
|
+
template = $compile(
|
|
880
|
+
'<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active">Contacts</a></div>',
|
|
881
|
+
)($rootScope);
|
|
882
|
+
$rootScope.$digest();
|
|
883
|
+
const a = jqLite(template[0].getElementsByTagName("a")[0]);
|
|
884
|
+
|
|
885
|
+
$state.transitionTo("contacts.item.edit", { id: 1 });
|
|
886
|
+
await wait(10);
|
|
887
|
+
expect($state.params.id).toBe("1");
|
|
888
|
+
expect(a.attr("class")).toMatch(/active/);
|
|
889
|
+
|
|
890
|
+
$state.transitionTo("contacts.item.edit", { id: 4 });
|
|
891
|
+
await wait(10);
|
|
892
|
+
expect($state.params.id).toBe("4");
|
|
893
|
+
expect(a.attr("class")).not.toMatch(/active/);
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
it("should NOT match on child states when active-equals is used", async () => {
|
|
897
|
+
template = $compile(
|
|
898
|
+
'<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active-eq="active">Contacts</a></div>',
|
|
899
|
+
)($rootScope);
|
|
900
|
+
$rootScope.$digest();
|
|
901
|
+
const a = jqLite(template[0].getElementsByTagName("a")[0]);
|
|
902
|
+
|
|
903
|
+
$state.transitionTo("contacts.item", { id: 1 });
|
|
904
|
+
await wait(10);
|
|
905
|
+
expect(a.attr("class")).toMatch(/active/);
|
|
906
|
+
|
|
907
|
+
$state.transitionTo("contacts.item.edit", { id: 1 });
|
|
908
|
+
await wait(10);
|
|
909
|
+
expect(a.attr("class")).not.toMatch(/active/);
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
it("should match on child states when active-equals and active-equals-eq is used", async () => {
|
|
913
|
+
template = $compile(
|
|
914
|
+
'<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active" ui-sref-active-eq="active-eq">Contacts</a></div>',
|
|
915
|
+
)($rootScope);
|
|
916
|
+
$rootScope.$digest();
|
|
917
|
+
const a = jqLite(template[0].getElementsByTagName("a")[0]);
|
|
918
|
+
|
|
919
|
+
$state.transitionTo("contacts.item", { id: 1 });
|
|
920
|
+
await wait(10);
|
|
921
|
+
expect(a.attr("class")).toMatch(/active/);
|
|
922
|
+
expect(a.attr("class")).toMatch(/active-eq/);
|
|
923
|
+
|
|
924
|
+
$state.transitionTo("contacts.item.edit", { id: 1 });
|
|
925
|
+
await wait(10);
|
|
926
|
+
expect(a.attr("class")).toMatch(/active/);
|
|
927
|
+
expect(a.attr("class")).not.toMatch(/active-eq/);
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
it("should resolve relative state refs", async () => {
|
|
931
|
+
el = jqLite("<section><div ui-view></div></section>");
|
|
932
|
+
template = $compile(el)($rootScope);
|
|
933
|
+
$rootScope.$digest();
|
|
934
|
+
|
|
935
|
+
$state.transitionTo("contacts");
|
|
936
|
+
await wait(10);
|
|
937
|
+
expect(
|
|
938
|
+
jqLite(template[0].querySelector("a")).attr("class"),
|
|
939
|
+
).toBeUndefined();
|
|
940
|
+
|
|
941
|
+
$state.transitionTo("contacts.item", { id: 6 });
|
|
942
|
+
await wait(10);
|
|
943
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
944
|
+
|
|
945
|
+
$state.transitionTo("contacts.item", { id: 5 });
|
|
946
|
+
await wait(10);
|
|
947
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("");
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
it("should match on any child state refs", async () => {
|
|
951
|
+
el = jqLite(
|
|
952
|
+
'<div ui-sref-active="active"><a ui-sref="contacts.item({ id: 1 })">Contacts</a><a ui-sref="contacts.item({ id: 2 })">Contacts</a></div>',
|
|
953
|
+
);
|
|
954
|
+
template = $compile(el)($rootScope);
|
|
955
|
+
$rootScope.$digest();
|
|
956
|
+
|
|
957
|
+
expect(jqLite(template[0]).attr("class")).toBeUndefined();
|
|
958
|
+
|
|
959
|
+
$state.transitionTo("contacts.item", { id: 1 });
|
|
960
|
+
await wait(10);
|
|
961
|
+
expect(jqLite(template[0]).attr("class")).toBe("active");
|
|
962
|
+
|
|
963
|
+
$state.transitionTo("contacts.item", { id: 2 });
|
|
964
|
+
await wait(10);
|
|
965
|
+
expect(jqLite(template[0]).attr("class")).toBe("active");
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
it("should match fuzzy on lazy loaded states", async () => {
|
|
969
|
+
el = jqLite(
|
|
970
|
+
'<div><a ui-sref="contacts.lazy" ui-sref-active="active">Lazy Contact</a></div>',
|
|
971
|
+
);
|
|
972
|
+
template = $compile(el)($rootScope);
|
|
973
|
+
await wait(10);
|
|
974
|
+
|
|
975
|
+
_stateProvider.onInvalid(function ($to$) {
|
|
976
|
+
if ($to$.name() === "contacts.lazy") {
|
|
977
|
+
_stateProvider.state({ name: "contacts.lazy" });
|
|
978
|
+
return $to$;
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
$state.transitionTo("contacts.item", { id: 1 });
|
|
983
|
+
await wait(10);
|
|
984
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
985
|
+
|
|
986
|
+
$state.transitionTo("contacts.lazy");
|
|
987
|
+
await wait(10);
|
|
988
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
it("should match exactly on lazy loaded states", async () => {
|
|
992
|
+
el = jqLite(
|
|
993
|
+
'<div><a ui-sref="contacts.lazy" ui-sref-active-eq="active">Lazy Contact</a></div>',
|
|
994
|
+
);
|
|
995
|
+
template = $compile(el)($rootScope);
|
|
996
|
+
await wait(10);
|
|
997
|
+
|
|
998
|
+
_stateProvider.onInvalid(function ($to$) {
|
|
999
|
+
if ($to$.name() === "contacts.lazy") {
|
|
1000
|
+
_stateProvider.state({ name: "contacts.lazy" });
|
|
1001
|
+
return $to$;
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
$state.transitionTo("contacts.item", { id: 1 });
|
|
1006
|
+
await wait(10);
|
|
1007
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBeFalsy();
|
|
1008
|
+
|
|
1009
|
+
$state.transitionTo("contacts.lazy");
|
|
1010
|
+
await wait(10);
|
|
1011
|
+
expect(jqLite(template[0].querySelector("a")).attr("class")).toBe("active");
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
it("should allow multiple classes to be supplied", async () => {
|
|
1015
|
+
template = $compile(
|
|
1016
|
+
'<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active also-active">Contacts</a></div>',
|
|
1017
|
+
)($rootScope);
|
|
1018
|
+
$rootScope.$digest();
|
|
1019
|
+
const a = jqLite(template[0].getElementsByTagName("a")[0]);
|
|
1020
|
+
|
|
1021
|
+
$state.transitionTo("contacts.item.edit", { id: 1 });
|
|
1022
|
+
await wait(10);
|
|
1023
|
+
expect(a.attr("class")).toMatch(/active also-active/);
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
// TODO does not work
|
|
1027
|
+
xit("should not match fuzzy on lazy loaded future states", async () => {
|
|
1028
|
+
_stateProvider.state({
|
|
1029
|
+
name: "contacts.lazy.**",
|
|
1030
|
+
url: "/lazy",
|
|
1031
|
+
lazyLoad: () => {
|
|
1032
|
+
return $q.when().then(() => {
|
|
1033
|
+
_stateProvider
|
|
1034
|
+
.state({ name: "contacts.lazy", abstract: true, url: "/lazy" })
|
|
1035
|
+
.state({ name: "contacts.lazy.s1", url: "/s1" })
|
|
1036
|
+
.state({ name: "contacts.lazy.s2", url: "/s2" });
|
|
1037
|
+
});
|
|
1038
|
+
},
|
|
1039
|
+
});
|
|
1040
|
+
template = $compile(
|
|
1041
|
+
'<div ui-sref-active="active"><a ui-sref="contacts.lazy.s1">Lazy</a></div><div ui-sref-active="active"><a ui-sref="contacts.lazy.s2"></a></div>',
|
|
1042
|
+
)($rootScope);
|
|
1043
|
+
$rootScope.$digest();
|
|
1044
|
+
$state.transitionTo("contacts.lazy.s1");
|
|
1045
|
+
await wait(10);
|
|
1046
|
+
|
|
1047
|
+
expect(template.eq(0)[0].hasClass("active")).toBeTruthy();
|
|
1048
|
+
//expect(template.eq(1).hasClass("active")).toBeFalsy();
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
// TODO investigate why transitions error out
|
|
1052
|
+
xdescribe("ng-{class,style} interface", () => {
|
|
1053
|
+
it("should match on abstract states that are included by the current state", async () => {
|
|
1054
|
+
el = $compile(
|
|
1055
|
+
'<div ui-sref-active="{active: \'admin.*\'}"><a ui-sref-active="active" ui-sref="admin.roles">Roles</a></div>',
|
|
1056
|
+
)($rootScope);
|
|
1057
|
+
$state.transitionTo("admin.roles");
|
|
1058
|
+
await wait(10);
|
|
1059
|
+
const abstractParent = el[0];
|
|
1060
|
+
expect(abstractParent.className).toMatch(/active/);
|
|
1061
|
+
const child = el[0].querySelector("a");
|
|
1062
|
+
expect(child.className).toMatch(/active/);
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
it("should match on state parameters", async () => {
|
|
1066
|
+
el = $compile(
|
|
1067
|
+
"<div ui-sref-active=\"{active: 'admin.roles({page: 1})'}\"></div>",
|
|
1068
|
+
)($rootScope);
|
|
1069
|
+
$state.transitionTo("admin.roles", { page: 1 });
|
|
1070
|
+
await wait(10);
|
|
1071
|
+
expect(el[0].className).toMatch(/active/);
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
it("should shadow the state provided by ui-sref", async () => {
|
|
1075
|
+
el = $compile(
|
|
1076
|
+
'<div ui-sref-active="{active: \'admin.roles({page: 1})\'}"><a ui-sref="admin.roles"></a></div>',
|
|
1077
|
+
)($rootScope);
|
|
1078
|
+
$state.transitionTo("admin.roles");
|
|
1079
|
+
await wait(10);
|
|
1080
|
+
expect(el[0].className).not.toMatch(/active/);
|
|
1081
|
+
$state.transitionTo("admin.roles", { page: 1 });
|
|
1082
|
+
await wait(10);
|
|
1083
|
+
expect(el[0].className).toMatch(/active/);
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
it("should support multiple <className, stateOrName> pairs", async () => {
|
|
1087
|
+
el = $compile(
|
|
1088
|
+
"<div ui-sref-active=\"{contacts: 'contacts.**', admin: 'admin.roles({page: 1})'}\"></div>",
|
|
1089
|
+
)($rootScope);
|
|
1090
|
+
$state.transitionTo("contacts");
|
|
1091
|
+
await wait(10);
|
|
1092
|
+
expect(el[0].className).toMatch(/contacts/);
|
|
1093
|
+
expect(el[0].className).not.toMatch(/admin/);
|
|
1094
|
+
$state.transitionTo("admin.roles", { page: 1 });
|
|
1095
|
+
await wait(10);
|
|
1096
|
+
expect(el[0].className).toMatch(/admin/);
|
|
1097
|
+
expect(el[0].className).not.toMatch(/contacts/);
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
it("should update the active classes when compiled", async () => {
|
|
1101
|
+
$state.transitionTo("admin.roles");
|
|
1102
|
+
await wait(10);
|
|
1103
|
+
el = $compile("<div ui-sref-active=\"{active: 'admin.roles'}\"/>")(
|
|
1104
|
+
$rootScope,
|
|
1105
|
+
);
|
|
1106
|
+
$rootScope.$digest();
|
|
1107
|
+
timeoutFlush();
|
|
1108
|
+
expect(el.hasClass("active")).toBeTruthy();
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
it("should not match fuzzy on lazy loaded future states", async () => {
|
|
1112
|
+
_stateProvider.state({
|
|
1113
|
+
name: "contacts.lazy.**",
|
|
1114
|
+
url: "/lazy",
|
|
1115
|
+
lazyLoad: () => {
|
|
1116
|
+
return $q.when().then(() => {
|
|
1117
|
+
_stateProvider
|
|
1118
|
+
.state({ name: "contacts.lazy", abstract: true, url: "/lazy" })
|
|
1119
|
+
.state({ name: "contacts.lazy.s1", url: "/s1" })
|
|
1120
|
+
.state({ name: "contacts.lazy.s2", url: "/s2" });
|
|
1121
|
+
});
|
|
1122
|
+
},
|
|
1123
|
+
});
|
|
1124
|
+
template = $compile(
|
|
1125
|
+
'<div ui-sref-active="{ active: \'contacts.lazy.s1\' }"><a ui-sref="contacts.lazy.s1">Lazy</a></div><div ui-sref-active="{ active: \'contacts.lazy.s2\' }"></div>',
|
|
1126
|
+
)($rootScope);
|
|
1127
|
+
$rootScope.$digest();
|
|
1128
|
+
$state.transitionTo("contacts.lazy.s1");
|
|
1129
|
+
await wait(10);
|
|
1130
|
+
expect(template.eq(0).hasClass("active")).toBeTruthy();
|
|
1131
|
+
expect(template.eq(1).hasClass("active")).toBeFalsy();
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
xdescribe("ng-{class,style} interface, and handle values as arrays", () => {
|
|
1136
|
+
it("should match on abstract states that are included by the current state", async () => {
|
|
1137
|
+
el = $compile(
|
|
1138
|
+
'<div ui-sref-active="{active: [\'randomState.**\', \'admin.roles\']}"><a ui-sref-active="active" ui-sref="admin.roles">Roles</a></div>',
|
|
1139
|
+
)($rootScope);
|
|
1140
|
+
$state.transitionTo("admin.roles");
|
|
1141
|
+
await wait(10);
|
|
1142
|
+
const abstractParent = el[0];
|
|
1143
|
+
expect(abstractParent.className).toMatch(/active/);
|
|
1144
|
+
const child = el[0].querySelector("a");
|
|
1145
|
+
expect(child.className).toMatch(/active/);
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
it("should match on state parameters", async () => {
|
|
1149
|
+
el = $compile(
|
|
1150
|
+
"<div ui-sref-active=\"{active: ['admin.roles({page: 1})']}\"></div>",
|
|
1151
|
+
)($rootScope);
|
|
1152
|
+
$state.transitionTo("admin.roles", { page: 1 });
|
|
1153
|
+
await wait(10);
|
|
1154
|
+
expect(el[0].className).toMatch(/active/);
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
it("should support multiple <className, stateOrName> pairs", async () => {
|
|
1158
|
+
el = $compile(
|
|
1159
|
+
"<div ui-sref-active=\"{contacts: ['contacts.item', 'contacts.item.detail'], admin: 'admin.roles({page: 1})'}\"></div>",
|
|
1160
|
+
)($rootScope);
|
|
1161
|
+
$state.transitionTo("contacts.item.detail", { id: 1, foo: "bar" });
|
|
1162
|
+
await wait(10);
|
|
1163
|
+
expect(el[0].className).toMatch(/contacts/);
|
|
1164
|
+
expect(el[0].className).not.toMatch(/admin/);
|
|
1165
|
+
$state.transitionTo("admin.roles", { page: 1 });
|
|
1166
|
+
await wait(10);
|
|
1167
|
+
expect(el[0].className).toMatch(/admin/);
|
|
1168
|
+
expect(el[0].className).not.toMatch(/contacts/);
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
it("should update the active classes when compiled", async () => {
|
|
1172
|
+
$state.transitionTo("admin.roles");
|
|
1173
|
+
await wait(10);
|
|
1174
|
+
el = $compile(
|
|
1175
|
+
"<div ui-sref-active=\"{active: ['admin.roles', 'admin.someOtherState']}\"/>",
|
|
1176
|
+
)($rootScope);
|
|
1177
|
+
$rootScope.$digest();
|
|
1178
|
+
timeoutFlush();
|
|
1179
|
+
expect(el.hasClass("active")).toBeTruthy();
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
1182
|
+
});
|