@angular-wave/angular.ts 0.0.1

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 (231) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +29 -0
  3. package/.github/workflows/playwright.yml +27 -0
  4. package/CHANGELOG.md +17974 -0
  5. package/CODE_OF_CONDUCT.md +3 -0
  6. package/CONTRIBUTING.md +246 -0
  7. package/DEVELOPERS.md +488 -0
  8. package/LICENSE +22 -0
  9. package/Makefile +31 -0
  10. package/README.md +115 -0
  11. package/RELEASE.md +98 -0
  12. package/SECURITY.md +16 -0
  13. package/TRIAGING.md +135 -0
  14. package/css/angular.css +22 -0
  15. package/dist/angular-ts.cjs.js +36843 -0
  16. package/dist/angular-ts.esm.js +36841 -0
  17. package/dist/angular-ts.umd.js +36848 -0
  18. package/dist/build/angular-animate.js +4272 -0
  19. package/dist/build/angular-aria.js +426 -0
  20. package/dist/build/angular-message-format.js +1072 -0
  21. package/dist/build/angular-messages.js +829 -0
  22. package/dist/build/angular-mocks.js +3757 -0
  23. package/dist/build/angular-parse-ext.js +1275 -0
  24. package/dist/build/angular-resource.js +911 -0
  25. package/dist/build/angular-route.js +1266 -0
  26. package/dist/build/angular-sanitize.js +891 -0
  27. package/dist/build/angular-touch.js +368 -0
  28. package/dist/build/angular.js +36600 -0
  29. package/e2e/unit.spec.ts +15 -0
  30. package/images/android-chrome-192x192.png +0 -0
  31. package/images/android-chrome-512x512.png +0 -0
  32. package/images/apple-touch-icon.png +0 -0
  33. package/images/favicon-16x16.png +0 -0
  34. package/images/favicon-32x32.png +0 -0
  35. package/images/favicon.ico +0 -0
  36. package/images/site.webmanifest +1 -0
  37. package/index.html +104 -0
  38. package/package.json +47 -0
  39. package/playwright.config.ts +78 -0
  40. package/public/circle.html +1 -0
  41. package/public/my_child_directive.html +1 -0
  42. package/public/my_directive.html +1 -0
  43. package/public/my_other_directive.html +1 -0
  44. package/public/test.html +1 -0
  45. package/rollup.config.js +31 -0
  46. package/src/animations/animateCache.js +55 -0
  47. package/src/animations/animateChildrenDirective.js +105 -0
  48. package/src/animations/animateCss.js +1139 -0
  49. package/src/animations/animateCssDriver.js +291 -0
  50. package/src/animations/animateJs.js +367 -0
  51. package/src/animations/animateJsDriver.js +67 -0
  52. package/src/animations/animateQueue.js +851 -0
  53. package/src/animations/animation.js +506 -0
  54. package/src/animations/module.js +779 -0
  55. package/src/animations/ngAnimateSwap.js +119 -0
  56. package/src/animations/rafScheduler.js +50 -0
  57. package/src/animations/shared.js +378 -0
  58. package/src/constants.js +20 -0
  59. package/src/core/animate.js +845 -0
  60. package/src/core/animateCss.js +73 -0
  61. package/src/core/animateRunner.js +195 -0
  62. package/src/core/attributes.js +199 -0
  63. package/src/core/cache.js +45 -0
  64. package/src/core/compile.js +4727 -0
  65. package/src/core/controller.js +225 -0
  66. package/src/core/exceptionHandler.js +63 -0
  67. package/src/core/filter.js +146 -0
  68. package/src/core/interpolate.js +442 -0
  69. package/src/core/interval.js +188 -0
  70. package/src/core/intervalFactory.js +57 -0
  71. package/src/core/location.js +1086 -0
  72. package/src/core/parser/parse.js +2562 -0
  73. package/src/core/parser/parse.md +13 -0
  74. package/src/core/q.js +746 -0
  75. package/src/core/rootScope.js +1596 -0
  76. package/src/core/sanitizeUri.js +85 -0
  77. package/src/core/sce.js +1161 -0
  78. package/src/core/taskTrackerFactory.js +125 -0
  79. package/src/core/timeout.js +121 -0
  80. package/src/core/urlUtils.js +187 -0
  81. package/src/core/utils.js +1349 -0
  82. package/src/directive/a.js +37 -0
  83. package/src/directive/attrs.js +283 -0
  84. package/src/directive/bind.js +51 -0
  85. package/src/directive/bind.md +142 -0
  86. package/src/directive/change.js +12 -0
  87. package/src/directive/change.md +25 -0
  88. package/src/directive/cloak.js +12 -0
  89. package/src/directive/cloak.md +24 -0
  90. package/src/directive/events.js +75 -0
  91. package/src/directive/events.md +166 -0
  92. package/src/directive/form.js +725 -0
  93. package/src/directive/init.js +15 -0
  94. package/src/directive/init.md +41 -0
  95. package/src/directive/input.js +1783 -0
  96. package/src/directive/list.js +46 -0
  97. package/src/directive/list.md +22 -0
  98. package/src/directive/ngClass.js +249 -0
  99. package/src/directive/ngController.js +64 -0
  100. package/src/directive/ngCsp.js +82 -0
  101. package/src/directive/ngIf.js +134 -0
  102. package/src/directive/ngInclude.js +217 -0
  103. package/src/directive/ngModel.js +1356 -0
  104. package/src/directive/ngModelOptions.js +509 -0
  105. package/src/directive/ngOptions.js +670 -0
  106. package/src/directive/ngRef.js +90 -0
  107. package/src/directive/ngRepeat.js +650 -0
  108. package/src/directive/ngShowHide.js +255 -0
  109. package/src/directive/ngSwitch.js +178 -0
  110. package/src/directive/ngTransclude.js +98 -0
  111. package/src/directive/non-bindable.js +11 -0
  112. package/src/directive/non-bindable.md +17 -0
  113. package/src/directive/script.js +30 -0
  114. package/src/directive/select.js +624 -0
  115. package/src/directive/style.js +25 -0
  116. package/src/directive/style.md +23 -0
  117. package/src/directive/validators.js +329 -0
  118. package/src/exts/aria.js +544 -0
  119. package/src/exts/messages.js +852 -0
  120. package/src/filters/filter.js +207 -0
  121. package/src/filters/filter.md +69 -0
  122. package/src/filters/filters.js +239 -0
  123. package/src/filters/json.md +16 -0
  124. package/src/filters/limit-to.js +43 -0
  125. package/src/filters/limit-to.md +19 -0
  126. package/src/filters/order-by.js +183 -0
  127. package/src/filters/order-by.md +83 -0
  128. package/src/index.js +13 -0
  129. package/src/injector.js +1034 -0
  130. package/src/jqLite.js +1117 -0
  131. package/src/loader.js +1320 -0
  132. package/src/public.js +215 -0
  133. package/src/routeToRegExp.js +41 -0
  134. package/src/services/anchorScroll.js +135 -0
  135. package/src/services/browser.js +321 -0
  136. package/src/services/cacheFactory.js +398 -0
  137. package/src/services/cookieReader.js +72 -0
  138. package/src/services/document.js +64 -0
  139. package/src/services/http.js +1537 -0
  140. package/src/services/httpBackend.js +206 -0
  141. package/src/services/log.js +160 -0
  142. package/src/services/templateRequest.js +139 -0
  143. package/test/angular.spec.js +2153 -0
  144. package/test/aria/aria.spec.js +1245 -0
  145. package/test/binding.spec.js +504 -0
  146. package/test/build-test.html +14 -0
  147. package/test/injector.spec.js +2327 -0
  148. package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
  149. package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
  150. package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
  151. package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
  152. package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
  153. package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
  154. package/test/jasmine/jasmine-browser.json +17 -0
  155. package/test/jasmine/jasmine.json +9 -0
  156. package/test/jqlite.spec.js +2133 -0
  157. package/test/loader.spec.js +219 -0
  158. package/test/messages/messages.spec.js +1146 -0
  159. package/test/min-err.spec.js +174 -0
  160. package/test/mock-test.html +13 -0
  161. package/test/module-test.html +15 -0
  162. package/test/ng/anomate.spec.js +606 -0
  163. package/test/ng/cache-factor.spec.js +334 -0
  164. package/test/ng/compile.spec.js +17956 -0
  165. package/test/ng/controller-provider.spec.js +227 -0
  166. package/test/ng/cookie-reader.spec.js +98 -0
  167. package/test/ng/directive/a.spec.js +192 -0
  168. package/test/ng/directive/bind.spec.js +334 -0
  169. package/test/ng/directive/boolean.spec.js +136 -0
  170. package/test/ng/directive/change.spec.js +71 -0
  171. package/test/ng/directive/class.spec.js +858 -0
  172. package/test/ng/directive/click.spec.js +38 -0
  173. package/test/ng/directive/cloak.spec.js +44 -0
  174. package/test/ng/directive/constoller.spec.js +194 -0
  175. package/test/ng/directive/element-style.spec.js +92 -0
  176. package/test/ng/directive/event.spec.js +282 -0
  177. package/test/ng/directive/form.spec.js +1518 -0
  178. package/test/ng/directive/href.spec.js +143 -0
  179. package/test/ng/directive/if.spec.js +402 -0
  180. package/test/ng/directive/include.spec.js +828 -0
  181. package/test/ng/directive/init.spec.js +68 -0
  182. package/test/ng/directive/input.spec.js +3810 -0
  183. package/test/ng/directive/list.spec.js +170 -0
  184. package/test/ng/directive/model-options.spec.js +1008 -0
  185. package/test/ng/directive/model.spec.js +1905 -0
  186. package/test/ng/directive/non-bindable.spec.js +55 -0
  187. package/test/ng/directive/options.spec.js +3583 -0
  188. package/test/ng/directive/ref.spec.js +575 -0
  189. package/test/ng/directive/repeat.spec.js +1675 -0
  190. package/test/ng/directive/script.spec.js +52 -0
  191. package/test/ng/directive/scrset.spec.js +67 -0
  192. package/test/ng/directive/select.spec.js +2541 -0
  193. package/test/ng/directive/show-hide.spec.js +253 -0
  194. package/test/ng/directive/src.spec.js +157 -0
  195. package/test/ng/directive/style.spec.js +178 -0
  196. package/test/ng/directive/switch.spec.js +647 -0
  197. package/test/ng/directive/validators.spec.js +717 -0
  198. package/test/ng/document.spec.js +52 -0
  199. package/test/ng/filter/filter.spec.js +714 -0
  200. package/test/ng/filter/filters.spec.js +35 -0
  201. package/test/ng/filter/limit-to.spec.js +251 -0
  202. package/test/ng/filter/order-by.spec.js +891 -0
  203. package/test/ng/filter.spec.js +149 -0
  204. package/test/ng/http-backend.spec.js +398 -0
  205. package/test/ng/http.spec.js +4071 -0
  206. package/test/ng/interpolate.spec.js +642 -0
  207. package/test/ng/interval.spec.js +343 -0
  208. package/test/ng/location.spec.js +3488 -0
  209. package/test/ng/on.spec.js +229 -0
  210. package/test/ng/parse.spec.js +4655 -0
  211. package/test/ng/prop.spec.js +805 -0
  212. package/test/ng/q.spec.js +2904 -0
  213. package/test/ng/root-element.spec.js +16 -0
  214. package/test/ng/sanitize-uri.spec.js +249 -0
  215. package/test/ng/sce.spec.js +660 -0
  216. package/test/ng/scope.spec.js +3442 -0
  217. package/test/ng/template-request.spec.js +236 -0
  218. package/test/ng/timeout.spec.js +351 -0
  219. package/test/ng/url-utils.spec.js +156 -0
  220. package/test/ng/utils.spec.js +144 -0
  221. package/test/original-test.html +21 -0
  222. package/test/public.spec.js +34 -0
  223. package/test/sanitize/bing-html.spec.js +36 -0
  224. package/test/server/express.js +158 -0
  225. package/test/test-utils.js +11 -0
  226. package/tsconfig.json +17 -0
  227. package/types/angular.d.ts +138 -0
  228. package/types/global.d.ts +9 -0
  229. package/types/index.d.ts +2357 -0
  230. package/types/jqlite.d.ts +558 -0
  231. package/vite.config.js +14 -0
