@angular-wave/angular.ts 0.0.20 → 0.0.22

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.
Files changed (128) hide show
  1. package/Makefile +1 -1
  2. package/README.md +3 -3
  3. package/TODO.md +14 -0
  4. package/dist/angular-ts.esm.js +1 -1
  5. package/dist/angular-ts.umd.js +1 -1
  6. package/index.html +2 -1
  7. package/package.json +1 -1
  8. package/src/animations/animate-css-driver.js +2 -2
  9. package/src/animations/animate-css.js +15 -6
  10. package/src/animations/animate-js.js +1 -1
  11. package/src/animations/animate-queue.js +1 -1
  12. package/src/animations/shared.js +0 -14
  13. package/src/core/compile.js +6 -3
  14. package/src/core/q.js +9 -9
  15. package/src/core/sanitize-uri.js +1 -1
  16. package/src/core/sce.js +1 -1
  17. package/src/directive/if.js +0 -79
  18. package/src/directive/if.md +80 -0
  19. package/src/directive/include.js +0 -82
  20. package/src/directive/include.md +86 -0
  21. package/src/directive/repeat.js +0 -1
  22. package/src/loader.js +0 -1
  23. package/src/public.js +0 -2
  24. package/src/router/common/trace.js +1 -1
  25. package/src/router/directives/stateDirectives.js +16 -14
  26. package/src/router/directives/viewDirective.js +2 -2
  27. package/src/router/hooks/resolve.js +3 -4
  28. package/src/router/hooks/views.js +3 -2
  29. package/src/router/state/stateService.js +1 -2
  30. package/src/router/transition/interface.js +14 -14
  31. package/src/router/transition/rejectFactory.js +29 -20
  32. package/src/router/transition/transitionHook.js +5 -5
  33. package/src/router/url/urlMatcher.js +1 -2
  34. package/src/router/url/urlRule.js +1 -1
  35. package/src/router/url/urlRules.js +1 -1
  36. package/src/shared/common.js +0 -1
  37. package/test/module-test.html +44 -12
  38. package/test/router/services.spec.js +71 -0
  39. package/test/router/state-directives.spec.js +1208 -0
  40. package/types/angular.d.ts +132 -124
  41. package/types/index.d.ts +2350 -2187
  42. package/types/jqlite.d.ts +463 -418
  43. package/types/router/core/common/common.d.ts +70 -24
  44. package/types/router/core/common/coreservices.d.ts +30 -32
  45. package/types/router/core/common/glob.d.ts +9 -9
  46. package/types/router/core/common/hof.d.ts +12 -4
  47. package/types/router/core/common/index.d.ts +8 -8
  48. package/types/router/core/common/predicates.d.ts +1 -1
  49. package/types/router/core/common/queue.d.ts +13 -13
  50. package/types/router/core/common/safeConsole.d.ts +3 -3
  51. package/types/router/core/common/strings.d.ts +4 -2
  52. package/types/router/core/common/trace.d.ts +94 -82
  53. package/types/router/core/globals.d.ts +37 -37
  54. package/types/router/core/hooks/coreResolvables.d.ts +5 -3
  55. package/types/router/core/hooks/ignoredTransition.d.ts +4 -2
  56. package/types/router/core/hooks/invalidTransition.d.ts +4 -2
  57. package/types/router/core/hooks/lazyLoad.d.ts +10 -5
  58. package/types/router/core/hooks/onEnterExitRetain.d.ts +10 -4
  59. package/types/router/core/hooks/redirectTo.d.ts +4 -2
  60. package/types/router/core/hooks/resolve.d.ts +10 -4
  61. package/types/router/core/hooks/updateGlobals.d.ts +4 -2
  62. package/types/router/core/hooks/url.d.ts +4 -2
  63. package/types/router/core/hooks/views.d.ts +7 -3
  64. package/types/router/core/index.d.ts +11 -12
  65. package/types/router/core/interface.d.ts +83 -81
  66. package/types/router/core/params/index.d.ts +5 -5
  67. package/types/router/core/params/interface.d.ts +439 -439
  68. package/types/router/core/params/param.d.ts +72 -60
  69. package/types/router/core/params/paramType.d.ts +40 -40
  70. package/types/router/core/params/paramTypes.d.ts +169 -165
  71. package/types/router/core/params/stateParams.d.ts +13 -13
  72. package/types/router/core/path/index.d.ts +2 -2
  73. package/types/router/core/path/pathNode.d.ts +49 -49
  74. package/types/router/core/path/pathUtils.d.ts +100 -74
  75. package/types/router/core/resolve/index.d.ts +3 -3
  76. package/types/router/core/resolve/interface.d.ts +137 -137
  77. package/types/router/core/resolve/resolvable.d.ts +60 -54
  78. package/types/router/core/resolve/resolveContext.d.ts +84 -79
  79. package/types/router/core/router.d.ts +95 -86
  80. package/types/router/core/state/index.d.ts +8 -8
  81. package/types/router/core/state/interface.d.ts +667 -643
  82. package/types/router/core/state/stateBuilder.d.ts +41 -38
  83. package/types/router/core/state/stateMatcher.d.ts +11 -9
  84. package/types/router/core/state/stateObject.d.ts +154 -139
  85. package/types/router/core/state/stateQueueManager.d.ts +26 -21
  86. package/types/router/core/state/stateRegistry.d.ts +124 -121
  87. package/types/router/core/state/stateService.d.ts +380 -343
  88. package/types/router/core/state/targetState.d.ts +74 -69
  89. package/types/router/core/transition/hookBuilder.d.ts +34 -30
  90. package/types/router/core/transition/hookRegistry.d.ts +96 -74
  91. package/types/router/core/transition/index.d.ts +8 -8
  92. package/types/router/core/transition/interface.d.ts +652 -609
  93. package/types/router/core/transition/rejectFactory.d.ts +97 -97
  94. package/types/router/core/transition/transition.d.ts +565 -517
  95. package/types/router/core/transition/transitionEventType.d.ts +20 -11
  96. package/types/router/core/transition/transitionHook.d.ts +90 -82
  97. package/types/router/core/transition/transitionService.d.ts +228 -161
  98. package/types/router/core/url/index.d.ts +8 -8
  99. package/types/router/core/url/interface.d.ts +100 -87
  100. package/types/router/core/url/urlConfig.d.ts +130 -126
  101. package/types/router/core/url/urlMatcher.d.ts +132 -127
  102. package/types/router/core/url/urlMatcherFactory.d.ts +46 -42
  103. package/types/router/core/url/urlRouter.d.ts +91 -75
  104. package/types/router/core/url/urlRule.d.ts +123 -100
  105. package/types/router/core/url/urlRules.d.ts +240 -232
  106. package/types/router/core/url/urlService.d.ts +201 -201
  107. package/types/router/core/view/index.d.ts +2 -2
  108. package/types/router/core/view/interface.d.ts +26 -26
  109. package/types/router/core/view/view.d.ts +152 -143
  110. package/types/router/directives/viewDirective.d.ts +12 -11
  111. package/types/router/index.d.ts +11 -12
  112. package/types/router/interface.d.ts +361 -351
  113. package/types/router/legacy/resolveService.d.ts +44 -40
  114. package/types/router/legacy/stateEvents.d.ts +1 -1
  115. package/types/router/locationServices.d.ts +45 -37
  116. package/types/router/services.d.ts +9 -9
  117. package/types/router/stateFilters.d.ts +3 -3
  118. package/types/router/stateProvider.d.ts +240 -235
  119. package/types/router/statebuilders/onEnterExitRetain.d.ts +4 -2
  120. package/types/router/statebuilders/views.d.ts +35 -22
  121. package/types/router/templateFactory.d.ts +99 -79
  122. package/types/router/viewScroll.d.ts +7 -7
  123. package/src/directive/a.js +0 -37
  124. package/test/directive/a.spec.js +0 -192
  125. package/types/router/angular.d.ts +0 -1
  126. package/types/router/core/vanilla.d.ts +0 -1
  127. package/types/router/directives/stateDirectives.d.ts +0 -3
  128. package/types/router/injectables.d.ts +0 -1
