Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/pkg/angular/test/core/templateurl_spec.dart

Issue 176943008: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library templateurl_spec; 1 library templateurl_spec;
2 2
3 import '../_specs.dart'; 3 import '../_specs.dart';
4 4
5 @NgComponent( 5 @NgComponent(
6 selector: 'simple-url', 6 selector: 'simple-url',
7 templateUrl: 'simple.html') 7 templateUrl: 'simple.html')
8 class SimpleUrlComponent { 8 class SimpleUrlComponent {
9 } 9 }
10 10
11 @NgComponent( 11 @NgComponent(
12 selector: 'html-and-css', 12 selector: 'html-and-css',
13 templateUrl: 'simple.html', 13 templateUrl: 'simple.html',
14 cssUrl: 'simple.css') 14 cssUrl: 'simple.css')
15 class HtmlAndCssComponent { 15 class HtmlAndCssComponent {
16 } 16 }
17 17
18 @NgComponent( 18 @NgComponent(
19 selector: 'html-and-css', 19 selector: 'html-and-css',
20 templateUrl: 'simple.html', 20 templateUrl: 'simple.html',
21 cssUrls: const ['simple.css', 'another.css']) 21 cssUrl: const ['simple.css', 'another.css'])
22 class HtmlAndMultipleCssComponent { 22 class HtmlAndMultipleCssComponent {
23 } 23 }
24 24
25 @NgComponent( 25 @NgComponent(
26 selector: 'inline-with-css', 26 selector: 'inline-with-css',
27 template: '<div>inline!</div>', 27 template: '<div>inline!</div>',
28 cssUrl: 'simple.css') 28 cssUrl: 'simple.css')
29 class InlineWithCssComponent { 29 class InlineWithCssComponent {
30 } 30 }
31 31
32 @NgComponent( 32 @NgComponent(
33 selector: 'only-css', 33 selector: 'only-css',
34 cssUrl: 'simple.css') 34 cssUrl: 'simple.css')
35 class OnlyCssComponent { 35 class OnlyCssComponent {
36 } 36 }
37 37
38 class PrefixedUrlRewriter extends UrlRewriter { 38 class PrefixedUrlRewriter extends UrlRewriter {
39 call(url) => "PREFIX:$url"; 39 call(url) => "PREFIX:$url";
40 } 40 }
41 41
42 main() => describe('template url', () { 42 main() => describe('template url', () {
43 afterEach(inject((MockHttpBackend backend) { 43 afterEach(inject((MockHttpBackend backend) {
44 backend.verifyNoOutstandingRequest(); 44 backend.verifyNoOutstandingRequest();
45 })); 45 }));
46 46
47 describe('loading with http rewriting', () { 47 describe('loading with http rewriting', () {
48 beforeEach(module((Module module) { 48 beforeEach(module((Module module) {
49 module 49 module
50 ..type(HtmlAndCssComponent) 50 ..type(HtmlAndCssComponent)
51 ..type(UrlRewriter, implementedBy: PrefixedUrlRewriter); 51 ..type(UrlRewriter, implementedBy: PrefixedUrlRewriter);
52 })); 52 }));
53 53
54 it('should use the UrlRewriter for both HTML and CSS URLs', async(inject((Ht tp $http, 54 it('should use the UrlRewriter for both HTML and CSS URLs', async(inject((Ht tp $http,
55 Compiler $compile, Scope $rootScope, Logger log, Injector injector, Ng Zone zone, 55 Compiler $compile, Scope $rootScope, Logger log, Injector injector, Ng Zone zone,
56 MockHttpBackend backend) { 56 MockHttpBackend backend, DirectiveMap directives) {
57 57
58 backend.whenGET('PREFIX:simple.html').respond('<div log="SIMPLE">Simple!</ div>'); 58 backend
59 backend.whenGET('PREFIX:simple.css').respond('.hello{}'); 59 ..whenGET('PREFIX:simple.html').respond('<div log="SIMPLE">Simple!</di v>')
60 ..whenGET('PREFIX:simple.css').respond('.hello{}');
60 61
61 var element = $('<div><html-and-css log>ignore</html-and-css><div>'); 62 var element = $('<div><html-and-css log>ignore</html-and-css><div>');
62 zone.run(() { 63 zone.run(() {
63 $compile(element)(injector, element); 64 $compile(element, directives)(injector, element);
64 }); 65 });
65 66
66 backend.flush(); 67 backend.flush();
67 microLeap(); 68 microLeap();
68 69
69 expect(renderedText(element)).toEqual('.hello{}Simple!'); 70 expect(renderedText(element)).toEqual('.hello{}Simple!');
70 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( 71 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
71 '<style>.hello{}</style><div log="SIMPLE">Simple!</div>' 72 '<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
72 ); 73 );
73 }))); 74 })));
74 }); 75 });
75 76
76 77
77 describe('async template loading', () { 78 describe('async template loading', () {
78 beforeEach(module((Module module) { 79 beforeEach(module((Module module) {
79 module.type(LogAttrDirective); 80 module
80 module.type(SimpleUrlComponent); 81 ..type(LogAttrDirective)
81 module.type(HtmlAndCssComponent); 82 ..type(SimpleUrlComponent)
82 module.type(OnlyCssComponent); 83 ..type(HtmlAndCssComponent)
83 module.type(InlineWithCssComponent); 84 ..type(OnlyCssComponent)
85 ..type(InlineWithCssComponent);
84 })); 86 }));
85 87
86 it('should replace element with template from url', async(inject((Http $http , 88 it('should replace element with template from url', async(inject((Http $http ,
87 Compiler $compile, Scope $rootScope, Logger log, Injector injector, 89 Compiler $compile, Scope $rootScope, Logger log, Injector injector,
88 MockHttpBackend backend) { 90 MockHttpBackend backend, DirectiveMap directives) {
89 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>' ); 91 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>' );
90 92
91 var element = $('<div><simple-url log>ignore</simple-url><div>'); 93 var element = $('<div><simple-url log>ignore</simple-url><div>');
92 $compile(element)(injector, element); 94 $compile(element, directives)(injector, element);
93 95
94 backend.flush(); 96 backend.flush();
95 microLeap(); 97 microLeap();
96 98
97 expect(renderedText(element)).toEqual('Simple!'); 99 expect(renderedText(element)).toEqual('Simple!');
98 $rootScope.$digest(); 100 $rootScope.apply();
99 // Note: There is no ordering. It is who ever comes off the wire first! 101 // Note: There is no ordering. It is who ever comes off the wire first!
100 expect(log.result()).toEqual('LOG; SIMPLE'); 102 expect(log.result()).toEqual('LOG; SIMPLE');
101 }))); 103 })));
102 104
103 it('should load template from URL once', async(inject((Http $http, 105 it('should load template from URL once', async(inject((Http $http,
104 Compiler $compile, Scope $rootScope, Logger log, Injector injector, 106 Compiler $compile, Scope $rootScope, Logger log, Injector injector,
105 MockHttpBackend backend) { 107 MockHttpBackend backend, DirectiveMap directives) {
106 backend.whenGET('simple.html').respond('<div log="SIMPLE">Simple!</div>'); 108 backend.whenGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
107 109
108 var element = $( 110 var element = $(
109 '<div>' + 111 '<div>' +
110 '<simple-url log>ignore</simple-url>' + 112 '<simple-url log>ignore</simple-url>' +
111 '<simple-url log>ignore</simple-url>' + 113 '<simple-url log>ignore</simple-url>' +
112 '<div>'); 114 '<div>');
113 $compile(element)(injector, element); 115 $compile(element, directives)(injector, element);
114 116
115 backend.flush(); 117 backend.flush();
116 microLeap(); 118 microLeap();
117 119
118 expect(renderedText(element)).toEqual('Simple!Simple!'); 120 expect(renderedText(element)).toEqual('Simple!Simple!');
119 $rootScope.$digest(); 121 $rootScope.apply();
120 // Note: There is no ordering. It is who ever comes off the wire first! 122 // Note: There is no ordering. It is who ever comes off the wire first!
121 expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE'); 123 expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE');
122 }))); 124 })));
123 125
124 it('should load a CSS file into a style', async(inject((Http $http, 126 it('should load a CSS file into a style', async(inject((Http $http,
125 Compiler $compile, Scope $rootScope, Logger log, Injector injector, 127 Compiler $compile, Scope $rootScope, Logger log, Injector injector,
126 MockHttpBackend backend) { 128 MockHttpBackend backend, DirectiveMap directives) {
127 backend.expectGET('simple.css').respond('.hello{}'); 129 backend
128 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>' ); 130 ..expectGET('simple.css').respond('.hello{}')
131 ..expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
129 132
130 var element = $('<div><html-and-css log>ignore</html-and-css><div>'); 133 var element = $('<div><html-and-css log>ignore</html-and-css><div>');
131 $compile(element)(injector, element); 134 $compile(element, directives)(injector, element);
132 135
133 backend.flush(); 136 backend.flush();
134 microLeap(); 137 microLeap();
135 138
136 expect(renderedText(element)).toEqual('.hello{}Simple!'); 139 expect(renderedText(element)).toEqual('.hello{}Simple!');
137 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( 140 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
138 '<style>.hello{}</style><div log="SIMPLE">Simple!</div>' 141 '<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
139 ); 142 );
140 $rootScope.$digest(); 143 $rootScope.apply();
141 // Note: There is no ordering. It is who ever comes off the wire first! 144 // Note: There is no ordering. It is who ever comes off the wire first!
142 expect(log.result()).toEqual('LOG; SIMPLE'); 145 expect(log.result()).toEqual('LOG; SIMPLE');
143 }))); 146 })));
144 147
145 it('should load a CSS file with a \$template', async(inject((Http $http, 148 it('should load a CSS file with a \$template', async(inject((Http $http,
146 Compiler $compile, Scope $rootScope, Injector injector, MockHttpBacke nd backend) { 149 Compiler $compile, Scope $rootScope, Injector injector,
150 MockHttpBackend backend, DirectiveMap directives) {
147 var element = $('<div><inline-with-css log>ignore</inline-with-css><div>') ; 151 var element = $('<div><inline-with-css log>ignore</inline-with-css><div>') ;
148 backend.expectGET('simple.css').respond('.hello{}'); 152 backend.expectGET('simple.css').respond('.hello{}');
149 $compile(element)(injector, element); 153 $compile(element, directives)(injector, element);
150 154
151 backend.flush(); 155 backend.flush();
152 microLeap(); 156 microLeap();
153 expect(renderedText(element)).toEqual('.hello{}inline!'); 157 expect(renderedText(element)).toEqual('.hello{}inline!');
154 }))); 158 })));
155 159
156 it('should load a CSS with no template', async(inject((Http $http, 160 it('should ignore CSS load errors ', async(inject((Http $http,
157 Compiler $compile, Scope $rootScope, Injector injector, MockHttpBacken d backend) { 161 Compiler $compile, Scope $rootScope, Injector injector,
158 var element = $('<div><only-css log>ignore</only-css><div>'); 162 MockHttpBackend backend, DirectiveMap directives) {
159 backend.expectGET('simple.css').respond('.hello{}'); 163 var element = $('<div><inline-with-css log>ignore</inline-with-css><div>') ;
160 $compile(element)(injector, element); 164 backend.expectGET('simple.css').respond(500, 'some error');
165 $compile(element, directives)(injector, element);
161 166
162 backend.flush(); 167 backend.flush();
163 microLeap(); 168 microLeap();
169 expect(renderedText(element)).toEqual(
170 '/*\n'
171 'HTTP 500: some error\n'
172 '*/\n'
173 'inline!');
174 })));
175
176 it('should load a CSS with no template', async(inject((Http $http,
177 Compiler $compile, Scope $rootScope, Injector injector,
178 MockHttpBackend backend, DirectiveMap directives) {
179 var element = $('<div><only-css log>ignore</only-css><div>');
180 backend.expectGET('simple.css').respond('.hello{}');
181 $compile(element, directives)(injector, element);
182
183 backend.flush();
184 microLeap();
164 expect(renderedText(element)).toEqual('.hello{}'); 185 expect(renderedText(element)).toEqual('.hello{}');
165 }))); 186 })));
166 187
167 it('should load the CSS before the template is loaded', async(inject((Http $ http, 188 it('should load the CSS before the template is loaded', async(inject((Http $ http,
168 Compiler $compile, Scope $rootScope, Injector injector, MockHttpBacken d backend) { 189 Compiler $compile, Scope $rootScope, Injector injector,
169 backend.expectGET('simple.css').respond('.hello{}'); 190 MockHttpBackend backend, DirectiveMap directives) {
170 backend.expectGET('simple.html').respond('<div>Simple!</div>'); 191 backend
192 ..expectGET('simple.css').respond('.hello{}')
193 ..expectGET('simple.html').respond('<div>Simple!</div>');
171 194
172 var element = $('<html-and-css>ignore</html-and-css>'); 195 var element = $('<html-and-css>ignore</html-and-css>');
173 $compile(element)(injector, element); 196 $compile(element, directives)(injector, element);
174 197
175 backend.flush(); 198 backend.flush();
176 microLeap(); 199 microLeap();
177 expect(renderedText(element)).toEqual('.hello{}Simple!'); 200 expect(renderedText(element)).toEqual('.hello{}Simple!');
178 }))); 201 })));
179 }); 202 });
180 203
181 describe('multiple css loading', () { 204 describe('multiple css loading', () {
182 beforeEach(module((Module module) { 205 beforeEach(module((Module module) {
183 module.type(LogAttrDirective); 206 module
184 module.type(HtmlAndMultipleCssComponent); 207 ..type(LogAttrDirective)
208 ..type(HtmlAndMultipleCssComponent);
185 })); 209 }));
186 210
187 it('should load multiple CSS files into a style', async(inject((Http $http, 211 it('should load multiple CSS files into a style', async(inject((Http $http,
188 Compiler $compile, Scope $rootScope, Logger log, Injector injector, 212 Compiler $compile, Scope $rootScope, Logger log, Injector injector,
189 MockHttpBackend backend) { 213 MockHttpBackend backend, DirectiveMap directives) {
190 backend.expectGET('simple.css').respond('.hello{}'); 214 backend
191 backend.expectGET('another.css').respond('.world{}'); 215 ..expectGET('simple.css').respond('.hello{}')
192 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>' ); 216 ..expectGET('another.css').respond('.world{}')
217 ..expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
193 218
194 var element = $('<div><html-and-css log>ignore</html-and-css><div>'); 219 var element = $('<div><html-and-css log>ignore</html-and-css><div>');
195 $compile(element)(injector, element); 220 $compile(element, directives)(injector, element);
196 221
197 backend.flush(); 222 backend.flush();
198 microLeap(); 223 microLeap();
199 224
200 expect(renderedText(element)).toEqual('.hello{}.world{}Simple!'); 225 expect(renderedText(element)).toEqual('.hello{}.world{}Simple!');
201 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( 226 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
202 '<style>.hello{}.world{}</style><div log="SIMPLE">Simple!</div>' 227 '<style>.hello{}.world{}</style><div log="SIMPLE">Simple!</div>'
203 ); 228 );
204 $rootScope.$digest(); 229 $rootScope.apply();
205 // Note: There is no ordering. It is who ever comes off the wire first! 230 // Note: There is no ordering. It is who ever comes off the wire first!
206 expect(log.result()).toEqual('LOG; SIMPLE'); 231 expect(log.result()).toEqual('LOG; SIMPLE');
207 }))); 232 })));
208 }); 233 });
209 }); 234 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698