@@ -0,0 +1,647 @@
1
+ import { publishExternalAPI } from "../../../src/public";
2
+ import { createInjector } from "../../../src/injector";
3
+ import { dealoc } from "../../../src/jqLite";
4
+
5
+ describe("ngSwitch", () => {
6
+ let $scope;
7
+ let $compile;
8
+ let element;
9
+ let $timeout;
10
+
11
+ beforeEach(() => {
12
+ publishExternalAPI();
13
+ createInjector(["ng"]).invoke(($rootScope, _$compile_, _$timeout_) => {
14
+ $scope = $rootScope.$new();
15
+ $compile = _$compile_;
16
+ $timeout = _$timeout_;
17
+ });
18
+ });
19
+
20
+ afterEach(() => {
21
+ dealoc(element);
22
+ });
23
+
24
+ it("should switch on value change", () => {
25
+ element = $compile(
26
+ '<div ng-switch="select">' +
27
+ '<div ng-switch-when="1">first:{{name}}</div>' +
28
+ '<div ng-switch-when="2">second:{{name}}</div>' +
29
+ '<div ng-switch-when="true">true:{{name}}</div>' +
30
+ "</div>",
31
+ )($scope);
32
+ expect(element[0].innerHTML).toEqual(
33
+ "<!-- ngSwitchWhen: 1 --><!-- ngSwitchWhen: 2 --><!-- ngSwitchWhen: true -->",
34
+ );
35
+ $scope.select = 1;
36
+ $scope.$apply();
37
+ expect(element.text()).toEqual("first:");
38
+ $scope.name = "shyam";
39
+ $scope.$apply();
40
+ expect(element.text()).toEqual("first:shyam");
41
+ $scope.select = 2;
42
+ $scope.$apply();
43
+ expect(element.text()).toEqual("second:shyam");
44
+ $scope.name = "misko";
45
+ $scope.$apply();
46
+ expect(element.text()).toEqual("second:misko");
47
+ $scope.select = true;
48
+ $scope.$apply();
49
+ expect(element.text()).toEqual("true:misko");
50
+ });
51
+
52
+ it("should show all switch-whens that match the current value", () => {
53
+ element = $compile(
54
+ '<ul ng-switch="select">' +
55
+ '<li ng-switch-when="1">first:{{name}}</li>' +
56
+ '<li ng-switch-when="1">, first too:{{name}}</li>' +
57
+ '<li ng-switch-when="2">second:{{name}}</li>' +
58
+ '<li ng-switch-when="true">true:{{name}}</li>' +
59
+ "</ul>",
60
+ )($scope);
61
+ expect(element[0].innerHTML).toEqual(
62
+ "<!-- ngSwitchWhen: 1 -->" +
63
+ "<!-- ngSwitchWhen: 1 -->" +
64
+ "<!-- ngSwitchWhen: 2 -->" +
65
+ "<!-- ngSwitchWhen: true -->",
66
+ );
67
+ $scope.select = 1;
68
+ $scope.$apply();
69
+ expect(element.text()).toEqual("first:, first too:");
70
+ $scope.name = "shyam";
71
+ $scope.$apply();
72
+ expect(element.text()).toEqual("first:shyam, first too:shyam");
73
+
74
+ $scope.select = 2;
75
+ $scope.$apply();
76
+ expect(element.text()).toEqual("second:shyam");
77
+ $scope.name = "misko";
78
+ $scope.$apply();
79
+ expect(element.text()).toEqual("second:misko");
80
+
81
+ $scope.select = true;
82
+ $scope.$apply();
83
+ expect(element.text()).toEqual("true:misko");
84
+ });
85
+
86
+ it("should show all elements between start and end markers that match the current value", () => {
87
+ element = $compile(
88
+ '<ul ng-switch="select">' +
89
+ '<li ng-switch-when-start="1">A</li>' +
90
+ "<li>B</li>" +
91
+ "<li ng-switch-when-end>C</li>" +
92
+ '<li ng-switch-when-start="2">D</li>' +
93
+ "<li>E</li>" +
94
+ "<li ng-switch-when-end>F</li>" +
95
+ "</ul>",
96
+ )($scope);
97
+
98
+ $scope.$apply('select = "1"');
99
+ expect(element.find("li").length).toBe(3);
100
+ expect(element.find("li").eq(0).text()).toBe("A");
101
+ expect(element.find("li").eq(1).text()).toBe("B");
102
+ expect(element.find("li").eq(2).text()).toBe("C");
103
+
104
+ $scope.$apply('select = "2"');
105
+ expect(element.find("li").length).toBe(3);
106
+ expect(element.find("li").eq(0).text()).toBe("D");
107
+ expect(element.find("li").eq(1).text()).toBe("E");
108
+ expect(element.find("li").eq(2).text()).toBe("F");
109
+ });
110
+
111
+ it("should switch on switch-when-default", () => {
112
+ element = $compile(
113
+ '<ng:switch on="select">' +
114
+ '<div ng:switch-when="1">one</div>' +
115
+ "<div ng:switch-default>other</div>" +
116
+ "</ng:switch>",
117
+ )($scope);
118
+ $scope.$apply();
119
+ expect(element.text()).toEqual("other");
120
+ $scope.select = 1;
121
+ $scope.$apply();
122
+ expect(element.text()).toEqual("one");
123
+ });
124
+
125
+ it("should show all default elements between start and end markers when no match", () => {
126
+ element = $compile(
127
+ '<ul ng-switch="select">' +
128
+ '<li ng-switch-when-start="1">A</li>' +
129
+ "<li>B</li>" +
130
+ "<li ng-switch-when-end>C</li>" +
131
+ "<li ng-switch-default-start>D</li>" +
132
+ "<li>E</li>" +
133
+ "<li ng-switch-default-end>F</li>" +
134
+ "</ul>",
135
+ )($scope);
136
+
137
+ $scope.$apply('select = "1"');
138
+ expect(element.find("li").length).toBe(3);
139
+ expect(element.find("li").eq(0).text()).toBe("A");
140
+ expect(element.find("li").eq(1).text()).toBe("B");
141
+ expect(element.find("li").eq(2).text()).toBe("C");
142
+
143
+ $scope.$apply('select = "2"');
144
+ expect(element.find("li").length).toBe(3);
145
+ expect(element.find("li").eq(0).text()).toBe("D");
146
+ expect(element.find("li").eq(1).text()).toBe("E");
147
+ expect(element.find("li").eq(2).text()).toBe("F");
148
+ });
149
+
150
+ it("should show all switch-when-default", () => {
151
+ element = $compile(
152
+ '<ul ng-switch="select">' +
153
+ '<li ng-switch-when="1">one</li>' +
154
+ "<li ng-switch-default>other</li>" +
155
+ "<li ng-switch-default>, other too</li>" +
156
+ "</ul>",
157
+ )($scope);
158
+ $scope.$apply();
159
+ expect(element.text()).toEqual("other, other too");
160
+ $scope.select = 1;
161
+ $scope.$apply();
162
+ expect(element.text()).toEqual("one");
163
+ });
164
+
165
+ it("should always display the elements that do not match a switch", () => {
166
+ element = $compile(
167
+ '<ul ng-switch="select">' +
168
+ "<li>always </li>" +
169
+ '<li ng-switch-when="1">one </li>' +
170
+ '<li ng-switch-when="2">two </li>' +
171
+ "<li ng-switch-default>other, </li>" +
172
+ "<li ng-switch-default>other too </li>" +
173
+ "</ul>",
174
+ )($scope);
175
+ $scope.$apply();
176
+ expect(element.text()).toEqual("always other, other too ");
177
+ $scope.select = 1;
178
+ $scope.$apply();
179
+ expect(element.text()).toEqual("always one ");
180
+ });
181
+
182
+ it(
183
+ "should display the elements that do not have ngSwitchWhen nor " +
184
+ "ngSwitchDefault at the position specified in the template, when the " +
185
+ "first and last elements in the ngSwitch body do not have a ngSwitch* " +
186
+ "directive",
187
+ () => {
188
+ element = $compile(
189
+ '<ul ng-switch="select">' +
190
+ "<li>1</li>" +
191
+ '<li ng-switch-when="1">2</li>' +
192
+ "<li>3</li>" +
193
+ '<li ng-switch-when="2">4</li>' +
194
+ "<li ng-switch-default>5</li>" +
195
+ "<li>6</li>" +
196
+ "<li ng-switch-default>7</li>" +
197
+ "<li>8</li>" +
198
+ "</ul>",
199
+ )($scope);
200
+ $scope.$apply();
201
+ expect(element.text()).toEqual("135678");
202
+ $scope.select = 1;
203
+ $scope.$apply();
204
+ expect(element.text()).toEqual("12368");
205
+ },
206
+ );
207
+
208
+ it(
209
+ "should display the elements that do not have ngSwitchWhen nor " +
210
+ "ngSwitchDefault at the position specified in the template when the " +
211
+ "first and last elements in the ngSwitch have a ngSwitch* directive",
212
+ () => {
213
+ element = $compile(
214
+ '<ul ng-switch="select">' +
215
+ '<li ng-switch-when="1">2</li>' +
216
+ "<li>3</li>" +
217
+ '<li ng-switch-when="2">4</li>' +
218
+ "<li ng-switch-default>5</li>" +
219
+ "<li>6</li>" +
220
+ "<li ng-switch-default>7</li>" +
221
+ "</ul>",
222
+ )($scope);
223
+ $scope.$apply();
224
+ expect(element.text()).toEqual("3567");
225
+ $scope.select = 1;
226
+ $scope.$apply();
227
+ expect(element.text()).toEqual("236");
228
+ },
229
+ );
230
+
231
+ it("should properly create and destroy child scopes", () => {
232
+ element = $compile(
233
+ '<ng:switch on="url">' +
234
+ '<div ng-switch-when="a">{{name}}</div>' +
235
+ "</ng:switch>",
236
+ )($scope);
237
+ $scope.$apply();
238
+
239
+ const getChildScope = function () {
240
+ return element.find("div").scope();
241
+ };
242
+
243
+ expect(getChildScope()).toBeUndefined();
244
+
245
+ $scope.url = "a";
246
+ $scope.$apply();
247
+ const child1 = getChildScope();
248
+ expect(child1).toBeDefined();
249
+ spyOn(child1, "$destroy");
250
+
251
+ $scope.url = "x";
252
+ $scope.$apply();
253
+ expect(getChildScope()).toBeUndefined();
254
+ expect(child1.$destroy).toHaveBeenCalled();
255
+
256
+ $scope.url = "a";
257
+ $scope.$apply();
258
+ const child2 = getChildScope();
259
+ expect(child2).toBeDefined();
260
+ expect(child2).not.toBe(child1);
261
+ });
262
+
263
+ it("should interoperate with other transclusion directives like ngRepeat", () => {
264
+ element = $compile(
265
+ '<div ng-switch="value">' +
266
+ '<div ng-switch-when="foo" ng-repeat="foo in foos">{{value}}:{{foo}}|</div>' +
267
+ '<div ng-switch-default ng-repeat="bar in bars">{{value}}:{{bar}}|</div>' +
268
+ "</div>",
269
+ )($scope);
270
+ $scope.$apply('value="foo";foos=["one", "two"]');
271
+ expect(element.text()).toEqual("foo:one|foo:two|");
272
+
273
+ $scope.$apply('value="foo";foos=["one"]');
274
+ expect(element.text()).toEqual("foo:one|");
275
+
276
+ $scope.$apply('value="foo";foos=["one","two","three"]');
277
+ expect(element.text()).toEqual("foo:one|foo:two|foo:three|");
278
+
279
+ $scope.$apply('value="bar";bars=["up", "down"]');
280
+ expect(element.text()).toEqual("bar:up|bar:down|");
281
+
282
+ $scope.$apply('value="bar";bars=["up", "down", "forwards", "backwards"]');
283
+ expect(element.text()).toEqual(
284
+ "bar:up|bar:down|bar:forwards|bar:backwards|",
285
+ );
286
+ });
287
+
288
+ it("should not leak jq data when compiled but not attached to parent when parent is destroyed", () => {
289
+ element = $compile(
290
+ '<div ng-repeat="i in []">' +
291
+ '<ng-switch on="url">' +
292
+ '<div ng-switch-when="a">{{name}}</div>' +
293
+ "</ng-switch>" +
294
+ "</div>",
295
+ )($scope);
296
+ $scope.$apply();
297
+
298
+ // element now contains only empty repeater. this element is deallocated by local afterEach.
299
+ // afterwards a global afterEach will check for leaks in jq data cache object
300
+ });
301
+
302
+ it("should properly support case labels with different numbers of transclude fns", () => {
303
+ element = $compile(
304
+ '<div ng-switch="mode">' +
305
+ '<p ng-switch-when="a">Block1</p>' +
306
+ '<p ng-switch-when="a">Block2</p>' +
307
+ '<a href ng-switch-when="b">a</a>' +
308
+ "</div>",
309
+ )($scope);
310
+
311
+ $scope.$apply('mode = "a"');
312
+ expect(element.children().length).toBe(2);
313
+
314
+ $scope.$apply('mode = "b"');
315
+ expect(element.children().length).toBe(1);
316
+
317
+ $scope.$apply('mode = "a"');
318
+ expect(element.children().length).toBe(2);
319
+
320
+ $scope.$apply('mode = "b"');
321
+ expect(element.children().length).toBe(1);
322
+ });
323
+
324
+ it("should not trigger a digest after an element is removed", () => {
325
+ const spy = spyOn($scope, "$digest").and.callThrough();
326
+
327
+ $scope.select = 1;
328
+ element = $compile(
329
+ '<div ng-switch="select">' +
330
+ '<div ng-switch-when="1">first</div>' +
331
+ '<div ng-switch-when="2">second</div>' +
332
+ "</div>",
333
+ )($scope);
334
+ $scope.$apply();
335
+
336
+ expect(element.text()).toEqual("first");
337
+
338
+ $scope.select = 2;
339
+ $scope.$apply();
340
+ spy.calls.reset();
341
+ expect(element.text()).toEqual("second");
342
+ // If ngSwitch re-introduces code that triggers a digest after an element is removed (in an
343
+ // animation .then callback), flushing the queue ensures the callback will be called, and the test
344
+ // fails
345
+
346
+ expect(spy).not.toHaveBeenCalled();
347
+ // A digest may have been triggered asynchronously, so check the queue
348
+ //$timeout.verifyNoPendingTasks();
349
+ });
350
+
351
+ it("should handle changes to the switch value in a digest loop with multiple value matches", () => {
352
+ const scope = $scope.$new();
353
+ scope.value = "foo";
354
+
355
+ scope.$watch("value", () => {
356
+ if (scope.value === "bar") {
357
+ scope.$evalAsync(() => {
358
+ scope.value = "baz";
359
+ });
360
+ }
361
+ });
362
+
363
+ element = $compile(
364
+ '<div ng-switch="value">' +
365
+ '<div ng-switch-when="foo">FOO 1</div>' +
366
+ '<div ng-switch-when="foo">FOO 2</div>' +
367
+ '<div ng-switch-when="bar">BAR</div>' +
368
+ '<div ng-switch-when="baz">BAZ</div>' +
369
+ "</div>",
370
+ )(scope);
371
+
372
+ scope.$apply();
373
+ expect(element.text()).toBe("FOO 1FOO 2");
374
+
375
+ scope.$apply('value = "bar"');
376
+ expect(element.text()).toBe("BAZ");
377
+ });
378
+
379
+ describe("ngSwitchWhen separator", () => {
380
+ it("should be possible to define a separator", () => {
381
+ element = $compile(
382
+ '<div ng-switch="mode">' +
383
+ '<p ng-switch-when="a|b" ng-switch-when-separator="|">Block1|</p>' +
384
+ '<p ng-switch-when="a">Block2|</p>' +
385
+ "<p ng-switch-default>Block3|</div>" +
386
+ "</div>",
387
+ )($scope);
388
+
389
+ $scope.$apply('mode = "a"');
390
+ expect(element.children().length).toBe(2);
391
+ expect(element.text()).toBe("Block1|Block2|");
392
+ $scope.$apply('mode = "b"');
393
+
394
+ expect(element.children().length).toBe(1);
395
+ expect(element.text()).toBe("Block1|");
396
+ $scope.$apply('mode = "c"');
397
+
398
+ expect(element.children().length).toBe(1);
399
+ expect(element.text()).toBe("Block3|");
400
+ });
401
+
402
+ it("should be possible to use a separator at the end of the value", () => {
403
+ element = $compile(
404
+ '<div ng-switch="mode">' +
405
+ '<p ng-switch-when="a|b|" ng-switch-when-separator="|">Block1|</p>' +
406
+ '<p ng-switch-when="a">Block2|</p>' +
407
+ "<p ng-switch-default>Block3|</div>" +
408
+ "</div>",
409
+ )($scope);
410
+
411
+ $scope.$apply('mode = "a"');
412
+ expect(element.children().length).toBe(2);
413
+ expect(element.text()).toBe("Block1|Block2|");
414
+ $scope.$apply('mode = ""');
415
+
416
+ expect(element.children().length).toBe(1);
417
+ expect(element.text()).toBe("Block1|");
418
+ $scope.$apply('mode = "c"');
419
+
420
+ expect(element.children().length).toBe(1);
421
+ expect(element.text()).toBe("Block3|");
422
+ });
423
+
424
+ it("should be possible to use the empty string as a separator", () => {
425
+ element = $compile(
426
+ '<div ng-switch="mode">' +
427
+ '<p ng-switch-when="ab" ng-switch-when-separator="">Block1|</p>' +
428
+ '<p ng-switch-when="a">Block2|</p>' +
429
+ "<p ng-switch-default>Block3|</div>" +
430
+ "</div>",
431
+ )($scope);
432
+
433
+ $scope.$apply('mode = "a"');
434
+ expect(element.children().length).toBe(2);
435
+ expect(element.text()).toBe("Block1|Block2|");
436
+ $scope.$apply('mode = "b"');
437
+
438
+ expect(element.children().length).toBe(1);
439
+ expect(element.text()).toBe("Block1|");
440
+ $scope.$apply('mode = "c"');
441
+
442
+ expect(element.children().length).toBe(1);
443
+ expect(element.text()).toBe("Block3|");
444
+ });
445
+
446
+ it("should be possible to use separators that are multiple characters long", () => {
447
+ element = $compile(
448
+ '<div ng-switch="mode">' +
449
+ '<p ng-switch-when="a||b|a" ng-switch-when-separator="||">Block1|</p>' +
450
+ '<p ng-switch-when="a">Block2|</p>' +
451
+ "<p ng-switch-default>Block3|</div>" +
452
+ "</div>",
453
+ )($scope);
454
+
455
+ $scope.$apply('mode = "a"');
456
+ expect(element.children().length).toBe(2);
457
+ expect(element.text()).toBe("Block1|Block2|");
458
+ $scope.$apply('mode = "b|a"');
459
+
460
+ expect(element.children().length).toBe(1);
461
+ expect(element.text()).toBe("Block1|");
462
+ $scope.$apply('mode = "c"');
463
+
464
+ expect(element.children().length).toBe(1);
465
+ expect(element.text()).toBe("Block3|");
466
+ });
467
+
468
+ it("should ignore multiple appearances of the same item", () => {
469
+ element = $compile(
470
+ '<div ng-switch="mode">' +
471
+ '<p ng-switch-when="a|b|a" ng-switch-when-separator="|">Block1|</p>' +
472
+ '<p ng-switch-when="a">Block2|</p>' +
473
+ "<p ng-switch-default>Block3|</div>" +
474
+ "</div>",
475
+ )($scope);
476
+
477
+ $scope.$apply('mode = "a"');
478
+ expect(element.children().length).toBe(2);
479
+ expect(element.text()).toBe("Block1|Block2|");
480
+ $scope.$apply('mode = "b"');
481
+
482
+ expect(element.children().length).toBe(1);
483
+ expect(element.text()).toBe("Block1|");
484
+ $scope.$apply('mode = "c"');
485
+
486
+ expect(element.children().length).toBe(1);
487
+ expect(element.text()).toBe("Block3|");
488
+ });
489
+ });
490
+ });
491
+
492
+ // describe("ngSwitch animation", () => {
493
+ // let body;
494
+ // let element;
495
+ // let $rootElement;
496
+
497
+ // function html(content) {
498
+ // $rootElement[0].innerHTML = content;
499
+ // element = $rootElement.children().eq(0);
500
+ // return element;
501
+ // }
502
+
503
+ // beforeEach(
504
+ // module(
505
+ // () =>
506
+ // // we need to run animation on attached elements;
507
+ // function (_$rootElement_) {
508
+ // $rootElement = _$rootElement_;
509
+ // body = jqLite(window.document.body);
510
+ // body.append($rootElement);
511
+ // },
512
+ // ),
513
+ // );
514
+
515
+ // afterEach(() => {
516
+ // dealoc(body);
517
+ // dealoc(element);
518
+ // });
519
+
520
+ // describe("behavior", () => {
521
+ // it("should destroy the previous leave animation if a new one takes place", () => {
522
+ // module("ngAnimate");
523
+ // module(($animateProvider) => {
524
+ // $animateProvider.register(".long-leave", () => ({
525
+ // leave(element, done) {
526
+ // // do nothing at all
527
+ // },
528
+ // }));
529
+ // });
530
+ // () => {
531
+ // // inejct $compile, $scope, $animate, $templateCache
532
+ // let item;
533
+ // const $scope = $rootScope.$new();
534
+ // element = $compile(
535
+ // html(
536
+ // '<div ng-switch="inc">' +
537
+ // '<div ng-switch-when="one">one</div>' +
538
+ // '<div ng-switch-when="two">two</div>' +
539
+ // "</div>",
540
+ // ),
541
+ // )($scope);
542
+
543
+ // $scope.$apply('inc = "one"');
544
+
545
+ // let destroyed;
546
+ // const inner = element.children(0);
547
+ // inner.on("$destroy", () => {
548
+ // destroyed = true;
549
+ // });
550
+
551
+ // $scope.$apply('inc = "two"');
552
+
553
+ // $scope.$apply('inc = "one"');
554
+
555
+ // expect(destroyed).toBe(true);
556
+ // };
557
+ // });
558
+ // });
559
+
560
+ // describe("events", () => {
561
+ // beforeEach(module("ngAnimateMock"));
562
+
563
+ // it("should fire off the enter animation", inject((
564
+ // $compile,
565
+ // $rootScope,
566
+ // $animate,
567
+ // ) => {
568
+ // let item;
569
+ // const $scope = $rootScope.$new();
570
+ // element = $compile(
571
+ // html(
572
+ // '<div ng-switch on="val">' +
573
+ // '<div ng-switch-when="one">one</div>' +
574
+ // '<div ng-switch-when="two">two</div>' +
575
+ // '<div ng-switch-when="three">three</div>' +
576
+ // "</div>",
577
+ // ),
578
+ // )($scope);
579
+
580
+ // $rootScope.$digest(); // re-enable the animations;
581
+ // $scope.val = "one";
582
+ // $scope.$digest();
583
+
584
+ // item = $animate.queue.shift();
585
+ // expect(item.event).toBe("enter");
586
+ // expect(item.element.text()).toBe("one");
587
+ // }));
588
+
589
+ // it("should fire off the leave animation", inject((
590
+ // $compile,
591
+ // $rootScope,
592
+ // $animate,
593
+ // ) => {
594
+ // let item;
595
+ // const $scope = $rootScope.$new();
596
+ // element = $compile(
597
+ // html(
598
+ // '<div ng-switch on="val">' +
599
+ // '<div ng-switch-when="one">one</div>' +
600
+ // '<div ng-switch-when="two">two</div>' +
601
+ // '<div ng-switch-when="three">three</div>' +
602
+ // "</div>",
603
+ // ),
604
+ // )($scope);
605
+
606
+ // $rootScope.$digest(); // re-enable the animations;
607
+ // $scope.val = "two";
608
+ // $scope.$digest();
609
+
610
+ // item = $animate.queue.shift();
611
+ // expect(item.event).toBe("enter");
612
+ // expect(item.element.text()).toBe("two");
613
+
614
+ // $scope.val = "three";
615
+ // $scope.$digest();
616
+
617
+ // item = $animate.queue.shift();
618
+ // expect(item.event).toBe("leave");
619
+ // expect(item.element.text()).toBe("two");
620
+
621
+ // item = $animate.queue.shift();
622
+ // expect(item.event).toBe("enter");
623
+ // expect(item.element.text()).toBe("three");
624
+ // }));
625
+
626
+ // it("should work with svg elements when the svg container is transcluded", () => {
627
+ // module(($compileProvider) => {
628
+ // $compileProvider.directive("svgContainer", () => ({
629
+ // template: "<svg ng-transclude></svg>",
630
+ // replace: true,
631
+ // transclude: true,
632
+ // }));
633
+ // });
634
+ // inject(($compile, $rootScope) => {
635
+ // element = $compile(
636
+ // '<svg-container ng-switch="inc"><circle ng-switch-when="one"></circle>' +
637
+ // "</svg-container>",
638
+ // )($rootScope);
639
+ // $rootScope.inc = "one";
640
+ // $rootScope.$apply();
641
+
642
+ // const circle = element.find("circle");
643
+ // expect(circle[0].toString()).toMatch(/SVG/);
644
+ // });
645
+ // });
646
+ // });
647
+ // });