@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,227 @@
1
+ import { publishExternalAPI } from "../../src/public";
2
+ import { createInjector } from "../../src/injector";
3
+
4
+ describe("$controller", () => {
5
+ let $controllerProvider;
6
+ let $controller;
7
+
8
+ beforeEach(() => {
9
+ publishExternalAPI();
10
+ createInjector([
11
+ "ng",
12
+ function (_$controllerProvider_) {
13
+ $controllerProvider = _$controllerProvider_;
14
+ },
15
+ ]).invoke((_$controller_) => {
16
+ $controller = _$controller_;
17
+ });
18
+ });
19
+
20
+ describe("provider", () => {
21
+ it("should allow registration of controllers", () => {
22
+ const FooCtrl = function ($scope) {
23
+ $scope.foo = "bar";
24
+ };
25
+ const scope = {};
26
+ let ctrl;
27
+
28
+ $controllerProvider.register("FooCtrl", FooCtrl);
29
+ ctrl = $controller("FooCtrl", { $scope: scope });
30
+
31
+ expect(scope.foo).toBe("bar");
32
+ expect(ctrl instanceof FooCtrl).toBe(true);
33
+ });
34
+
35
+ it("should allow registration of bound controller functions", () => {
36
+ const FooCtrl = function ($scope) {
37
+ $scope.foo = "bar";
38
+ };
39
+ const scope = {};
40
+ let ctrl;
41
+
42
+ const BoundFooCtrl = FooCtrl.bind(null);
43
+
44
+ $controllerProvider.register("FooCtrl", ["$scope", BoundFooCtrl]);
45
+ ctrl = $controller("FooCtrl", { $scope: scope });
46
+
47
+ expect(scope.foo).toBe("bar");
48
+ });
49
+
50
+ it("should allow registration of map of controllers", () => {
51
+ const FooCtrl = function ($scope) {
52
+ $scope.foo = "foo";
53
+ };
54
+ const BarCtrl = function ($scope) {
55
+ $scope.bar = "bar";
56
+ };
57
+ const scope = {};
58
+ let ctrl;
59
+
60
+ $controllerProvider.register({ FooCtrl, BarCtrl });
61
+
62
+ ctrl = $controller("FooCtrl", { $scope: scope });
63
+ expect(scope.foo).toBe("foo");
64
+ expect(ctrl instanceof FooCtrl).toBe(true);
65
+
66
+ ctrl = $controller("BarCtrl", { $scope: scope });
67
+ expect(scope.bar).toBe("bar");
68
+ expect(ctrl instanceof BarCtrl).toBe(true);
69
+ });
70
+
71
+ it("should allow registration of controllers annotated with arrays", () => {
72
+ const FooCtrl = function ($scope) {
73
+ $scope.foo = "bar";
74
+ };
75
+ const scope = {};
76
+ let ctrl;
77
+
78
+ $controllerProvider.register("FooCtrl", ["$scope", FooCtrl]);
79
+ ctrl = $controller("FooCtrl", { $scope: scope });
80
+
81
+ expect(scope.foo).toBe("bar");
82
+ expect(ctrl instanceof FooCtrl).toBe(true);
83
+ });
84
+
85
+ it('should throw an exception if a controller is called "hasOwnProperty"', () => {
86
+ expect(() => {
87
+ $controllerProvider.register("hasOwnProperty", ($scope) => {});
88
+ }).toThrowError(/badname/);
89
+ });
90
+
91
+ it("should allow checking the availability of a controller", () => {
92
+ $controllerProvider.register("FooCtrl", () => {});
93
+ $controllerProvider.register("BarCtrl", ["dep1", "dep2", () => {}]);
94
+ $controllerProvider.register({
95
+ BazCtrl: () => {},
96
+ QuxCtrl: ["dep1", "dep2", () => {}],
97
+ });
98
+
99
+ expect($controllerProvider.has("FooCtrl")).toBe(true);
100
+ expect($controllerProvider.has("BarCtrl")).toBe(true);
101
+ expect($controllerProvider.has("BazCtrl")).toBe(true);
102
+ expect($controllerProvider.has("QuxCtrl")).toBe(true);
103
+
104
+ expect($controllerProvider.has("UnknownCtrl")).toBe(false);
105
+ });
106
+
107
+ it("should throw ctrlfmt if name contains spaces", () => {
108
+ expect(() => {
109
+ $controller("ctrl doom");
110
+ }).toThrow();
111
+ });
112
+ });
113
+
114
+ it("should return instance of given controller class", () => {
115
+ const MyClass = function () {};
116
+ const ctrl = $controller(MyClass);
117
+
118
+ expect(ctrl).toBeDefined();
119
+ expect(ctrl instanceof MyClass).toBe(true);
120
+ });
121
+
122
+ it("should inject arguments", () => {
123
+ const MyClass = function ($http) {
124
+ this.$http = $http;
125
+ };
126
+
127
+ const ctrl = $controller(MyClass);
128
+ expect(ctrl.$http).toBeTruthy();
129
+ });
130
+
131
+ it("should inject given scope", () => {
132
+ const MyClass = function ($scope) {
133
+ this.$scope = $scope;
134
+ };
135
+
136
+ const scope = {};
137
+ const ctrl = $controller(MyClass, { $scope: scope });
138
+
139
+ expect(ctrl.$scope).toBe(scope);
140
+ });
141
+
142
+ it("should not instantiate a controller defined on window", () => {
143
+ const scope = {};
144
+ const Foo = function () {};
145
+
146
+ window.a = { Foo };
147
+
148
+ expect(() => {
149
+ $controller("a.Foo", { $scope: scope });
150
+ }).toThrow();
151
+ });
152
+
153
+ it("should throw ctrlreg when the controller name does not match a registered controller", () => {
154
+ expect(() => {
155
+ $controller("IDoNotExist", { $scope: {} });
156
+ }).toThrowError(/ctrlreg/);
157
+ });
158
+
159
+ describe("ctrl as syntax", () => {
160
+ it("should publish controller instance into scope", () => {
161
+ const scope = {};
162
+
163
+ $controllerProvider.register("FooCtrl", function () {
164
+ this.mark = "foo";
165
+ });
166
+
167
+ const foo = $controller("FooCtrl as foo", { $scope: scope });
168
+ expect(scope.foo).toBe(foo);
169
+ expect(scope.foo.mark).toBe("foo");
170
+ });
171
+
172
+ it("should allow controllers with dots", () => {
173
+ const scope = {};
174
+
175
+ $controllerProvider.register("a.b.FooCtrl", function () {
176
+ this.mark = "foo";
177
+ });
178
+
179
+ const foo = $controller("a.b.FooCtrl as foo", { $scope: scope });
180
+ expect(scope.foo).toBe(foo);
181
+ expect(scope.foo.mark).toBe("foo");
182
+ });
183
+
184
+ it("should throw an error if $scope is not provided", () => {
185
+ $controllerProvider.register("a.b.FooCtrl", function () {
186
+ this.mark = "foo";
187
+ });
188
+
189
+ expect(() => {
190
+ $controller("a.b.FooCtrl as foo");
191
+ }).toThrowError(/noscp/);
192
+ });
193
+
194
+ it("should throw ctrlfmt if identifier contains non-ident characters", () => {
195
+ expect(() => {
196
+ $controller("ctrl as foo<bar");
197
+ }).toThrowError(/ctrlfmt/);
198
+ });
199
+
200
+ it("should throw ctrlfmt if identifier contains spaces", () => {
201
+ expect(() => {
202
+ $controller("ctrl as foo bar");
203
+ }).toThrowError(/ctrlfmt/);
204
+ });
205
+
206
+ it('should throw ctrlfmt if identifier missing after " as "', () => {
207
+ expect(() => {
208
+ $controller("ctrl as ");
209
+ }).toThrowError(/ctrlfmt/);
210
+ expect(() => {
211
+ $controller("ctrl as");
212
+ }).toThrowError(/ctrlfmt/);
213
+ });
214
+
215
+ it("should allow identifiers containing `$`", () => {
216
+ const scope = {};
217
+
218
+ $controllerProvider.register("FooCtrl", function () {
219
+ this.mark = "foo";
220
+ });
221
+
222
+ const foo = $controller("FooCtrl as $foo", { $scope: scope });
223
+ expect(scope.$foo).toBe(foo);
224
+ expect(scope.$foo.mark).toBe("foo");
225
+ });
226
+ });
227
+ });
@@ -0,0 +1,98 @@
1
+ import { publishExternalAPI } from "../../src/public";
2
+ import { createInjector } from "../../src/injector";
3
+
4
+ describe("$$cookieReader", () => {
5
+ let $$cookieReader;
6
+ let document;
7
+
8
+ describe("with access to `document.cookie`", () => {
9
+ function deleteAllCookies() {
10
+ const cookies = document.cookie.split(";");
11
+ const path = window.location.pathname;
12
+
13
+ for (let i = 0; i < cookies.length; i++) {
14
+ const cookie = cookies[i];
15
+ const eqPos = cookie.indexOf("=");
16
+ const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
17
+ const parts = path.split("/");
18
+ while (parts.length) {
19
+ document.cookie = `${name}=;path=${parts.join("/") || "/"};expires=Thu, 01 Jan 1970 00:00:00 GMT`;
20
+ parts.pop();
21
+ }
22
+ }
23
+ }
24
+
25
+ beforeEach(() => {
26
+ document = window.document;
27
+ deleteAllCookies();
28
+ expect(document.cookie).toEqual("");
29
+
30
+ publishExternalAPI();
31
+ var injector = createInjector(["ng"]);
32
+ $$cookieReader = injector.get("$$cookieReader");
33
+ });
34
+
35
+ afterEach(() => {
36
+ deleteAllCookies();
37
+ expect(document.cookie).toEqual("");
38
+ });
39
+
40
+ describe("get via $$cookieReader()[cookieName]", () => {
41
+ it("should return undefined for nonexistent cookie", () => {
42
+ expect($$cookieReader().nonexistent).not.toBeDefined();
43
+ });
44
+
45
+ it("should return a value for an existing cookie", () => {
46
+ document.cookie = "foo=bar=baz;path=/";
47
+ expect($$cookieReader().foo).toEqual("bar=baz");
48
+ });
49
+
50
+ it("should return the the first value provided for a cookie", () => {
51
+ // For a cookie that has different values that differ by path, the
52
+ // value for the most specific path appears first. $$cookieReader()
53
+ // should provide that value for the cookie.
54
+ document.cookie = 'foo="first"; foo="second"';
55
+ expect($$cookieReader().foo).toBe('"first"');
56
+ });
57
+
58
+ it("should decode cookie values that were encoded by puts", () => {
59
+ document.cookie = "cookie2%3Dbar%3Bbaz=val%3Due;path=/";
60
+ expect($$cookieReader()["cookie2=bar;baz"]).toEqual("val=ue");
61
+ });
62
+
63
+ it("should preserve leading & trailing spaces in names and values", () => {
64
+ document.cookie = "%20cookie%20name%20=%20cookie%20value%20";
65
+ expect($$cookieReader()[" cookie name "]).toEqual(" cookie value ");
66
+ expect($$cookieReader()["cookie name"]).not.toBeDefined();
67
+ });
68
+
69
+ it("should decode special characters in cookie values", () => {
70
+ document.cookie = "cookie_name=cookie_value_%E2%82%AC";
71
+ expect($$cookieReader().cookie_name).toEqual("cookie_value_€");
72
+ });
73
+
74
+ it("should not decode cookie values that do not appear to be encoded", () => {
75
+ // see #9211 - sometimes cookies contain a value that causes decodeURIComponent to throw
76
+ document.cookie = "cookie_name=cookie_value_%XX";
77
+ expect($$cookieReader().cookie_name).toEqual("cookie_value_%XX");
78
+ });
79
+ });
80
+
81
+ describe("getAll via $$cookieReader()", () => {
82
+ it("should return cookies as hash", () => {
83
+ document.cookie = "foo1=bar1;path=/";
84
+ document.cookie = "foo2=bar2;path=/";
85
+ expect($$cookieReader()).toEqual({ foo1: "bar1", foo2: "bar2" });
86
+ });
87
+
88
+ it("should return empty hash if no cookies exist", () => {
89
+ expect($$cookieReader()).toEqual({});
90
+ });
91
+ });
92
+
93
+ it("should initialize cookie cache with existing cookies", () => {
94
+ document.cookie = "existingCookie=existingValue;path=/";
95
+ expect($$cookieReader()).toEqual({ existingCookie: "existingValue" });
96
+ });
97
+ });
98
+ });
@@ -0,0 +1,192 @@
1
+ import { publishExternalAPI } from "../../../src/public";
2
+ import { createInjector } from "../../../src/injector";
3
+ import { dealoc, jqLite } from "../../../src/jqLite";
4
+ import { valueFn, isDefined } from "../../../src/core/utils";
5
+
6
+ describe("a", () => {
7
+ let element;
8
+ let $compile;
9
+ let $rootScope;
10
+
11
+ beforeEach(() => {
12
+ publishExternalAPI();
13
+ createInjector([
14
+ "ng",
15
+ function ($compileProvider) {
16
+ $compileProvider
17
+ .directive(
18
+ "linkTo",
19
+ valueFn({
20
+ restrict: "A",
21
+ template:
22
+ '<div class="my-link"><a href="{{destination}}">{{destination}}</a></div>',
23
+ replace: true,
24
+ scope: {
25
+ destination: "@linkTo",
26
+ },
27
+ }),
28
+ )
29
+ .directive(
30
+ "linkNot",
31
+ valueFn({
32
+ restrict: "A",
33
+ template:
34
+ '<div class="my-link"><a href>{{destination}}</a></div>',
35
+ replace: true,
36
+ scope: {
37
+ destination: "@linkNot",
38
+ },
39
+ }),
40
+ );
41
+ },
42
+ ]).invoke((_$compile_, _$rootScope_) => {
43
+ $compile = _$compile_;
44
+ $rootScope = _$rootScope_;
45
+ });
46
+ });
47
+
48
+ afterEach(() => {
49
+ dealoc(element);
50
+ });
51
+
52
+ it("should prevent default action to be executed when href is empty", () => {
53
+ const orgLocation = window.document.location.href;
54
+ let preventDefaultCalled = false;
55
+ let event;
56
+
57
+ element = $compile('<a href="">empty link</a>')($rootScope);
58
+
59
+ event = window.document.createEvent("MouseEvent");
60
+ event.initMouseEvent(
61
+ "click",
62
+ true,
63
+ true,
64
+ window,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 0,
69
+ 0,
70
+ false,
71
+ false,
72
+ false,
73
+ false,
74
+ 0,
75
+ null,
76
+ );
77
+
78
+ event.preventDefaultOrg = event.preventDefault;
79
+ event.preventDefault = function () {
80
+ preventDefaultCalled = true;
81
+ if (this.preventDefaultOrg) this.preventDefaultOrg();
82
+ };
83
+
84
+ element[0].dispatchEvent(event);
85
+
86
+ expect(preventDefaultCalled).toEqual(true);
87
+
88
+ expect(window.document.location.href).toEqual(orgLocation);
89
+ });
90
+
91
+ it("should not link and hookup an event if href is present at compile", () => {
92
+ const jq = jqLite;
93
+ element = jq('<a href="//a.com">hello@you</a>');
94
+ const linker = $compile(element);
95
+
96
+ spyOn(jq.prototype, "on");
97
+
98
+ linker($rootScope);
99
+
100
+ expect(jq.prototype.on).not.toHaveBeenCalled();
101
+ });
102
+
103
+ it("should not preventDefault if anchor element is replaced with href-containing element", () => {
104
+ spyOn(jqLite.prototype, "on").and.callThrough();
105
+ element = $compile('<a link-to="https://www.google.com">')($rootScope);
106
+ $rootScope.$digest();
107
+
108
+ const child = element.children("a");
109
+ const preventDefault = jasmine.createSpy("preventDefault");
110
+
111
+ child.triggerHandler({
112
+ type: "click",
113
+ preventDefault,
114
+ });
115
+
116
+ expect(preventDefault).not.toHaveBeenCalled();
117
+ });
118
+
119
+ it("should preventDefault if anchor element is replaced with element without href attribute", () => {
120
+ spyOn(jqLite.prototype, "on").and.callThrough();
121
+ element = $compile('<a link-not="https://www.google.com">')($rootScope);
122
+ $rootScope.$digest();
123
+
124
+ const child = element.children("a");
125
+ const preventDefault = jasmine.createSpy("preventDefault");
126
+
127
+ child.triggerHandler({
128
+ type: "click",
129
+ preventDefault,
130
+ });
131
+
132
+ expect(preventDefault).toHaveBeenCalled();
133
+ });
134
+
135
+ if (isDefined(window.SVGElement)) {
136
+ describe("SVGAElement", () => {
137
+ it("should prevent default action to be executed when href is empty", () => {
138
+ const orgLocation = window.document.location.href;
139
+ let preventDefaultCalled = false;
140
+ let event;
141
+ let child;
142
+
143
+ element = $compile('<svg><a xlink:href="">empty link</a></svg>')(
144
+ $rootScope,
145
+ );
146
+ child = element.children("a");
147
+
148
+ event = window.document.createEvent("MouseEvent");
149
+ event.initMouseEvent(
150
+ "click",
151
+ true,
152
+ true,
153
+ window,
154
+ 0,
155
+ 0,
156
+ 0,
157
+ 0,
158
+ 0,
159
+ false,
160
+ false,
161
+ false,
162
+ false,
163
+ 0,
164
+ null,
165
+ );
166
+
167
+ event.preventDefaultOrg = event.preventDefault;
168
+ event.preventDefault = function () {
169
+ preventDefaultCalled = true;
170
+ if (this.preventDefaultOrg) this.preventDefaultOrg();
171
+ };
172
+
173
+ child[0].dispatchEvent(event);
174
+
175
+ expect(preventDefaultCalled).toEqual(true);
176
+ expect(window.document.location.href).toEqual(orgLocation);
177
+ });
178
+
179
+ it("should not link and hookup an event if xlink:href is present at compile", () => {
180
+ const jq = jqLite;
181
+ element = jq('<svg><a xlink:href="bobby">hello@you</a></svg>');
182
+ const linker = $compile(element);
183
+
184
+ spyOn(jq.prototype, "on");
185
+
186
+ linker($rootScope);
187
+
188
+ expect(jq.prototype.on).not.toHaveBeenCalled();
189
+ });
190
+ });
191
+ }
192
+ });