@@ -0,0 +1,1208 @@
1
+ import { jqLite } from "../../src/jqLite";
2
+ import { Angular } from "../../src/loader";
3
+ import { publishExternalAPI } from "../../src/public";
4
+ import { browserTrigger, wait } from "../test-utils";
5
+
6
+ describe("uiStateRef", function () {
7
+ let el,
8
+ el2,
9
+ template,
10
+ scope,
11
+ _locationProvider,
12
+ $rootScope,
13
+ $compile,
14
+ $q,
15
+ $injector,
16
+ $timeout,
17
+ $state,
18
+ $stateParams;
19
+
20
+ beforeEach(() => {
21
+ window.angular = new Angular();
22
+ publishExternalAPI();
23
+ let module = window.angular.module("defaultModule", ["ui.router"]);
24
+ module.config(($stateProvider, $locationProvider) => {
25
+ _locationProvider = $locationProvider;
26
+ $locationProvider.hashPrefix("");
27
+ $stateProvider
28
+ .state({ name: "top", url: "" })
29
+ .state({ name: "other", url: "/other/:id", template: "other" })
30
+ .state({ name: "other.detail", url: "/detail", template: "detail" })
31
+ .state({
32
+ name: "contacts",
33
+ url: "/contacts",
34
+ template:
35
+ '<a ui-sref=".item({ id: 5 })" class="item">Person</a> <ui-view></ui-view>',
36
+ })
37
+ .state({
38
+ name: "contacts.item",
39
+ url: "/{id:int}",
40
+ template:
41
+ '<a ui-sref=".detail" class="item-detail">Detail</a> | <a ui-sref="^" class="item-parent">Parent</a> | <ui-view></ui-view>',
42
+ })
43
+ .state({
44
+ name: "contacts.item.detail",
45
+ template:
46
+ '<div class="title">Detail</div> | <a ui-sref="^" class="item-parent2">Item</a>',
47
+ });
48
+ });
49
+ $injector = window.angular.bootstrap(document.getElementById("dummy"), [
50
+ "defaultModule",
51
+ ]);
52
+ $q = $injector.get("$q");
53
+ $rootScope = $injector.get("$rootScope");
54
+ $compile = $injector.get("$compile");
55
+ $timeout = $injector.get("$timeout");
56
+ $state = $injector.get("$state");
57
+ $stateParams = $injector.get("$stateParams");
58
+ });
59
+
60
+ afterEach(() => (window.location.hash = "#!"));
61
+
62
+ describe("links with promises", function () {
63
+ it("should update the href when promises on parameters change before scope is applied", async () => {
64
+ const defer = $q.defer();
65
+ el = jqLite(
66
+ '<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>',
67
+ );
68
+ defer.promise.then((val) => {
69
+ $rootScope.contact = val;
70
+ });
71
+ defer.resolve({ id: 6 });
72
+ el = $compile(el)($rootScope);
73
+
74
+ $rootScope.$digest();
75
+ expect(el.attr("href")).toBe("#/contacts/6");
76
+ });
77
+ });
78
+
79
+ function buildDOM() {
80
+ el = jqLite(
81
+ '<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>',
82
+ );
83
+ el2 = jqLite('<a ui-sref="top">Top</a>');
84
+ scope = $rootScope;
85
+ scope.contact = { id: 5 };
86
+ scope.$apply();
87
+
88
+ $compile(el)(scope);
89
+ $compile(el2)(scope);
90
+ scope.$digest();
91
+ }
92
+
93
+ describe("links", function () {
94
+ beforeEach(() => buildDOM());
95
+ afterEach(() => (window.location.hash = ""));
96
+
97
+ it("should generate the correct href", function () {
98
+ expect(el.attr("href")).toBe("#/contacts/5");
99
+ expect(el2.attr("href")).toBe("#");
100
+ });
101
+
102
+ it("should update the href when parameters change", function () {
103
+ expect(el.attr("href")).toBe("#/contacts/5");
104
+ scope.contact.id = 6;
105
+ scope.$apply();
106
+ expect(el.attr("href")).toBe("#/contacts/6");
107
+ });
108
+
109
+ it("should allow multi-line attribute values", async () => {
110
+ el = jqLite(
111
+ '<a ui-sref="contacts.item.detail({\n\tid: $index\n})">Details</a>',
112
+ );
113
+ $rootScope.$index = 3;
114
+ $rootScope.$apply();
115
+
116
+ $compile(el)($rootScope);
117
+ $rootScope.$digest();
118
+ expect(el.attr("href")).toBe("#/contacts/3");
119
+ });
120
+
121
+ it("should transition states when left-clicked", async () => {
122
+ browserTrigger(el, "click");
123
+ await wait(100);
124
+ expect($state.current.name).toEqual("contacts.item.detail");
125
+ expect($stateParams.id).toEqual(5);
126
+ });
127
+
128
+ it("should not transition states when ctrl-clicked", async () => {
129
+ jqLite(el)[0].dispatchEvent(
130
+ new MouseEvent("click", {
131
+ ctrlKey: true,
132
+ bubbles: true,
133
+ cancelable: true,
134
+ }),
135
+ );
136
+ await wait(100);
137
+ expect($state.current.name).toEqual("top");
138
+ expect($stateParams.id).toBeUndefined();
139
+ });
140
+
141
+ // TODO investigate further why this fails
142
+ xit("should not transition states when meta-clicked", async () => {
143
+ jqLite(el)[0].dispatchEvent(new MouseEvent("click", { metaKey: true }));
144
+ expect($state.current.name).toEqual("");
145
+ expect($stateParams.id).toBeUndefined();
146
+ });
147
+
148
+ it("should not transition states when shift-clicked", async () => {
149
+ jqLite(el)[0].dispatchEvent(new MouseEvent("click", { shiftKey: true }));
150
+ expect($state.current.name).toEqual("top");
151
+ expect($stateParams.id).toBeUndefined();
152
+ });
153
+
154
+ xit("should not transition states when alt-clicked", async () => {
155
+ expect($state.current.name).toEqual("");
156
+
157
+ jqLite(el)[0].dispatchEvent(new MouseEvent("click", { altKey: true }));
158
+ expect($state.current.name).toEqual("top");
159
+ expect($stateParams.id).toBeUndefined();
160
+ });
161
+
162
+ it("should not transition states when alt-clicked", async () => {
163
+ expect($state.current.name).toEqual("top");
164
+
165
+ jqLite(el)[0].dispatchEvent(new MouseEvent("click", { button: 1 }));
166
+ expect($state.current.name).toEqual("top");
167
+ expect($stateParams.id).toBeUndefined();
168
+ });
169
+
170
+ it("should not transition states when element has target specified", async () => {
171
+ el.attr("target", "_blank");
172
+ browserTrigger(el, "click");
173
+ await wait(100);
174
+ expect($state.current.name).toEqual("top");
175
+ expect($stateParams.id).toBeUndefined();
176
+ });
177
+
178
+ it("should not transition states if preventDefault() is called in click handler", async () => {
179
+ expect($stateParams.id).toBeUndefined();
180
+ el[0].onclick = (e) => e.preventDefault();
181
+
182
+ browserTrigger(el, "click");
183
+ await wait(100);
184
+ expect($state.current.name).toEqual("top");
185
+ expect($stateParams.id).toBeUndefined();
186
+ });
187
+
188
+ // // Test for #1031
189
+ // it('should allow passing params to current state', async () => {
190
+ // $state.go('other', { id: 'abc' });
191
+ // $rootScope.$index = 'def';
192
+ // $rootScope.$digest();
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');
201
+
202
+ // triggerClick(el);
203
+ // timeoutFlush();
204
+ // $q.flush();
205
+
206
+ // expect($state.current.name).toBe('other');
207
+ // expect($state.params).toEqual(expect.objectContaining({ id: 'def' });
208
+
209
+ // $rootScope.$index = 'ghi';
210
+ // $state.go('other.detail');
211
+ // $rootScope.$digest();
212
+
213
+ // expect($state.current.name).toBe('other.detail');
214
+ // expect($state.params).toEqual(expect.objectContaining({ id: 'def' });
215
+
216
+ // expect(el.attr('href')).toBe('#/other/ghi/detail');
217
+
218
+ // triggerClick(el);
219
+ // timeoutFlush();
220
+ // $q.flush();
221
+
222
+ // expect($state.current.name).toBe('other.detail');
223
+ // expect($state.params).toEqual(expect.objectContaining({ id: 'ghi' });
224
+ // });
225
+
226
+ // it('should allow multi-line attribute values when passing params to current state', async () => {
227
+ // $state.go('contacts.item.detail', { id: '123' });
228
+ // $rootScope.$digest();
229
+
230
+ // el = jqLite('<a ui-sref="{\n\tid: $index\n}">Details</a>');
231
+ // $rootScope.$index = 3;
232
+ // $rootScope.$apply();
233
+
234
+ // $compile(el)($rootScope);
235
+ // $rootScope.$digest();
236
+ // expect(el.attr('href')).toBe('#/contacts/3');
237
+ // });
238
+
239
+ // it('should take an object as a parameter and update properly on digest churns', async () => {
240
+ // el = jqLite('<div><a ui-sref="contacts.item.detail(urlParams)">Contacts</a></div>');
241
+ // template = $compile(el)($rootScope);
242
+
243
+ // $rootScope.urlParams = { id: 1 };
244
+ // $rootScope.$digest();
245
+ // expect(jqLite(template[0].querySelector('a')).attr('href')).toBe('#/contacts/1');
246
+
247
+ // $rootScope.urlParams.id = 2;
248
+ // $rootScope.$digest();
249
+ // expect(jqLite(template[0].querySelector('a')).attr('href')).toBe('#/contacts/2');
250
+ // });
251
+ });
252
+
253
+ // describe('links in html5 mode', function () {
254
+ // beforeEach(function () {
255
+ // _locationProvider.html5Mode(true);
256
+ // });
257
+
258
+ // beforeEach(inject(buildDOM));
259
+
260
+ // it('should generate the correct href', function () {
261
+ // expect(el.attr('href')).toBe('/contacts/5');
262
+ // expect(el2.attr('href')).toBe('');
263
+ // });
264
+
265
+ // it('should update the href when parameters change', function () {
266
+ // expect(el.attr('href')).toBe('/contacts/5');
267
+ // scope.contact.id = 6;
268
+ // scope.$apply();
269
+ // expect(el.attr('href')).toBe('/contacts/6');
270
+ // });
271
+
272
+ // it('should transition states when the url is empty', async () => {
273
+ // // Odd, in html5Mode, the initial state isn't matching on empty url, but does match if top.url is "/".
274
+ // // expect($state.$current.name).toEqual('top');
275
+
276
+ // triggerClick(el2);
277
+ // timeoutFlush();
278
+ // $q.flush();
279
+
280
+ // expect($state.current.name).toEqual('top');
281
+ // expect(obj($stateParams)).toEqual({});
282
+ // });
283
+ // });
284
+
285
+ // describe('links with dynamic state definitions', function () {
286
+ // let template, $state;
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
+ // });
298
+
299
+ // it('sets the correct initial href', function () {
300
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts');
301
+ // });
302
+
303
+ // it('updates to the new href', function () {
304
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts');
305
+
306
+ // scope.state = 'contacts.item';
307
+ // scope.params = { id: 5 };
308
+ // scope.$digest();
309
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/5');
310
+
311
+ // scope.params.id = 25;
312
+ // scope.$digest();
313
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/25');
314
+ // });
315
+
316
+ // it('updates a linked ui-sref-active', inject(function ($timeout) {
317
+ // function tick() {
318
+ // scope.$digest();
319
+ // try {
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
+ // });
351
+
352
+ // it('updates to a new href when it points to a new state', function () {
353
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts');
354
+ // scope.state = 'other';
355
+ // scope.params = { id: '123' };
356
+ // scope.$digest();
357
+ // expect(jqLite(template[0]).attr('href')).toBe('#/other/123');
358
+ // });
359
+
360
+ // // Test for #1031
361
+ // it('should allow passing params to current state using empty ui-state', inject(function (
362
+ // $compile,
363
+ // $rootScope,
364
+ // $state,
365
+ // $q
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();
382
+
383
+ // expect($state.current.name).toBe('other');
384
+ // expect($state.params).toEqual(expect.objectContaining({ id: 'def' });
385
+
386
+ // $rootScope.$index = 'ghi';
387
+ // $state.go('other.detail');
388
+ // $rootScope.$digest();
389
+
390
+ // expect($state.current.name).toBe('other.detail');
391
+ // expect($state.params).toEqual(expect.objectContaining({ id: 'def' });
392
+
393
+ // expect(el.attr('href')).toBe('#/other/ghi/detail');
394
+
395
+ // triggerClick(el);
396
+ // timeoutFlush();
397
+ // $q.flush();
398
+
399
+ // expect($state.current.name).toBe('other.detail');
400
+ // expect($state.params).toEqual(expect.objectContaining({ id: 'ghi' });
401
+ // });
402
+
403
+ // it('retains the old href if the new points to a non-state', function () {
404
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts');
405
+ // scope.state = 'nostate';
406
+ // scope.$digest();
407
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts');
408
+ // });
409
+
410
+ // it('accepts param overrides', inject(function ($compile) {
411
+ // scope.state = 'contacts.item';
412
+ // scope.params = { id: 10 };
413
+ // scope.$digest();
414
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
415
+ // });
416
+
417
+ // it('accepts param overrides', inject(function ($compile) {
418
+ // scope.state = 'contacts.item';
419
+ // scope.params = { id: 10 };
420
+ // scope.$digest();
421
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
422
+
423
+ // scope.params.id = 22;
424
+ // scope.$digest();
425
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/22');
426
+ // });
427
+
428
+ // it('watches attributes', inject(function ($compile) {
429
+ // el = jqLite('<a ui-state="{{exprvar}}" ui-state-params="params">state</a>');
430
+ // template = $compile(el)(scope);
431
+
432
+ // scope.exprvar = 'state1';
433
+ // scope.state1 = 'contacts.item';
434
+ // scope.state2 = 'other';
435
+ // scope.params = { id: 10 };
436
+ // scope.$digest();
437
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
438
+
439
+ // scope.exprvar = 'state2';
440
+ // scope.$digest();
441
+ // expect(jqLite(template[0]).attr('href')).toBe('#/other/10');
442
+ // });
443
+
444
+ // if (angular.version.minor >= 3) {
445
+ // it('allows one-time-binding on ng1.3+', inject(function ($compile) {
446
+ // el = jqLite('<a ui-state="::state" ui-state-params="::params">state</a>');
447
+
448
+ // scope.state = 'contacts.item';
449
+ // scope.params = { id: 10 };
450
+ // template = $compile(el)(scope);
451
+ // scope.$digest();
452
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
453
+
454
+ // scope.state = 'other';
455
+ // scope.params = { id: 22 };
456
+
457
+ // scope.$digest();
458
+ // expect(jqLite(template[0]).attr('href')).toBe('#/contacts/10');
459
+ // });
460
+ // }
461
+
462
+ // it('accepts option overrides', inject(function ($compile, $timeout, $state) {
463
+ // let transitionOptions;
464
+
465
+ // el = jqLite('<a ui-state="state" ui-state-opts="opts">state</a>');
466
+ // scope.state = 'contacts';
467
+ // scope.opts = { reload: true };
468
+ // template = $compile(el)(scope);
469
+ // scope.$digest();
470
+
471
+ // spyOn($state, 'go').and.callFake(function (state, params, options) {
472
+ // transitionOptions = options;
473
+ // });
474
+
475
+ // triggerClick(template);
476
+ // $timeout.flush();
477
+
478
+ // expect(transitionOptions.reload).toEqual(true);
479
+ // expect(transitionOptions.absolute).toBeUndefined();
480
+ // });
481
+
482
+ // describe('option event', function () {
483
+ // it('should bind click event by default', inject(function ($compile, $state, $timeout) {
484
+ // expect($state.current.name).toBe('top');
485
+
486
+ // el = jqLite('<a ui-state="state"></a>');
487
+
488
+ // scope.state = 'contacts';
489
+ // $compile(el)(scope);
490
+ // scope.$digest();
491
+
492
+ // triggerClick(el);
493
+ // $timeout.flush();
494
+
495
+ // expect($state.current.name).toBe('contacts');
496
+ // });
497
+
498
+ // it('should bind single HTML events', inject(function ($compile, $state, $timeout) {
499
+ // expect($state.current.name).toEqual('top');
500
+
501
+ // el = jqLite('<input type="text" ui-state="state" ui-state-opts="{ events: [\'change\'] }">');
502
+
503
+ // scope.state = 'contacts';
504
+ // $compile(el)(scope);
505
+ // scope.$digest();
506
+
507
+ // triggerHTMLEvent('change');
508
+ // $timeout.flush();
509
+
510
+ // expect($state.current.name).toEqual('contacts');
511
+ // });
512
+
513
+ // it('should bind multiple HTML events', inject(function ($compile, $state, $timeout) {
514
+ // expect($state.current.name).toEqual('top');
515
+
516
+ // el = jqLite('<input type="text" ui-state="state" ui-state-opts="{ events: [\'change\', \'blur\'] }">');
517
+
518
+ // scope.state = 'contacts';
519
+ // $compile(el)(scope);
520
+ // scope.$digest();
521
+
522
+ // triggerHTMLEvent('change');
523
+ // $timeout.flush();
524
+ // expect($state.current.name).toEqual('contacts');
525
+
526
+ // $state.go('top');
527
+ // scope.$digest();
528
+
529
+ // expect($state.current.name).toEqual('top');
530
+
531
+ // triggerHTMLEvent('blur');
532
+ // $timeout.flush();
533
+ // expect($state.current.name).toEqual('contacts');
534
+ // });
535
+
536
+ // it('should bind multiple Mouse events', inject(function ($compile, $state, $timeout) {
537
+ // expect($state.current.name).toEqual('top');
538
+
539
+ // el = jqLite('<a ui-state="state" ui-state-opts="{ events: [\'mouseover\', \'mousedown\'] }">');
540
+
541
+ // scope.state = 'contacts';
542
+ // $compile(el)(scope);
543
+ // scope.$digest();
544
+
545
+ // triggerMouseEvent('mouseover');
546
+ // $timeout.flush();
547
+ // expect($state.current.name).toEqual('contacts');
548
+
549
+ // $state.go('top');
550
+ // scope.$digest();
551
+
552
+ // expect($state.current.name).toEqual('top');
553
+
554
+ // triggerMouseEvent('mousedown');
555
+ // $timeout.flush();
556
+ // expect($state.current.name).toEqual('contacts');
557
+ // });
558
+ // });
559
+ // });
560
+
561
+ // describe('forms', function () {
562
+ // let el, scope;
563
+
564
+ // beforeEach(inject(function ($rootScope, $compile) {
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();
569
+
570
+ // $compile(el)(scope);
571
+ // scope.$digest();
572
+ // });
573
+
574
+ // it('should generate the correct action', function () {
575
+ // expect(el.attr('action')).toBe('#/contacts/5');
576
+ // });
577
+ // });
578
+
579
+ // describe('relative transitions', function () {
580
+ // beforeEach(inject(function ($rootScope, $compile, $state) {
581
+ // $state.transitionTo('contacts.item', { id: 5 });
582
+ // el = angular.element('<a ui-sref=".detail">Details</a>');
583
+ // scope = $rootScope;
584
+ // scope.$apply();
585
+
586
+ // $compile(el)(scope);
587
+ // template = $compile(angular.element('<div><ui-view></ui-view><div>'))(scope);
588
+ // scope.$digest();
589
+ // });
590
+
591
+ // it('should work', inject(function ($state, $stateParams, $q, $timeout) {
592
+ // triggerClick(el);
593
+ // $timeout.flush();
594
+ // $q.flush();
595
+
596
+ // expect($state.$current.name).toBe('contacts.item.detail');
597
+ // expect(obj($state.params)).toEqual({ id: 5 });
598
+ // });
599
+
600
+ // it('should resolve states from parent uiView', inject(function ($state, $stateParams, $q, $timeout) {
601
+ // $state.transitionTo('contacts');
602
+ // $q.flush();
603
+
604
+ // const parentToChild = angular.element(template[0].querySelector('a.item'));
605
+ // triggerClick(parentToChild);
606
+ // $timeout.flush();
607
+ // $q.flush();
608
+ // expect($state.$current.name).toBe('contacts.item');
609
+
610
+ // const childToGrandchild = angular.element(template[0].querySelector('a.item-detail'));
611
+ // const childToParent = angular.element(template[0].querySelector('a.item-parent'));
612
+
613
+ // triggerClick(childToGrandchild);
614
+ // $timeout.flush();
615
+ // $q.flush();
616
+
617
+ // const grandchildToParent = angular.element(template[0].querySelector('a.item-parent2'));
618
+ // expect($state.$current.name).toBe('contacts.item.detail');
619
+
620
+ // triggerClick(grandchildToParent);
621
+ // $timeout.flush();
622
+ // $q.flush();
623
+ // expect($state.$current.name).toBe('contacts.item');
624
+
625
+ // $state.transitionTo('contacts.item.detail', { id: 3 });
626
+ // triggerClick(childToParent);
627
+ // $timeout.flush();
628
+ // $q.flush();
629
+ // expect($state.$current.name).toBe('contacts');
630
+ // });
631
+ // });
632
+
633
+ // describe('option event', function () {
634
+ // it('should bind click event by default', inject(function ($rootScope, $compile, $state, $timeout) {
635
+ // el = angular.element('<a ui-sref="contacts"></a>');
636
+ // $compile(el)($rootScope);
637
+ // $rootScope.$digest();
638
+
639
+ // expect($state.current.name).toEqual('top');
640
+
641
+ // triggerClick(el);
642
+ // $timeout.flush();
643
+
644
+ // expect($state.current.name).toEqual('contacts');
645
+ // });
646
+
647
+ // it('should bind single HTML events', inject(function ($rootScope, $compile, $state, $timeout) {
648
+ // el = angular.element('<input type="text" ui-sref="contacts" ui-sref-opts="{ events: [\'change\'] }">');
649
+ // $compile(el)($rootScope);
650
+ // $rootScope.$digest();
651
+
652
+ // expect($state.current.name).toEqual('top');
653
+
654
+ // triggerHTMLEvent('change');
655
+ // $timeout.flush();
656
+
657
+ // expect($state.current.name).toEqual('contacts');
658
+ // });
659
+
660
+ // it('should bind multiple HTML events', inject(function ($rootScope, $compile, $state, $timeout) {
661
+ // el = angular.element('<input type="text" ui-sref="contacts" ui-sref-opts="{ events: [\'change\', \'blur\'] }">');
662
+ // $compile(el)($rootScope);
663
+ // $rootScope.$digest();
664
+
665
+ // expect($state.current.name).toEqual('top');
666
+
667
+ // triggerHTMLEvent('change');
668
+ // $timeout.flush();
669
+ // expect($state.current.name).toEqual('contacts');
670
+
671
+ // $state.go('top');
672
+ // $rootScope.$digest();
673
+
674
+ // expect($state.current.name).toEqual('top');
675
+
676
+ // triggerHTMLEvent('blur');
677
+ // $timeout.flush();
678
+ // expect($state.current.name).toEqual('contacts');
679
+ // });
680
+
681
+ // it('should bind multiple Mouse events', inject(function ($rootScope, $compile, $state, $timeout) {
682
+ // el = angular.element('<a ui-sref="contacts" ui-sref-opts="{ events: [\'mouseover\', \'mousedown\'] }">');
683
+ // $compile(el)($rootScope);
684
+ // $rootScope.$digest();
685
+
686
+ // expect($state.current.name).toEqual('top');
687
+
688
+ // triggerMouseEvent('mouseover');
689
+ // $timeout.flush();
690
+ // expect($state.current.name).toEqual('contacts');
691
+
692
+ // $state.go('top');
693
+ // $rootScope.$digest();
694
+
695
+ // expect($state.current.name).toEqual('top');
696
+
697
+ // triggerMouseEvent('mousedown');
698
+ // $timeout.flush();
699
+ // expect($state.current.name).toEqual('contacts');
700
+ // });
701
+ // });
702
+ });
703
+
704
+ // describe('uiSrefActive', function () {
705
+ // let el, template, scope, document, _stateProvider;
706
+
707
+ // beforeEach(module('ui.router'));
708
+
709
+ // beforeEach(
710
+ // module(function ($stateProvider) {
711
+ // _stateProvider = $stateProvider;
712
+ // $stateProvider
713
+ // .state({name: 'top', url: '',
714
+ // })
715
+ // .state({name: 'contacts', url: '/contacts',
716
+ // views: {
717
+ // $default: {
718
+ // template: '<a ui-sref=".item({ id: 6 })" ui-sref-active="active">Contacts</a>',
719
+ // },
720
+ // },
721
+ // })
722
+ // .state({name: 'contacts.item', url: '/:id',
723
+ // })
724
+ // .state({name: 'contacts.item.detail', url: '/detail/:foo',
725
+ // })
726
+ // .state({name: 'contacts.item.edit', url: '/edit',
727
+ // })
728
+ // .state({name: 'admin', url: '/admin',
729
+ // abstract: true,
730
+ // template: '<ui-view/>',
731
+ // })
732
+ // .state({name: 'admin.roles', url: '/roles?page',
733
+ // })
734
+ // .state({name: 'arrayparam', url: '/arrayparam?{foo:int}&bar',
735
+ // template: '<div></div>',
736
+ // });
737
+ // })
738
+ // );
739
+
740
+ // beforeEach(inject(function ($document, $timeout) {
741
+ // document = $document[0];
742
+ // timeoutFlush = function () {
743
+ // try {
744
+ // $timeout.flush();
745
+ // } catch (e) {
746
+ // // Angular 1.0.8 throws 'No deferred tasks to be flushed' if there is nothing in queue.
747
+ // // Behave as Angular >=1.1.5 and do nothing in such case.
748
+ // }
749
+ // };
750
+ // });
751
+
752
+ // it('should update class for sibling uiSref', inject(function ($rootScope, $q, $compile, $state) {
753
+ // el = angular.element(
754
+ // '<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>'
755
+ // );
756
+ // template = $compile(el)($rootScope);
757
+ // $rootScope.$digest();
758
+
759
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
760
+ // $state.transitionTo('contacts.item', { id: 1 });
761
+ // $q.flush();
762
+ // timeoutFlush();
763
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
764
+
765
+ // $state.transitionTo('contacts.item', { id: 2 });
766
+ // $q.flush();
767
+ // timeoutFlush();
768
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
769
+ // });
770
+
771
+ // it("should match state's parameters", inject(function ($rootScope, $q, $compile, $state) {
772
+ // el = angular.element(
773
+ // '<div><a ui-sref="contacts.item.detail({ foo: \'bar\' })" ui-sref-active="active">Contacts</a></div>'
774
+ // );
775
+ // template = $compile(el)($rootScope);
776
+ // $rootScope.$digest();
777
+
778
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
779
+ // $state.transitionTo('contacts.item.detail', { id: 5, foo: 'bar' });
780
+ // $q.flush();
781
+ // timeoutFlush();
782
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
783
+
784
+ // $state.transitionTo('contacts.item.detail', { id: 5, foo: 'baz' });
785
+ // $q.flush();
786
+ // timeoutFlush();
787
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
788
+ // });
789
+
790
+ // // Test for #2696
791
+ // it('should compare using typed parameters', inject(function ($rootScope, $q, $compile, $state) {
792
+ // el = angular.element('<div><a ui-sref="arrayparam({ foo: [1,2,3] })" ui-sref-active="active">foo 123</a></div>');
793
+ // template = $compile(el)($rootScope);
794
+ // $rootScope.$digest();
795
+
796
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
797
+
798
+ // $state.transitionTo('arrayparam', { foo: [1, 2, 3] });
799
+ // $q.flush();
800
+ // timeoutFlush();
801
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
802
+
803
+ // $state.transitionTo('arrayparam', { foo: [1, 2, 3], bar: 'asdf' });
804
+ // $q.flush();
805
+ // timeoutFlush();
806
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
807
+
808
+ // $state.transitionTo('arrayparam', { foo: [1, 2] });
809
+ // $q.flush();
810
+ // timeoutFlush();
811
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
812
+ // });
813
+
814
+ // // Test for #3154
815
+ // it('should compare ui-sref-active-eq using typed parameters', inject(function ($rootScope, $q, $compile, $state) {
816
+ // el = angular.element('<div><a ui-sref="arrayparam({ foo: [1,2,3] })" ui-sref-active-eq="active">foo 123</a></div>');
817
+ // template = $compile(el)($rootScope);
818
+ // $rootScope.$digest();
819
+
820
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
821
+
822
+ // $state.transitionTo('arrayparam', { foo: [1, 2, 3] });
823
+ // $q.flush();
824
+ // timeoutFlush();
825
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
826
+
827
+ // $state.transitionTo('arrayparam', { foo: [1, 2, 3], bar: 'asdf' });
828
+ // $q.flush();
829
+ // timeoutFlush();
830
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
831
+
832
+ // $state.transitionTo('arrayparam', { foo: [1, 2] });
833
+ // $q.flush();
834
+ // timeoutFlush();
835
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
836
+ // });
837
+
838
+ // it('should update in response to ui-sref param expression changes', inject(function (
839
+ // $rootScope,
840
+ // $q,
841
+ // $compile,
842
+ // $state
843
+ // ) {
844
+ // el = angular.element(
845
+ // '<div><a ui-sref="contacts.item.detail({ foo: fooId })" ui-sref-active="active">Contacts</a></div>'
846
+ // );
847
+ // template = $compile(el)($rootScope);
848
+ // $rootScope.fooId = 'bar';
849
+ // $rootScope.$digest();
850
+
851
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
852
+ // $state.transitionTo('contacts.item.detail', { id: 5, foo: 'bar' });
853
+ // $q.flush();
854
+ // timeoutFlush();
855
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
856
+
857
+ // $rootScope.fooId = 'baz';
858
+ // $q.flush();
859
+ // timeoutFlush();
860
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
861
+ // });
862
+
863
+ // it('should match on child states', inject(function ($rootScope, $q, $compile, $state) {
864
+ // template = $compile('<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active">Contacts</a></div>')(
865
+ // $rootScope
866
+ // );
867
+ // $rootScope.$digest();
868
+ // const a = angular.element(template[0].getElementsByTagName('a')[0]);
869
+
870
+ // $state.transitionTo('contacts.item.edit', { id: 1 });
871
+ // $q.flush();
872
+ // timeoutFlush();
873
+ // expect($state.params.id).toBe('1');
874
+ // expect(a.attr('class')).toMatch(/active/);
875
+
876
+ // $state.transitionTo('contacts.item.edit', { id: 4 });
877
+ // $q.flush();
878
+ // timeoutFlush();
879
+ // expect($state.params.id).toBe('4');
880
+ // expect(a.attr('class')).not.toMatch(/active/);
881
+ // });
882
+
883
+ // it('should NOT match on child states when active-equals is used', inject(function ($rootScope, $q, $compile, $state) {
884
+ // template = $compile('<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active-eq="active">Contacts</a></div>')(
885
+ // $rootScope
886
+ // );
887
+ // $rootScope.$digest();
888
+ // const a = angular.element(template[0].getElementsByTagName('a')[0]);
889
+
890
+ // $state.transitionTo('contacts.item', { id: 1 });
891
+ // $q.flush();
892
+ // timeoutFlush();
893
+ // expect(a.attr('class')).toMatch(/active/);
894
+
895
+ // $state.transitionTo('contacts.item.edit', { id: 1 });
896
+ // $q.flush();
897
+ // timeoutFlush();
898
+ // expect(a.attr('class')).not.toMatch(/active/);
899
+ // });
900
+
901
+ // it('should match on child states when active-equals and active-equals-eq is used', inject(function (
902
+ // $rootScope,
903
+ // $q,
904
+ // $compile,
905
+ // $state,
906
+ // $timeout
907
+ // ) {
908
+ // template = $compile(
909
+ // '<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active" ui-sref-active-eq="active-eq">Contacts</a></div>'
910
+ // )($rootScope);
911
+ // $rootScope.$digest();
912
+ // const a = angular.element(template[0].getElementsByTagName('a')[0]);
913
+
914
+ // $state.transitionTo('contacts.item', { id: 1 });
915
+ // $q.flush();
916
+ // timeoutFlush();
917
+ // expect(a.attr('class')).toMatch(/active/);
918
+ // expect(a.attr('class')).toMatch(/active-eq/);
919
+
920
+ // $state.transitionTo('contacts.item.edit', { id: 1 });
921
+ // $q.flush();
922
+ // timeoutFlush();
923
+ // expect(a.attr('class')).toMatch(/active/);
924
+ // expect(a.attr('class')).not.toMatch(/active-eq/);
925
+ // });
926
+
927
+ // it('should resolve relative state refs', inject(function ($rootScope, $q, $compile, $state) {
928
+ // el = angular.element('<section><div ui-view></div></section>');
929
+ // template = $compile(el)($rootScope);
930
+ // $rootScope.$digest();
931
+
932
+ // $state.transitionTo('contacts');
933
+ // $q.flush();
934
+ // timeoutFlush();
935
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('ng-scope');
936
+
937
+ // $state.transitionTo('contacts.item', { id: 6 });
938
+ // $q.flush();
939
+ // timeoutFlush();
940
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('ng-scope active');
941
+
942
+ // $state.transitionTo('contacts.item', { id: 5 });
943
+ // $q.flush();
944
+ // timeoutFlush();
945
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('ng-scope');
946
+ // });
947
+
948
+ // it('should match on any child state refs', inject(function ($rootScope, $q, $compile, $state) {
949
+ // el = angular.element(
950
+ // '<div ui-sref-active="active"><a ui-sref="contacts.item({ id: 1 })">Contacts</a><a ui-sref="contacts.item({ id: 2 })">Contacts</a></div>'
951
+ // );
952
+ // template = $compile(el)($rootScope);
953
+ // $rootScope.$digest();
954
+
955
+ // expect(angular.element(template[0]).attr('class')).toBe('ng-scope');
956
+
957
+ // $state.transitionTo('contacts.item', { id: 1 });
958
+ // $q.flush();
959
+ // timeoutFlush();
960
+ // expect(angular.element(template[0]).attr('class')).toBe('ng-scope active');
961
+
962
+ // $state.transitionTo('contacts.item', { id: 2 });
963
+ // $q.flush();
964
+ // timeoutFlush();
965
+ // expect(angular.element(template[0]).attr('class')).toBe('ng-scope active');
966
+ // });
967
+
968
+ // it('should match fuzzy on lazy loaded states', inject(function ($rootScope, $q, $compile, $state) {
969
+ // el = angular.element('<div><a ui-sref="contacts.lazy" ui-sref-active="active">Lazy Contact</a></div>');
970
+ // template = $compile(el)($rootScope);
971
+ // $q.flush();
972
+
973
+ // _stateProvider.onInvalid(function ($to$) {
974
+ // if ($to$.name() === 'contacts.lazy') {
975
+ // _stateProvider.state({name: 'contacts.lazy', {});
976
+ // return $to$;
977
+ // }
978
+ // });
979
+
980
+ // $state.transitionTo('contacts.item', { id: 1 });
981
+ // $q.flush();
982
+ // timeoutFlush();
983
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
984
+
985
+ // $state.transitionTo('contacts.lazy');
986
+ // $q.flush();
987
+ // timeoutFlush();
988
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
989
+ // });
990
+
991
+ // it('should match exactly on lazy loaded states', inject(function ($transitions, $rootScope, $q, $compile, $state) {
992
+ // el = angular.element('<div><a ui-sref="contacts.lazy" ui-sref-active-eq="active">Lazy Contact</a></div>');
993
+ // template = $compile(el)($rootScope);
994
+ // $q.flush();
995
+
996
+ // _stateProvider.onInvalid(function ($to$) {
997
+ // if ($to$.name() === 'contacts.lazy') {
998
+ // _stateProvider.state({name: 'contacts.lazy', {});
999
+ // return $to$;
1000
+ // }
1001
+ // });
1002
+
1003
+ // $state.transitionTo('contacts.item', { id: 1 });
1004
+ // $q.flush();
1005
+ // timeoutFlush();
1006
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBeFalsy();
1007
+
1008
+ // $state.transitionTo('contacts.lazy');
1009
+ // $q.flush();
1010
+ // timeoutFlush();
1011
+ // expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active');
1012
+ // });
1013
+
1014
+ // it('should allow multiple classes to be supplied', inject(function ($rootScope, $q, $compile, $state) {
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 = angular.element(template[0].getElementsByTagName('a')[0]);
1020
+
1021
+ // $state.transitionTo('contacts.item.edit', { id: 1 });
1022
+ // $q.flush();
1023
+ // timeoutFlush();
1024
+ // expect(a.attr('class')).toMatch(/active also-active/);
1025
+ // });
1026
+
1027
+ // it('should not match fuzzy on lazy loaded future states', inject(function ($rootScope, $compile, $q, $state) {
1028
+ // _stateProvider.state({name: 'contacts.lazy.**', {
1029
+ // url: '/lazy',
1030
+ // lazyLoad: function () {
1031
+ // return $q.when().then(function () {
1032
+ // _stateProvider
1033
+ // .state({name: 'contacts.lazy', {
1034
+ // abstract: true,
1035
+ // url: '/lazy',
1036
+ // })
1037
+ // .state({name: 'contacts.lazy.s1', {
1038
+ // url: '/s1',
1039
+ // })
1040
+ // .state({name: 'contacts.lazy.s2', {
1041
+ // url: '/s2',
1042
+ // });
1043
+ // });
1044
+ // },
1045
+ // });
1046
+ // template = $compile(
1047
+ // '<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>'
1048
+ // )($rootScope);
1049
+ // $rootScope.$digest();
1050
+ // $state.transitionTo('contacts.lazy.s1');
1051
+ // $q.flush();
1052
+ // timeoutFlush();
1053
+ // expect(template.eq(0).hasClass('active')).toBeTruthy();
1054
+ // expect(template.eq(1).hasClass('active')).toBeFalsy();
1055
+ // });
1056
+
1057
+ // describe('ng-{class,style} interface', function () {
1058
+ // it('should match on abstract states that are included by the current state', inject(function (
1059
+ // $rootScope,
1060
+ // $compile,
1061
+ // $state,
1062
+ // $q
1063
+ // ) {
1064
+ // el = $compile(
1065
+ // '<div ui-sref-active="{active: \'admin.*\'}"><a ui-sref-active="active" ui-sref="admin.roles">Roles</a></div>'
1066
+ // )($rootScope);
1067
+ // $state.transitionTo('admin.roles');
1068
+ // $q.flush();
1069
+ // timeoutFlush();
1070
+ // const abstractParent = el[0];
1071
+ // expect(abstractParent.className).toMatch(/active/);
1072
+ // const child = el[0].querySelector('a');
1073
+ // expect(child.className).toMatch(/active/);
1074
+ // });
1075
+
1076
+ // it('should match on state parameters', async () => {
1077
+ // el = $compile('<div ui-sref-active="{active: \'admin.roles({page: 1})\'}"></div>')($rootScope);
1078
+ // $state.transitionTo('admin.roles', { page: 1 });
1079
+ // $q.flush();
1080
+ // timeoutFlush();
1081
+ // expect(el[0].className).toMatch(/active/);
1082
+ // });
1083
+
1084
+ // it('should shadow the state provided by ui-sref', async () => {
1085
+ // el = $compile('<div ui-sref-active="{active: \'admin.roles({page: 1})\'}"><a ui-sref="admin.roles"></a></div>')(
1086
+ // $rootScope
1087
+ // );
1088
+ // $state.transitionTo('admin.roles');
1089
+ // $q.flush();
1090
+ // timeoutFlush();
1091
+ // expect(el[0].className).not.toMatch(/active/);
1092
+ // $state.transitionTo('admin.roles', { page: 1 });
1093
+ // $q.flush();
1094
+ // timeoutFlush();
1095
+ // expect(el[0].className).toMatch(/active/);
1096
+ // });
1097
+
1098
+ // it('should support multiple <className, stateOrName> pairs', async () => {
1099
+ // el = $compile("<div ui-sref-active=\"{contacts: 'contacts.**', admin: 'admin.roles({page: 1})'}\"></div>")(
1100
+ // $rootScope
1101
+ // );
1102
+ // $state.transitionTo('contacts');
1103
+ // $q.flush();
1104
+ // timeoutFlush();
1105
+ // expect(el[0].className).toMatch(/contacts/);
1106
+ // expect(el[0].className).not.toMatch(/admin/);
1107
+ // $state.transitionTo('admin.roles', { page: 1 });
1108
+ // $q.flush();
1109
+ // timeoutFlush();
1110
+ // expect(el[0].className).toMatch(/admin/);
1111
+ // expect(el[0].className).not.toMatch(/contacts/);
1112
+ // });
1113
+
1114
+ // it('should update the active classes when compiled', inject(function ($compile, $rootScope, $document, $state, $q) {
1115
+ // $state.transitionTo('admin.roles');
1116
+ // $q.flush();
1117
+ // timeoutFlush();
1118
+ // el = $compile('<div ui-sref-active="{active: \'admin.roles\'}"/>')($rootScope);
1119
+ // $rootScope.$digest();
1120
+ // timeoutFlush();
1121
+ // expect(el.hasClass('active')).toBeTruthy();
1122
+ // });
1123
+
1124
+ // it('should not match fuzzy on lazy loaded future states', inject(function ($rootScope, $compile, $q, $state) {
1125
+ // _stateProvider.state({name: 'contacts.lazy.**', {
1126
+ // url: '/lazy',
1127
+ // lazyLoad: function () {
1128
+ // return $q.when().then(function () {
1129
+ // _stateProvider
1130
+ // .state({name: 'contacts.lazy', {
1131
+ // abstract: true,
1132
+ // url: '/lazy',
1133
+ // })
1134
+ // .state({name: 'contacts.lazy.s1', {
1135
+ // url: '/s1',
1136
+ // })
1137
+ // .state({name: 'contacts.lazy.s2', {
1138
+ // url: '/s2',
1139
+ // });
1140
+ // });
1141
+ // },
1142
+ // });
1143
+ // template = $compile(
1144
+ // '<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>'
1145
+ // )($rootScope);
1146
+ // $rootScope.$digest();
1147
+ // $state.transitionTo('contacts.lazy.s1');
1148
+ // $q.flush();
1149
+ // timeoutFlush();
1150
+ // expect(template.eq(0).hasClass('active')).toBeTruthy();
1151
+ // expect(template.eq(1).hasClass('active')).toBeFalsy();
1152
+ // });
1153
+ // });
1154
+
1155
+ // describe('ng-{class,style} interface, and handle values as arrays', function () {
1156
+ // it('should match on abstract states that are included by the current state', inject(function (
1157
+ // $rootScope,
1158
+ // $compile,
1159
+ // $state,
1160
+ // $q
1161
+ // ) {
1162
+ // el = $compile(
1163
+ // '<div ui-sref-active="{active: [\'randomState.**\', \'admin.roles\']}"><a ui-sref-active="active" ui-sref="admin.roles">Roles</a></div>'
1164
+ // )($rootScope);
1165
+ // $state.transitionTo('admin.roles');
1166
+ // $q.flush();
1167
+ // timeoutFlush();
1168
+ // const abstractParent = el[0];
1169
+ // expect(abstractParent.className).toMatch(/active/);
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
+ // });