@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.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { publishExternalAPI } from "../../../src/public";
|
|
2
|
+
import { createInjector } from "../../../src/injector";
|
|
3
|
+
import { dealoc } from "../../../src/jqLite";
|
|
4
|
+
import { isDefined } from "../../../src/core/utils";
|
|
5
|
+
|
|
6
|
+
describe("ngHref", () => {
|
|
7
|
+
let $rootScope;
|
|
8
|
+
let $compile;
|
|
9
|
+
let element;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
publishExternalAPI().decorator("$exceptionHandler", function () {
|
|
13
|
+
return (exception, cause) => {
|
|
14
|
+
throw new Error(exception.message);
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
createInjector(["ng"]).invoke((_$rootScope_, _$compile_) => {
|
|
18
|
+
$rootScope = _$rootScope_;
|
|
19
|
+
$compile = _$compile_;
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
dealoc(element);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should interpolate the expression and bind to href", () => {
|
|
28
|
+
element = $compile('<a ng-href="some/{{id}}"></div>')($rootScope);
|
|
29
|
+
$rootScope.$digest();
|
|
30
|
+
expect(element.attr("href")).toEqual("some/");
|
|
31
|
+
|
|
32
|
+
$rootScope.$apply(() => {
|
|
33
|
+
$rootScope.id = 1;
|
|
34
|
+
});
|
|
35
|
+
expect(element.attr("href")).toEqual("some/1");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should bind href and merge with other attrs", () => {
|
|
39
|
+
element = $compile('<a ng-href="{{url}}" rel="{{rel}}"></a>')($rootScope);
|
|
40
|
+
$rootScope.url = "http://server";
|
|
41
|
+
$rootScope.rel = "REL";
|
|
42
|
+
$rootScope.$digest();
|
|
43
|
+
expect(element.attr("href")).toEqual("http://server");
|
|
44
|
+
expect(element.attr("rel")).toEqual("REL");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should bind href even if no interpolation", () => {
|
|
48
|
+
element = $compile('<a ng-href="http://server"></a>')($rootScope);
|
|
49
|
+
$rootScope.$digest();
|
|
50
|
+
expect(element.attr("href")).toEqual("http://server");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should not set the href if ng-href is empty", () => {
|
|
54
|
+
$rootScope.url = null;
|
|
55
|
+
element = $compile('<a ng-href="{{url}}">')($rootScope);
|
|
56
|
+
$rootScope.$digest();
|
|
57
|
+
expect(element.attr("href")).toEqual(undefined);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should remove the href if ng-href changes to empty", () => {
|
|
61
|
+
$rootScope.url = "http://www.google.com/";
|
|
62
|
+
element = $compile('<a ng-href="{{url}}">')($rootScope);
|
|
63
|
+
$rootScope.$digest();
|
|
64
|
+
|
|
65
|
+
$rootScope.url = null;
|
|
66
|
+
$rootScope.$digest();
|
|
67
|
+
expect(element.attr("href")).toEqual(undefined);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should sanitize interpolated url", () => {
|
|
71
|
+
/* eslint no-script-url: "off" */
|
|
72
|
+
$rootScope.imageUrl = "javascript:alert(1);";
|
|
73
|
+
element = $compile('<a ng-href="{{imageUrl}}">')($rootScope);
|
|
74
|
+
$rootScope.$digest();
|
|
75
|
+
expect(element.attr("href")).toBe("unsafe:javascript:alert(1);");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should sanitize non-interpolated url", () => {
|
|
79
|
+
element = $compile('<a ng-href="javascript:alert(1);">')($rootScope);
|
|
80
|
+
$rootScope.$digest();
|
|
81
|
+
expect(element.attr("href")).toBe("unsafe:javascript:alert(1);");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should bind numbers", () => {
|
|
85
|
+
element = $compile('<a ng-href="{{1234}}"></a>')($rootScope);
|
|
86
|
+
$rootScope.$digest();
|
|
87
|
+
expect(element.attr("href")).toEqual("1234");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should bind and sanitize the result of a (custom) toString() function", () => {
|
|
91
|
+
$rootScope.value = {};
|
|
92
|
+
element = $compile('<a ng-href="{{value}}"></a>')($rootScope);
|
|
93
|
+
$rootScope.$digest();
|
|
94
|
+
expect(element.attr("href")).toEqual("[object Object]");
|
|
95
|
+
|
|
96
|
+
function SafeClass() {}
|
|
97
|
+
|
|
98
|
+
SafeClass.prototype.toString = function () {
|
|
99
|
+
return "custom value";
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
$rootScope.value = new SafeClass();
|
|
103
|
+
$rootScope.$digest();
|
|
104
|
+
expect(element.attr("href")).toEqual("custom value");
|
|
105
|
+
|
|
106
|
+
function UnsafeClass() {}
|
|
107
|
+
|
|
108
|
+
UnsafeClass.prototype.toString = function () {
|
|
109
|
+
return "javascript:alert(1);";
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
$rootScope.value = new UnsafeClass();
|
|
113
|
+
$rootScope.$digest();
|
|
114
|
+
expect(element.attr("href")).toEqual("unsafe:javascript:alert(1);");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (isDefined(window.SVGElement)) {
|
|
118
|
+
describe("SVGAElement", () => {
|
|
119
|
+
it("should interpolate the expression and bind to xlink:href", () => {
|
|
120
|
+
element = $compile('<svg><a ng-href="some/{{id}}"></a></svg>')(
|
|
121
|
+
$rootScope,
|
|
122
|
+
);
|
|
123
|
+
const child = element.children("a");
|
|
124
|
+
$rootScope.$digest();
|
|
125
|
+
expect(child.attr("xlink:href")).toEqual("some/");
|
|
126
|
+
|
|
127
|
+
$rootScope.$apply(() => {
|
|
128
|
+
$rootScope.id = 1;
|
|
129
|
+
});
|
|
130
|
+
expect(child.attr("xlink:href")).toEqual("some/1");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should bind xlink:href even if no interpolation", () => {
|
|
134
|
+
element = $compile('<svg><a ng-href="http://server"></a></svg>')(
|
|
135
|
+
$rootScope,
|
|
136
|
+
);
|
|
137
|
+
const child = element.children("a");
|
|
138
|
+
$rootScope.$digest();
|
|
139
|
+
expect(child.attr("xlink:href")).toEqual("http://server");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { dealoc, jqLite } from "../../../src/jqLite";
|
|
2
|
+
import { forEach, valueFn } from "../../../src/core/utils";
|
|
3
|
+
import { publishExternalAPI } from "../../../src/public";
|
|
4
|
+
import { createInjector } from "../../../src/injector";
|
|
5
|
+
import { Angular } from "../../../src/loader";
|
|
6
|
+
|
|
7
|
+
describe("ngIf", () => {
|
|
8
|
+
describe("basic", () => {
|
|
9
|
+
let $scope;
|
|
10
|
+
let $compile;
|
|
11
|
+
let element;
|
|
12
|
+
let $compileProvider;
|
|
13
|
+
let $rootScope;
|
|
14
|
+
let injector;
|
|
15
|
+
let angular;
|
|
16
|
+
|
|
17
|
+
beforeEach(function () {
|
|
18
|
+
angular = new Angular();
|
|
19
|
+
publishExternalAPI();
|
|
20
|
+
injector = createInjector([
|
|
21
|
+
"ng",
|
|
22
|
+
function (_$compileProvider_) {
|
|
23
|
+
$compileProvider = _$compileProvider_;
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
injector.invoke((_$rootScope_, _$compile_) => {
|
|
27
|
+
$rootScope = _$rootScope_;
|
|
28
|
+
$scope = $rootScope.$new();
|
|
29
|
+
$compile = _$compile_;
|
|
30
|
+
element = $compile("<div></div>")($scope);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
dealoc(element);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function makeIf() {
|
|
39
|
+
forEach(arguments, (expr) => {
|
|
40
|
+
element.append(
|
|
41
|
+
$compile(`<div class="my-class" ng-if="${expr}"><div>Hi</div></div>`)(
|
|
42
|
+
$scope,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
$scope.$apply();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
it("should immediately remove the element if condition is falsy", () => {
|
|
50
|
+
makeIf("false", "undefined", "null", "NaN", "''", "0");
|
|
51
|
+
expect(element.children().length).toBe(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should leave the element if condition is true", () => {
|
|
55
|
+
makeIf("true");
|
|
56
|
+
expect(element.children().length).toBe(1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should leave the element if the condition is a non-empty string", () => {
|
|
60
|
+
makeIf("'f'", "'0'", "'false'", "'no'", "'n'", "'[]'");
|
|
61
|
+
expect(element.children().length).toBe(6);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should leave the element if the condition is an object", () => {
|
|
65
|
+
makeIf("[]", "{}");
|
|
66
|
+
expect(element.children().length).toBe(2);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should not add the element twice if the condition goes from true to true", () => {
|
|
70
|
+
$scope.hello = "true1";
|
|
71
|
+
makeIf("hello");
|
|
72
|
+
expect(element.children().length).toBe(1);
|
|
73
|
+
$scope.$apply('hello = "true2"');
|
|
74
|
+
expect(element.children().length).toBe(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should not recreate the element if the condition goes from true to true", () => {
|
|
78
|
+
$scope.hello = "true1";
|
|
79
|
+
makeIf("hello");
|
|
80
|
+
element.children().data("flag", true);
|
|
81
|
+
$scope.$apply('hello = "true2"');
|
|
82
|
+
expect(element.children().data("flag")).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should create then remove the element if condition changes", () => {
|
|
86
|
+
$scope.hello = true;
|
|
87
|
+
makeIf("hello");
|
|
88
|
+
expect(element.children().length).toBe(1);
|
|
89
|
+
$scope.$apply("hello = false");
|
|
90
|
+
expect(element.children().length).toBe(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should create a new scope every time the expression evaluates to true", () => {
|
|
94
|
+
$scope.$apply("value = true");
|
|
95
|
+
element.append(
|
|
96
|
+
$compile(
|
|
97
|
+
'<div ng-if="value"><span ng-init="value=false"></span></div>',
|
|
98
|
+
)($scope),
|
|
99
|
+
);
|
|
100
|
+
$scope.$apply();
|
|
101
|
+
expect(element.children("div").length).toBe(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should destroy the child scope every time the expression evaluates to false", () => {
|
|
105
|
+
$scope.value = true;
|
|
106
|
+
element.append($compile('<div ng-if="value"></div>')($scope));
|
|
107
|
+
$scope.$apply();
|
|
108
|
+
|
|
109
|
+
const childScope = element.children().scope();
|
|
110
|
+
let destroyed = false;
|
|
111
|
+
|
|
112
|
+
childScope.$on("$destroy", () => {
|
|
113
|
+
destroyed = true;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
$scope.value = false;
|
|
117
|
+
$scope.$apply();
|
|
118
|
+
|
|
119
|
+
expect(destroyed).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should play nice with other elements beside it", () => {
|
|
123
|
+
$scope.values = [1, 2, 3, 4];
|
|
124
|
+
element.append(
|
|
125
|
+
$compile(
|
|
126
|
+
'<div ng-repeat="i in values"></div>' +
|
|
127
|
+
'<div ng-if="values.length==4"></div>' +
|
|
128
|
+
'<div ng-repeat="i in values"></div>',
|
|
129
|
+
)($scope),
|
|
130
|
+
);
|
|
131
|
+
$scope.$apply();
|
|
132
|
+
expect(element.children().length).toBe(9);
|
|
133
|
+
$scope.$apply("values.splice(0,1)");
|
|
134
|
+
expect(element.children().length).toBe(6);
|
|
135
|
+
$scope.$apply("values.push(1)");
|
|
136
|
+
expect(element.children().length).toBe(9);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should play nice with ngInclude on the same element", (done) => {
|
|
140
|
+
element = jqLite(
|
|
141
|
+
`<div><div ng-if="value=='first'" ng-include="'/mock/hello'"></div></div>`,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
window.angular.module("myModule", []).run(($rootScope) => {
|
|
145
|
+
$rootScope.value = "first";
|
|
146
|
+
});
|
|
147
|
+
injector = angular.bootstrap(element, ["myModule"]);
|
|
148
|
+
|
|
149
|
+
$rootScope.$digest();
|
|
150
|
+
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
expect(element.text()).toBe("Hello");
|
|
153
|
+
done();
|
|
154
|
+
}, 100);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should work with multiple elements", () => {
|
|
158
|
+
$scope.show = true;
|
|
159
|
+
$scope.things = [1, 2, 3];
|
|
160
|
+
element.append(
|
|
161
|
+
$compile(
|
|
162
|
+
"<div><div>before;</div>" +
|
|
163
|
+
'<div ng-if-start="show">start;</div>' +
|
|
164
|
+
'<div ng-repeat="thing in things">{{thing}};</div>' +
|
|
165
|
+
"<div ng-if-end>end;</div>" +
|
|
166
|
+
"<div>after;</div></div>",
|
|
167
|
+
)($scope),
|
|
168
|
+
);
|
|
169
|
+
$scope.$apply();
|
|
170
|
+
expect(element.text()).toBe("before;start;1;2;3;end;after;");
|
|
171
|
+
|
|
172
|
+
$scope.things.push(4);
|
|
173
|
+
$scope.$apply();
|
|
174
|
+
expect(element.text()).toBe("before;start;1;2;3;4;end;after;");
|
|
175
|
+
|
|
176
|
+
$scope.show = false;
|
|
177
|
+
$scope.$apply();
|
|
178
|
+
// expect(element.text()).toBe("before;after;");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("should restore the element to its compiled state", () => {
|
|
182
|
+
$scope.value = true;
|
|
183
|
+
makeIf("value");
|
|
184
|
+
expect(element.children().length).toBe(1);
|
|
185
|
+
element.children()[0].classList.remove("my-class");
|
|
186
|
+
expect(element.children()[0].className).not.toContain("my-class");
|
|
187
|
+
$scope.$apply("value = false");
|
|
188
|
+
expect(element.children().length).toBe(0);
|
|
189
|
+
$scope.$apply("value = true");
|
|
190
|
+
expect(element.children().length).toBe(1);
|
|
191
|
+
expect(element.children()[0].className).toContain("my-class");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should work when combined with an ASYNC template that loads after the first digest", (done) => {
|
|
195
|
+
$compileProvider.directive("test", () => ({
|
|
196
|
+
templateUrl: "/test.html",
|
|
197
|
+
}));
|
|
198
|
+
element.append('<div ng-if="show" test></div>');
|
|
199
|
+
$compile(element)($rootScope);
|
|
200
|
+
$rootScope.show = true;
|
|
201
|
+
expect(element.text()).toBe("");
|
|
202
|
+
$rootScope.$apply();
|
|
203
|
+
setTimeout(() => {
|
|
204
|
+
expect(element.text()).toBe("hello");
|
|
205
|
+
$rootScope.show = false;
|
|
206
|
+
$rootScope.$apply();
|
|
207
|
+
expect(element.children().length).toBe(0);
|
|
208
|
+
expect(element.text()).toBe("");
|
|
209
|
+
done();
|
|
210
|
+
}, 100);
|
|
211
|
+
expect(element.text()).toBe("");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should not trigger a digest when the element is removed", () => {
|
|
215
|
+
const spy = spyOn($rootScope, "$digest").and.callThrough();
|
|
216
|
+
let $timeout = injector.get("$timeout");
|
|
217
|
+
$scope.hello = true;
|
|
218
|
+
makeIf("hello");
|
|
219
|
+
expect(element.children().length).toBe(1);
|
|
220
|
+
$scope.$apply("hello = false");
|
|
221
|
+
spy.calls.reset();
|
|
222
|
+
expect(element.children().length).toBe(0);
|
|
223
|
+
expect(spy).not.toHaveBeenCalled();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("and transcludes", () => {
|
|
227
|
+
it("should allow access to directive controller from children when used in a replace template", () => {
|
|
228
|
+
let controller;
|
|
229
|
+
const { directive } = $compileProvider;
|
|
230
|
+
directive(
|
|
231
|
+
"template",
|
|
232
|
+
valueFn({
|
|
233
|
+
template: '<div ng-if="true"><span test></span></div>',
|
|
234
|
+
replace: true,
|
|
235
|
+
controller() {
|
|
236
|
+
this.flag = true;
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
directive(
|
|
241
|
+
"test",
|
|
242
|
+
valueFn({
|
|
243
|
+
require: "^template",
|
|
244
|
+
link(scope, el, attr, ctrl) {
|
|
245
|
+
controller = ctrl;
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
249
|
+
$compile("<div><div template></div></div>")($rootScope);
|
|
250
|
+
$rootScope.$apply();
|
|
251
|
+
expect(controller.flag).toBe(true);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("should use the correct transcluded scope", () => {
|
|
255
|
+
$compileProvider.directive(
|
|
256
|
+
"iso",
|
|
257
|
+
valueFn({
|
|
258
|
+
link(scope) {
|
|
259
|
+
scope.val = "value in iso scope";
|
|
260
|
+
},
|
|
261
|
+
restrict: "E",
|
|
262
|
+
transclude: true,
|
|
263
|
+
template:
|
|
264
|
+
'<div ng-if="true">val={{val}}-<div ng-transclude></div></div>',
|
|
265
|
+
scope: {},
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
$rootScope.val = "transcluded content";
|
|
269
|
+
const element = $compile('<iso><span ng-bind="val"></span></iso>')(
|
|
270
|
+
$rootScope,
|
|
271
|
+
);
|
|
272
|
+
$rootScope.$digest();
|
|
273
|
+
expect(element.text().trim()).toEqual(
|
|
274
|
+
"val=value in iso scope-transcluded content",
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// TODO ANIMATIONS
|
|
280
|
+
// describe("and animations", () => {
|
|
281
|
+
// let body = document.getElementById("dummy");
|
|
282
|
+
// let element;
|
|
283
|
+
// let $rootElement;
|
|
284
|
+
|
|
285
|
+
// function html(content) {
|
|
286
|
+
// $rootElement.html(content);
|
|
287
|
+
// element = $rootElement.children().eq(0);
|
|
288
|
+
// return element;
|
|
289
|
+
// }
|
|
290
|
+
|
|
291
|
+
// afterEach(() => {
|
|
292
|
+
// dealoc(body);
|
|
293
|
+
// dealoc(element);
|
|
294
|
+
// });
|
|
295
|
+
|
|
296
|
+
// // beforeEach(
|
|
297
|
+
// // module(
|
|
298
|
+
// // ($animateProvider, $provide) =>
|
|
299
|
+
// // function ($animate) {
|
|
300
|
+
// // $animate.enabled(true);
|
|
301
|
+
// // },
|
|
302
|
+
// // ),
|
|
303
|
+
// // );
|
|
304
|
+
|
|
305
|
+
// it("should fire off the enter animation", () => {
|
|
306
|
+
// body.innerHTML =
|
|
307
|
+
// "<div>" + '<div ng-if="value"><div>Hi</div></div>' + "</div>";
|
|
308
|
+
|
|
309
|
+
// let item;
|
|
310
|
+
// const $scope = $rootScope.$new();
|
|
311
|
+
// element = $compile(body)($scope);
|
|
312
|
+
|
|
313
|
+
// $rootScope.$digest();
|
|
314
|
+
// $scope.$apply("value = true");
|
|
315
|
+
|
|
316
|
+
// item = $animate.queue.shift();
|
|
317
|
+
// expect(item.event).toBe("enter");
|
|
318
|
+
// expect(item.element.text()).toBe("Hi");
|
|
319
|
+
|
|
320
|
+
// expect(element.children().length).toBe(1);
|
|
321
|
+
// });
|
|
322
|
+
|
|
323
|
+
// it("should fire off the leave animation", () => {
|
|
324
|
+
// let item;
|
|
325
|
+
// const $scope = $rootScope.$new();
|
|
326
|
+
// element = $compile(
|
|
327
|
+
// html("<div>" + '<div ng-if="value"><div>Hi</div></div>' + "</div>"),
|
|
328
|
+
// )($scope);
|
|
329
|
+
// $scope.$apply("value = true");
|
|
330
|
+
|
|
331
|
+
// item = $animate.queue.shift();
|
|
332
|
+
// expect(item.event).toBe("enter");
|
|
333
|
+
// expect(item.element.text()).toBe("Hi");
|
|
334
|
+
|
|
335
|
+
// expect(element.children().length).toBe(1);
|
|
336
|
+
// $scope.$apply("value = false");
|
|
337
|
+
|
|
338
|
+
// item = $animate.queue.shift();
|
|
339
|
+
// expect(item.event).toBe("leave");
|
|
340
|
+
// expect(item.element.text()).toBe("Hi");
|
|
341
|
+
|
|
342
|
+
// expect(element.children().length).toBe(0);
|
|
343
|
+
// });
|
|
344
|
+
|
|
345
|
+
// it("should destroy the previous leave animation if a new one takes place", () => {
|
|
346
|
+
// module(($provide) => {
|
|
347
|
+
// $provide.decorator("$animate", ($delegate, $$q) => {
|
|
348
|
+
// const emptyPromise = $$q.defer().promise;
|
|
349
|
+
// emptyPromise.done = () => {};
|
|
350
|
+
|
|
351
|
+
// $delegate.leave = function () {
|
|
352
|
+
// return emptyPromise;
|
|
353
|
+
// };
|
|
354
|
+
// return $delegate;
|
|
355
|
+
// });
|
|
356
|
+
// });
|
|
357
|
+
// inject(($compile, $rootScope, $animate) => {
|
|
358
|
+
// let item;
|
|
359
|
+
// const $scope = $rootScope.$new();
|
|
360
|
+
// element = $compile(
|
|
361
|
+
// html("<div>" + '<div ng-if="value">Yo</div>' + "</div>"),
|
|
362
|
+
// )($scope);
|
|
363
|
+
|
|
364
|
+
// $scope.$apply("value = true");
|
|
365
|
+
|
|
366
|
+
// let destroyed;
|
|
367
|
+
// const inner = element.children(0);
|
|
368
|
+
// inner.on("$destroy", () => {
|
|
369
|
+
// destroyed = true;
|
|
370
|
+
// });
|
|
371
|
+
|
|
372
|
+
// $scope.$apply("value = false");
|
|
373
|
+
|
|
374
|
+
// $scope.$apply("value = true");
|
|
375
|
+
|
|
376
|
+
// $scope.$apply("value = false");
|
|
377
|
+
|
|
378
|
+
// expect(destroyed).toBe(true);
|
|
379
|
+
// });
|
|
380
|
+
// });
|
|
381
|
+
|
|
382
|
+
// it("should work with svg elements when the svg container is transcluded", () => {
|
|
383
|
+
// // module(($compileProvider) => {
|
|
384
|
+
// // $compileProvider.directive("svgContainer", () => ({
|
|
385
|
+
// // template: "<svg ng-transclude></svg>",
|
|
386
|
+
// // replace: true,
|
|
387
|
+
// // transclude: true,
|
|
388
|
+
// // });
|
|
389
|
+
// // });
|
|
390
|
+
|
|
391
|
+
// element = $compile(
|
|
392
|
+
// '<svg-container><circle ng-if="flag"></circle></svg-container>',
|
|
393
|
+
// )($rootScope);
|
|
394
|
+
// $rootScope.flag = true;
|
|
395
|
+
// $rootScope.$apply();
|
|
396
|
+
|
|
397
|
+
// const circle = element.find("circle");
|
|
398
|
+
// expect(circle[0].toString()).toMatch(/SVG/);
|
|
399
|
+
// });
|
|
400
|
+
// });
|
|
401
|
+
});
|
|
402
|
+
});
|