@angular-wave/angular.ts 0.0.22 → 0.0.23

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.
@@ -0,0 +1,146 @@
1
+ import { dealoc, jqLite } from "../../src/jqLite";
2
+ import { Angular } from "../../src/loader";
3
+ import { publishExternalAPI } from "../../src/public";
4
+ import { wait } from "../test-utils";
5
+
6
+ describe("templateFactory", () => {
7
+ let $injector, $templateFactory, $httpBackend, $sce, $scope, $compile;
8
+
9
+ beforeEach(() => {
10
+ dealoc(document.getElementById("dummy"));
11
+ window.angular = new Angular();
12
+ publishExternalAPI();
13
+ window.angular.module("defaultModule", ["ui.router"]);
14
+ $injector = window.angular.bootstrap(document.getElementById("dummy"), [
15
+ "defaultModule",
16
+ ]);
17
+ $injector.invoke(
18
+ (_$templateFactory_, _$httpBackend_, _$sce_, $rootScope) => {
19
+ ($templateFactory = _$templateFactory_),
20
+ ($httpBackend = _$httpBackend_),
21
+ ($sce = _$sce_);
22
+ $scope = $rootScope;
23
+ },
24
+ );
25
+ });
26
+
27
+ it("exists", () => {
28
+ expect($injector.get("$templateFactory")).toBeDefined();
29
+ });
30
+
31
+ describe("should follow $sce policy and", () => {
32
+ it("accepts relative URLs", async () => {
33
+ let res = $templateFactory.fromUrl("mock/hello");
34
+ $scope.$digest();
35
+ await wait(10);
36
+ expect(res.$$state.status).toBe(1);
37
+ });
38
+
39
+ it("rejects untrusted URLs", () => {
40
+ let error = "No error thrown";
41
+ try {
42
+ $templateFactory.fromUrl("http://evil.com/views/view.html");
43
+ } catch (e) {
44
+ error = e.message;
45
+ }
46
+ expect(error).toMatch(/sce:insecurl/);
47
+ });
48
+
49
+ it("accepts explicitly trusted URLs", () => {
50
+ expect(() => {
51
+ $templateFactory.fromUrl(
52
+ $sce.trustAsResourceUrl("http://evil.com/views/view.html"),
53
+ );
54
+ }).not.toThrowError();
55
+ });
56
+ });
57
+
58
+ describe("templateFactory with forced use of $http service", () => {
59
+ beforeEach(() => {
60
+ dealoc(document.getElementById("dummy"));
61
+ let module = window.angular.module("defaultModule", ["ui.router"]);
62
+ module.config(function ($templateFactoryProvider) {
63
+ $templateFactoryProvider.useHttpService(true);
64
+ });
65
+ $injector = window.angular.bootstrap(document.getElementById("dummy"), [
66
+ "defaultModule",
67
+ ]);
68
+ $injector.invoke(
69
+ (_$templateFactory_, _$httpBackend_, _$sce_, $rootScope) => {
70
+ ($templateFactory = _$templateFactory_),
71
+ ($httpBackend = _$httpBackend_),
72
+ ($sce = _$sce_);
73
+ $scope = $rootScope;
74
+ },
75
+ );
76
+ });
77
+
78
+ it("does not restrict URL loading", function () {
79
+ expect(() => {
80
+ $templateFactory.fromUrl("http://evil.com/views/view.html");
81
+ }).not.toThrowError();
82
+
83
+ expect(() => {
84
+ $templateFactory.fromUrl("data:text/html,foo");
85
+ }).not.toThrowError();
86
+ });
87
+ });
88
+
89
+ describe("component template builder", () => {
90
+ let $router, el;
91
+
92
+ beforeEach(() => {
93
+ dealoc(document.getElementById("dummy"));
94
+ const mod = angular.module("defaultModule", ["ui.router"]);
95
+ mod.component("myComponent", { template: "hi" });
96
+ mod.component("dataComponent", { template: "hi" });
97
+ mod.component("xComponent", { template: "hi" });
98
+ $injector = window.angular.bootstrap(document.getElementById("dummy"), [
99
+ "defaultModule",
100
+ ]);
101
+ $injector.invoke(
102
+ (
103
+ _$templateFactory_,
104
+ _$httpBackend_,
105
+ _$sce_,
106
+ $rootScope,
107
+ _$router_,
108
+ _$compile_,
109
+ ) => {
110
+ ($templateFactory = _$templateFactory_),
111
+ ($httpBackend = _$httpBackend_),
112
+ ($sce = _$sce_);
113
+ $scope = $rootScope;
114
+ $router = _$router_;
115
+ $compile = _$compile_;
116
+ },
117
+ );
118
+ el = $compile(jqLite("<div><ui-view></ui-view></div>"))($scope.$new());
119
+ });
120
+
121
+ it("should not prefix the components dom element with anything", async () => {
122
+ $router.stateRegistry.register({ name: "cmp", component: "myComponent" });
123
+ $router.stateService.go("cmp");
124
+ $scope.$digest();
125
+ await wait(10);
126
+ expect(el.html()).toMatch(/\<my-component/);
127
+ });
128
+
129
+ it("should prefix the components dom element with x- for components named dataFoo", () => {
130
+ $router.stateRegistry.register({
131
+ name: "cmp",
132
+ component: "dataComponent",
133
+ });
134
+ $router.stateService.go("cmp");
135
+ $scope.$digest();
136
+ expect(el.html()).toMatch(/\<x-data-component/);
137
+ });
138
+
139
+ it("should prefix the components dom element with x- for components named xFoo", () => {
140
+ $router.stateRegistry.register({ name: "cmp", component: "xComponent" });
141
+ $router.stateService.go("cmp");
142
+ $scope.$digest();
143
+ expect(el.html()).toMatch(/\<x-x-component/);
144
+ });
145
+ });
146
+ });