@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,253 @@
1
+ import { publishExternalAPI } from "../../../src/public";
2
+ import { createInjector } from "../../../src/injector";
3
+ import { dealoc, jqLite } from "../../../src/jqLite";
4
+
5
+ describe("ngShow / ngHide", () => {
6
+ let $scope;
7
+ let $compile;
8
+ let element;
9
+
10
+ beforeEach(() => {
11
+ publishExternalAPI();
12
+ createInjector(["ng"]).invoke(($rootScope, _$compile_) => {
13
+ $scope = $rootScope.$new();
14
+ $compile = _$compile_;
15
+ });
16
+ });
17
+
18
+ afterEach(() => {
19
+ dealoc(element);
20
+ });
21
+
22
+ describe("ngShow", () => {
23
+ it("should show and hide an element", () => {
24
+ element = jqLite('<div ng-show="exp"></div>');
25
+ element = $compile(element)($scope);
26
+ $scope.$digest();
27
+ expect(element[0].classList.contains("ng-hide")).toBeTrue();
28
+ $scope.exp = true;
29
+ $scope.$digest();
30
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
31
+ });
32
+
33
+ // https://github.com/angular/angular.js/issues/5414
34
+ it("should show if the expression is a function with a no arguments", () => {
35
+ element = jqLite('<div ng-show="exp"></div>');
36
+ element = $compile(element)($scope);
37
+ $scope.exp = function () {};
38
+ $scope.$digest();
39
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
40
+ });
41
+
42
+ it("should make hidden element visible", () => {
43
+ element = jqLite('<div class="ng-hide" ng-show="exp"></div>');
44
+ element = $compile(element)($scope);
45
+ expect(element[0].classList.contains("ng-hide")).toBeTrue();
46
+ $scope.exp = true;
47
+ $scope.$digest();
48
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
49
+ });
50
+
51
+ it("should hide the element if condition is falsy", () => {
52
+ ["false", "undefined", "null", "NaN", "''", "0"].forEach((x) => {
53
+ element = jqLite(`<div ng-show="${x}"></div>`);
54
+ element = $compile(element)($scope);
55
+ $scope.$digest();
56
+ expect(element[0].classList.contains("ng-hide")).toBeTrue();
57
+ });
58
+ });
59
+
60
+ it("should show the element if condition is a non-empty string", () => {
61
+ ["'f'", "'0'", "'false'", "'no'", "'n'", "'[]'"].forEach((x) => {
62
+ element = jqLite(`<div ng-show="${x}"></div>`);
63
+ element = $compile(element)($scope);
64
+ $scope.$digest();
65
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
66
+ });
67
+ });
68
+
69
+ it("should show the element if condition is an object", () => {
70
+ ["[]", "{}"].forEach((x) => {
71
+ element = jqLite(`<div ng-show="${x}"></div>`);
72
+ element = $compile(element)($scope);
73
+ $scope.$digest();
74
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
75
+ });
76
+ });
77
+ });
78
+
79
+ describe("ngHide", () => {
80
+ it("should hide an element", () => {
81
+ element = jqLite('<div ng-hide="exp"></div>');
82
+ element = $compile(element)($scope);
83
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
84
+ $scope.exp = true;
85
+ $scope.$digest();
86
+ expect(element[0].classList.contains("ng-hide")).toBeTrue();
87
+ });
88
+
89
+ it("should show the element if condition is falsy", () => {
90
+ ["false", "undefined", "null", "NaN", "''", "0"].forEach((x) => {
91
+ element = jqLite(`<div ng-hide="${x}"></div>`);
92
+ element = $compile(element)($scope);
93
+ $scope.$digest();
94
+ expect(element[0].classList.contains("ng-hide")).toBeFalse();
95
+ });
96
+ });
97
+
98
+ it("should hide the element if condition is a non-empty string", () => {
99
+ ["'f'", "'0'", "'false'", "'no'", "'n'", "'[]'"].forEach((x) => {
100
+ element = jqLite(`<div ng-hide="${x}"></div>`);
101
+ element = $compile(element)($scope);
102
+ $scope.$digest();
103
+ expect(element[0].classList.contains("ng-hide")).toBeTrue();
104
+ });
105
+ });
106
+
107
+ it("should hide the element if condition is an object", () => {
108
+ ["[]", "{}"].forEach((x) => {
109
+ element = jqLite(`<div ng-hide="${x}"></div>`);
110
+ element = $compile(element)($scope);
111
+ $scope.$digest();
112
+ expect(element[0].classList.contains("ng-hide")).toBeTrue();
113
+ });
114
+ });
115
+ });
116
+ });
117
+
118
+ // describe("ngShow / ngHide animations", () => {
119
+ // let body;
120
+ // let element;
121
+ // let $rootElement;
122
+
123
+ // function html(content) {
124
+ // body.append($rootElement);
125
+ // $rootElement.html(content);
126
+ // element = $rootElement.children().eq(0);
127
+ // return element;
128
+ // }
129
+
130
+ // beforeEach(() => {
131
+ // // we need to run animation on attached elements;
132
+ // body = jqLite(window.document.body);
133
+ // });
134
+
135
+ // afterEach(() => {
136
+ // dealoc(body);
137
+ // dealoc(element);
138
+ // body[0].removeAttribute("ng-animation-running");
139
+ // });
140
+
141
+ // beforeEach(module("ngAnimateMock"));
142
+
143
+ // beforeEach(
144
+ // module(
145
+ // ($animateProvider, $provide) =>
146
+ // function (_$rootElement_) {
147
+ // $rootElement = _$rootElement_;
148
+ // },
149
+ // ),
150
+ // );
151
+
152
+ // describe("ngShow", () => {
153
+ // it("should fire off the $animate.show and $animate.hide animation", inject((
154
+ // $compile,
155
+ // $rootScope,
156
+ // $animate,
157
+ // ) => {
158
+ // let item;
159
+ // const $scope = $rootScope.$new();
160
+ // $scope.on = true;
161
+ // element = $compile(html('<div ng-show="on">data</div>'))($scope);
162
+ // $scope.$digest();
163
+
164
+ // item = $animate.queue.shift();
165
+ // expect(item.event).toBe("removeClass");
166
+ // expect(item.element.text()).toBe("data");
167
+ // expect(item.element).toBeShown();
168
+
169
+ // $scope.on = false;
170
+ // $scope.$digest();
171
+
172
+ // item = $animate.queue.shift();
173
+ // expect(item.event).toBe("addClass");
174
+ // expect(item.element.text()).toBe("data");
175
+ // expect(item.element).toBeHidden();
176
+ // }));
177
+
178
+ // it("should apply the temporary `.ng-hide-animate` class to the element", inject((
179
+ // $compile,
180
+ // $rootScope,
181
+ // $animate,
182
+ // ) => {
183
+ // let item;
184
+ // const $scope = $rootScope.$new();
185
+ // $scope.on = false;
186
+ // element = $compile(
187
+ // html('<div class="show-hide" ng-show="on">data</div>'),
188
+ // )($scope);
189
+ // $scope.$digest();
190
+
191
+ // item = $animate.queue.shift();
192
+ // expect(item.event).toEqual("addClass");
193
+ // expect(item.options.tempClasses).toEqual("ng-hide-animate");
194
+
195
+ // $scope.on = true;
196
+ // $scope.$digest();
197
+ // item = $animate.queue.shift();
198
+ // expect(item.event).toEqual("removeClass");
199
+ // expect(item.options.tempClasses).toEqual("ng-hide-animate");
200
+ // }));
201
+ // });
202
+
203
+ // describe("ngHide", () => {
204
+ // it("should fire off the $animate.show and $animate.hide animation", inject((
205
+ // $compile,
206
+ // $rootScope,
207
+ // $animate,
208
+ // ) => {
209
+ // let item;
210
+ // const $scope = $rootScope.$new();
211
+ // $scope.off = true;
212
+ // element = $compile(html('<div ng-hide="off">datum</div>'))($scope);
213
+ // $scope.$digest();
214
+
215
+ // item = $animate.queue.shift();
216
+ // expect(item.event).toBe("addClass");
217
+ // expect(item.element.text()).toBe("datum");
218
+ // expect(item.element).toBeHidden();
219
+
220
+ // $scope.off = false;
221
+ // $scope.$digest();
222
+
223
+ // item = $animate.queue.shift();
224
+ // expect(item.event).toBe("removeClass");
225
+ // expect(item.element.text()).toBe("datum");
226
+ // expect(item.element).toBeShown();
227
+ // }));
228
+
229
+ // it("should apply the temporary `.ng-hide-animate` class to the element", inject((
230
+ // $compile,
231
+ // $rootScope,
232
+ // $animate,
233
+ // ) => {
234
+ // let item;
235
+ // const $scope = $rootScope.$new();
236
+ // $scope.on = false;
237
+ // element = $compile(
238
+ // html('<div class="show-hide" ng-hide="on">data</div>'),
239
+ // )($scope);
240
+ // $scope.$digest();
241
+
242
+ // item = $animate.queue.shift();
243
+ // expect(item.event).toEqual("removeClass");
244
+ // expect(item.options.tempClasses).toEqual("ng-hide-animate");
245
+
246
+ // $scope.on = true;
247
+ // $scope.$digest();
248
+ // item = $animate.queue.shift();
249
+ // expect(item.event).toEqual("addClass");
250
+ // expect(item.options.tempClasses).toEqual("ng-hide-animate");
251
+ // }));
252
+ // });
253
+ // });
@@ -0,0 +1,157 @@
1
+ import { publishExternalAPI } from "../../../src/public";
2
+ import { createInjector } from "../../../src/injector";
3
+ import { dealoc } from "../../../src/jqLite";
4
+
5
+ describe("ngSrc", () => {
6
+ let $scope;
7
+ let $compile;
8
+ let element;
9
+
10
+ beforeEach(() => {
11
+ publishExternalAPI();
12
+ createInjector(["ng"]).invoke(($rootScope, _$compile_) => {
13
+ $scope = $rootScope.$new();
14
+ $compile = _$compile_;
15
+ });
16
+ });
17
+
18
+ afterEach(() => {
19
+ dealoc(element);
20
+ });
21
+
22
+ describe("img[ng-src]", () => {
23
+ it("should not result empty string in img src", () => {
24
+ $scope.image = {};
25
+ element = $compile('<img ng-src="{{image.url}}">')($scope);
26
+ $scope.$digest();
27
+ expect(element.attr("src")).not.toBe("");
28
+ expect(element.attr("src")).toBeUndefined();
29
+ });
30
+
31
+ it("should sanitize interpolated url", () => {
32
+ $scope.imageUrl = "javascript:alert(1);";
33
+ element = $compile('<img ng-src="{{imageUrl}}">')($scope);
34
+ $scope.$digest();
35
+ expect(element.attr("src")).toBe("unsafe:javascript:alert(1);");
36
+ });
37
+
38
+ it("should sanitize non-interpolated url", () => {
39
+ element = $compile('<img ng-src="javascript:alert(1);">')($scope);
40
+ $scope.$digest();
41
+ expect(element.attr("src")).toBe("unsafe:javascript:alert(1);");
42
+ });
43
+
44
+ it("should interpolate the expression and bind to src with raw same-domain value", () => {
45
+ element = $compile('<img ng-src="{{id}}"></img>')($scope);
46
+
47
+ $scope.$digest();
48
+ expect(element.attr("src")).toBeUndefined();
49
+
50
+ $scope.$apply(() => {
51
+ $scope.id = "/somewhere/here";
52
+ });
53
+ expect(element.attr("src")).toEqual("/somewhere/here");
54
+ });
55
+
56
+ it("should interpolate a multi-part expression for img src attribute (which requires the MEDIA_URL context)", () => {
57
+ element = $compile('<img ng-src="some/{{id}}"></img>')($scope);
58
+ expect(element.attr("src")).toBe(undefined); // URL concatenations are all-or-nothing
59
+ $scope.$apply(() => {
60
+ $scope.id = 1;
61
+ });
62
+ expect(element.attr("src")).toEqual("some/1");
63
+ });
64
+
65
+ it("should work with `src` attribute on the same element", () => {
66
+ $scope.imageUrl = "dynamic";
67
+ element = $compile('<img ng-src="{{imageUrl}}" src="static">')($scope);
68
+ expect(element.attr("src")).toBe("static");
69
+ $scope.$digest();
70
+ expect(element.attr("src")).toBe("dynamic");
71
+ dealoc(element);
72
+
73
+ element = $compile('<img src="static" ng-src="{{imageUrl}}">')($scope);
74
+ expect(element.attr("src")).toBe("static");
75
+ $scope.$digest();
76
+ expect(element.attr("src")).toBe("dynamic");
77
+ });
78
+ });
79
+
80
+ describe("iframe[ng-src]", () => {
81
+ let $scope;
82
+ let $compile;
83
+ let element;
84
+ let $sce;
85
+
86
+ beforeEach(() => {
87
+ publishExternalAPI();
88
+ createInjector(["ng"]).invoke(($rootScope, _$compile_, _$sce_) => {
89
+ $scope = $rootScope.$new();
90
+ $compile = _$compile_;
91
+ $sce = _$sce_;
92
+ });
93
+ });
94
+
95
+ afterEach(() => {
96
+ dealoc(element);
97
+ });
98
+
99
+ it("should pass through src attributes for the same domain", () => {
100
+ element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($scope);
101
+ $scope.testUrl = "different_page";
102
+ $scope.$apply();
103
+ expect(element.attr("src")).toEqual("different_page");
104
+ });
105
+
106
+ it("should error on src attributes for a different domain", () => {
107
+ element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($scope);
108
+ $scope.testUrl = "http://a.different.domain.example.com";
109
+ $scope.$apply();
110
+ expect($scope.$apply).toThrowError();
111
+ });
112
+
113
+ it("should error on JS src attributes", () => {
114
+ element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($scope);
115
+ $scope.testUrl = "javascript:alert(1);";
116
+ expect($scope.$apply).toThrowError();
117
+ });
118
+
119
+ it("should error on non-resource_url src attributes", () => {
120
+ element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($scope);
121
+ $scope.testUrl = $sce.trustAsUrl("javascript:doTrustedStuff()");
122
+ expect($scope.$apply).toThrowError();
123
+ });
124
+
125
+ it("should pass through $sce.trustAs() values in src attributes", () => {
126
+ element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($scope);
127
+ $scope.testUrl = $sce.trustAsResourceUrl("javascript:doTrustedStuff()");
128
+ $scope.$apply();
129
+
130
+ expect(element.attr("src")).toEqual("javascript:doTrustedStuff()");
131
+ });
132
+
133
+ it("should interpolate the expression and bind to src with a trusted value", () => {
134
+ element = $compile('<iframe ng-src="{{id}}"></iframe>')($scope);
135
+
136
+ $scope.$digest();
137
+ expect(element.attr("src")).toBeUndefined();
138
+
139
+ $scope.$apply(() => {
140
+ $scope.id = $sce.trustAsResourceUrl("http://somewhere");
141
+ });
142
+ expect(element.attr("src")).toEqual("http://somewhere");
143
+ });
144
+
145
+ it("should NOT interpolate a multi-part expression in a `src` attribute that requires a non-MEDIA_URL context", () => {
146
+ element = $compile('<iframe ng-src="some/{{id}}"></iframe>')($scope);
147
+ $scope.id = 1;
148
+ expect($scope.$apply).toThrowError();
149
+ });
150
+
151
+ it("should NOT interpolate a wrongly typed expression", () => {
152
+ element = $compile('<iframe ng-src="{{id}}"></iframe>')($scope);
153
+ $scope.id = $sce.trustAsUrl("http://somewhere");
154
+ expect($scope.$apply).toThrowError();
155
+ });
156
+ });
157
+ });
@@ -0,0 +1,178 @@
1
+ import { publishExternalAPI } from "../../../src/public";
2
+ import { createInjector } from "../../../src/injector";
3
+ import { dealoc, jqLite } from "../../../src/jqLite";
4
+
5
+ describe("ng-style", () => {
6
+ let $scope;
7
+ let $compile;
8
+ let element;
9
+
10
+ beforeEach(() => {
11
+ publishExternalAPI();
12
+ createInjector(["ng"]).invoke(($rootScope, _$compile_) => {
13
+ $scope = $rootScope.$new();
14
+ $compile = _$compile_;
15
+ });
16
+ });
17
+
18
+ afterEach(() => {
19
+ dealoc(element);
20
+ });
21
+
22
+ it("should set", () => {
23
+ element = $compile("<div ng-style=\"{height: '40px'}\"></div>")($scope);
24
+ $scope.$digest();
25
+ expect(element[0].style.height).toEqual("40px");
26
+ });
27
+
28
+ it("should silently ignore undefined style", () => {
29
+ element = $compile('<div ng-style="myStyle"></div>')($scope);
30
+ $scope.$digest();
31
+ expect(element[0].classList.contains("ng-exception")).toBeFalsy();
32
+ });
33
+
34
+ it("should not deep watch objects", () => {
35
+ element = $compile('<div ng-style="{height: heightObj}"></div>')($scope);
36
+ $scope.$digest();
37
+ expect(parseInt(element[0].style.height + 0, 10)).toEqual(0); // height could be '' or '0px'
38
+ $scope.heightObj = {
39
+ toString() {
40
+ return "40px";
41
+ },
42
+ };
43
+ $scope.$digest();
44
+ expect(element[0].style.height).toBe("40px");
45
+
46
+ element[0].style.height = "10px";
47
+ $scope.heightObj.otherProp = 123;
48
+ $scope.$digest();
49
+ expect(element[0].style.height).toBe("10px");
50
+ });
51
+
52
+ it("should support binding for object literals", () => {
53
+ element = $compile('<div ng-style="{height: heightStr}"></div>')($scope);
54
+ $scope.$digest();
55
+ expect(parseInt(element[0].style.height + 0, 10)).toEqual(0); // height could be '' or '0px'
56
+ $scope.$apply('heightStr = "40px"');
57
+ expect(element[0].style.height).toBe("40px");
58
+
59
+ $scope.$apply('heightStr = "100px"');
60
+ expect(element[0].style.height).toBe("100px");
61
+ });
62
+
63
+ it("should support lazy one-time binding for object literals", () => {
64
+ element = $compile('<div ng-style="::{height: heightStr}"></div>')($scope);
65
+ $scope.$digest();
66
+ expect(parseInt(element[0].style.height + 0, 10)).toEqual(0); // height could be '' or '0px'
67
+ $scope.$apply('heightStr = "40px"');
68
+ expect(element[0].style.height).toBe("40px");
69
+ });
70
+
71
+ describe("preserving styles set before and after compilation", () => {
72
+ let scope;
73
+ let preCompStyle;
74
+ let preCompVal;
75
+ let postCompStyle;
76
+ let postCompVal;
77
+ let element;
78
+
79
+ beforeEach(() => {
80
+ preCompStyle = "width";
81
+ preCompVal = "300px";
82
+ postCompStyle = "height";
83
+ postCompVal = "100px";
84
+ element = jqLite('<div ng-style="styleObj"></div>');
85
+ element[0].style[preCompStyle] = preCompVal;
86
+ jqLite(window.document.body).append(element);
87
+ $compile(element)($scope);
88
+ scope = $scope;
89
+ scope.styleObj = { "margin-top": "44px" };
90
+ scope.$apply();
91
+ element[0].style[postCompStyle] = postCompVal;
92
+ });
93
+
94
+ afterEach(() => {
95
+ element.remove();
96
+ });
97
+
98
+ it("should not mess up stuff after compilation", () => {
99
+ element[0].style.margin = "44px";
100
+ expect(element[0].style[preCompStyle]).toBe(preCompVal);
101
+ expect(element[0].style["margin-top"]).toBe("44px");
102
+ expect(element[0].style[postCompStyle]).toBe(postCompVal);
103
+ });
104
+
105
+ it("should not mess up stuff after $apply with no model changes", () => {
106
+ element[0].style["padding-top"] = "33px";
107
+ scope.$apply();
108
+ expect(element[0].style[preCompStyle]).toBe(preCompVal);
109
+ expect(element[0].style["margin-top"]).toBe("44px");
110
+ expect(element[0].style[postCompStyle]).toBe(postCompVal);
111
+ expect(element[0].style["padding-top"]).toBe("33px");
112
+ });
113
+
114
+ it("should not mess up stuff after $apply with non-colliding model changes", () => {
115
+ scope.styleObj = { "padding-top": "99px" };
116
+ scope.$apply();
117
+ expect(element[0].style[preCompStyle]).toBe(preCompVal);
118
+ expect(element[0].style["margin-top"]).not.toBe("44px");
119
+ expect(element[0].style["padding-top"]).toBe("99px");
120
+ expect(element[0].style[postCompStyle]).toBe(postCompVal);
121
+ });
122
+
123
+ it("should overwrite original styles after a colliding model change", () => {
124
+ scope.styleObj = { height: "99px", width: "88px" };
125
+ scope.$apply();
126
+ expect(element[0].style[preCompStyle]).toBe("88px");
127
+ expect(element[0].style[postCompStyle]).toBe("99px");
128
+ scope.styleObj = {};
129
+ scope.$apply();
130
+ expect(element[0].style[preCompStyle]).not.toBe("88px");
131
+ expect(element[0].style[postCompStyle]).not.toBe("99px");
132
+ });
133
+
134
+ it("should clear style when the new model is null", () => {
135
+ scope.styleObj = { height: "99px", width: "88px" };
136
+ scope.$apply();
137
+ expect(element[0].style[preCompStyle]).toBe("88px");
138
+ expect(element[0].style[postCompStyle]).toBe("99px");
139
+ scope.styleObj = null;
140
+ scope.$apply();
141
+ expect(element[0].style[preCompStyle]).not.toBe("88px");
142
+ expect(element[0].style[postCompStyle]).not.toBe("99px");
143
+ });
144
+
145
+ it("should clear style when the value is undefined or null", () => {
146
+ scope.styleObj = { height: "99px", width: "88px" };
147
+ scope.$apply();
148
+ expect(element[0].style[preCompStyle]).toBe("88px");
149
+ expect(element[0].style[postCompStyle]).toBe("99px");
150
+ scope.styleObj = { height: undefined, width: null };
151
+ scope.$apply();
152
+ expect(element[0].style[preCompStyle]).not.toBe("88px");
153
+ expect(element[0].style[postCompStyle]).not.toBe("99px");
154
+ });
155
+
156
+ it("should clear style when the value is false", () => {
157
+ scope.styleObj = { height: "99px", width: "88px" };
158
+ scope.$apply();
159
+ expect(element[0].style[preCompStyle]).toBe("88px");
160
+ expect(element[0].style[postCompStyle]).toBe("99px");
161
+ scope.styleObj = { height: false, width: false };
162
+ scope.$apply();
163
+ expect(element[0].style[preCompStyle]).not.toBe("88px");
164
+ expect(element[0].style[postCompStyle]).not.toBe("99px");
165
+ });
166
+
167
+ it("should set style when the value is zero", () => {
168
+ scope.styleObj = { height: "99px", width: "88px" };
169
+ scope.$apply();
170
+ expect(element[0].style[preCompStyle]).toBe("88px");
171
+ expect(element[0].style[postCompStyle]).toBe("99px");
172
+ scope.styleObj = { height: 0, width: 0 };
173
+ scope.$apply();
174
+ expect(element[0].style[preCompStyle]).toBe("0px");
175
+ expect(element[0].style[postCompStyle]).toBe("0px");
176
+ });
177
+ });
178
+ });