| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   el, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   TestComponentBuilder, | 
					
						
							| 
									
										
										
										
											2015-11-11 14:28:23 +01:00
										 |  |  |   beforeEachProviders | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |   CompileTypeMetadata, | 
					
						
							|  |  |  |   CompileTemplateMetadata | 
					
						
							| 
									
										
										
										
											2015-11-05 14:07:57 -08:00
										 |  |  | } from 'angular2/src/compiler/directive_metadata'; | 
					
						
							| 
									
										
										
										
											2015-10-05 10:10:07 -07:00
										 |  |  | import {ViewEncapsulation} from 'angular2/src/core/metadata/view'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-05 14:07:57 -08:00
										 |  |  | import {TemplateNormalizer} from 'angular2/src/compiler/template_normalizer'; | 
					
						
							|  |  |  | import {XHR} from 'angular2/src/compiler/xhr'; | 
					
						
							|  |  |  | import {MockXHR} from 'angular2/src/compiler/xhr_mock'; | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  | import {TEST_PROVIDERS} from './test_bindings'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('TemplateNormalizer', () => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |     var dirType: CompileTypeMetadata; | 
					
						
							| 
									
										
										
										
											2015-10-27 14:00:15 -07:00
										 |  |  |     var dirTypeWithHttpUrl: CompileTypeMetadata; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-11 14:28:23 +01:00
										 |  |  |     beforeEachProviders(() => TEST_PROVIDERS); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |       dirType = new CompileTypeMetadata({moduleUrl: 'package:some/module/a.js', name: 'SomeComp'}); | 
					
						
							| 
									
										
										
										
											2015-10-27 14:00:15 -07:00
										 |  |  |       dirTypeWithHttpUrl = | 
					
						
							|  |  |  |           new CompileTypeMetadata({moduleUrl: 'http://some/module/a.js', name: 'SomeComp'}); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('loadTemplate', () => { | 
					
						
							|  |  |  |       describe('inline template', () => { | 
					
						
							|  |  |  |         it('should store the template', | 
					
						
							|  |  |  |            inject([AsyncTestCompleter, TemplateNormalizer], | 
					
						
							|  |  |  |                   (async, normalizer: TemplateNormalizer) => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                     normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    encapsulation: null, | 
					
						
							|  |  |  |                                                    template: 'a', | 
					
						
							|  |  |  |                                                    templateUrl: null, | 
					
						
							|  |  |  |                                                    styles: [], | 
					
						
							|  |  |  |                                                    styleUrls: ['test.css'] | 
					
						
							|  |  |  |                                                  })) | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                         .then((template: CompileTemplateMetadata) => { | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           expect(template.template).toEqual('a'); | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                           expect(template.templateUrl).toEqual('package:some/module/a.js'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           async.done(); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                   })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |         it('should resolve styles on the annotation against the moduleUrl', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            inject([AsyncTestCompleter, TemplateNormalizer], | 
					
						
							|  |  |  |                   (async, normalizer: TemplateNormalizer) => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                     normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    encapsulation: null, | 
					
						
							|  |  |  |                                                    template: '', | 
					
						
							|  |  |  |                                                    templateUrl: null, | 
					
						
							|  |  |  |                                                    styles: [], | 
					
						
							|  |  |  |                                                    styleUrls: ['test.css'] | 
					
						
							|  |  |  |                                                  })) | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                         .then((template: CompileTemplateMetadata) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                           expect(template.styleUrls).toEqual(['package:some/module/test.css']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           async.done(); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                   })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |         it('should resolve styles in the template against the moduleUrl', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            inject([AsyncTestCompleter, TemplateNormalizer], | 
					
						
							|  |  |  |                   (async, normalizer: TemplateNormalizer) => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                     normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    encapsulation: null, | 
					
						
							|  |  |  |                                                    template: '<style>@import test.css</style>', | 
					
						
							|  |  |  |                                                    templateUrl: null, | 
					
						
							|  |  |  |                                                    styles: [], | 
					
						
							|  |  |  |                                                    styleUrls: [] | 
					
						
							|  |  |  |                                                  })) | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                         .then((template: CompileTemplateMetadata) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                           expect(template.styleUrls).toEqual(['package:some/module/test.css']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           async.done(); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                   })); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('templateUrl', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |         it('should load a template from a url that is resolved against moduleUrl', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            inject([AsyncTestCompleter, TemplateNormalizer, XHR], | 
					
						
							|  |  |  |                   (async, normalizer: TemplateNormalizer, xhr: MockXHR) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                     xhr.expect('package:some/module/sometplurl.html', 'a'); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                     normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    encapsulation: null, | 
					
						
							|  |  |  |                                                    template: null, | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                                                    templateUrl: 'sometplurl.html', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    styles: [], | 
					
						
							|  |  |  |                                                    styleUrls: ['test.css'] | 
					
						
							|  |  |  |                                                  })) | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                         .then((template: CompileTemplateMetadata) => { | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           expect(template.template).toEqual('a'); | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                           expect(template.templateUrl) | 
					
						
							|  |  |  |                               .toEqual('package:some/module/sometplurl.html'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           async.done(); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                     xhr.flush(); | 
					
						
							|  |  |  |                   })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |         it('should resolve styles on the annotation against the moduleUrl', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            inject([AsyncTestCompleter, TemplateNormalizer, XHR], | 
					
						
							|  |  |  |                   (async, normalizer: TemplateNormalizer, xhr: MockXHR) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                     xhr.expect('package:some/module/tpl/sometplurl.html', ''); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                     normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    encapsulation: null, | 
					
						
							|  |  |  |                                                    template: null, | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                                                    templateUrl: 'tpl/sometplurl.html', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    styles: [], | 
					
						
							|  |  |  |                                                    styleUrls: ['test.css'] | 
					
						
							|  |  |  |                                                  })) | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                         .then((template: CompileTemplateMetadata) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                           expect(template.styleUrls).toEqual(['package:some/module/test.css']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           async.done(); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                     xhr.flush(); | 
					
						
							|  |  |  |                   })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should resolve styles in the template against the templateUrl', | 
					
						
							|  |  |  |            inject([AsyncTestCompleter, TemplateNormalizer, XHR], | 
					
						
							|  |  |  |                   (async, normalizer: TemplateNormalizer, xhr: MockXHR) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                     xhr.expect('package:some/module/tpl/sometplurl.html', | 
					
						
							|  |  |  |                                '<style>@import test.css</style>'); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                     normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    encapsulation: null, | 
					
						
							|  |  |  |                                                    template: null, | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                                                    templateUrl: 'tpl/sometplurl.html', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                                                    styles: [], | 
					
						
							|  |  |  |                                                    styleUrls: [] | 
					
						
							|  |  |  |                                                  })) | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                         .then((template: CompileTemplateMetadata) => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                           expect(template.styleUrls).toEqual(['package:some/module/tpl/test.css']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                           async.done(); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                     xhr.flush(); | 
					
						
							|  |  |  |                   })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should throw if no template was specified', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            expect(() => normalizer.normalizeTemplate( | 
					
						
							|  |  |  |                       dirType, new CompileTemplateMetadata( | 
					
						
							|  |  |  |                                    {encapsulation: null, styles: [], styleUrls: []}))) | 
					
						
							|  |  |  |                .toThrowError('No template specified for component SomeComp'); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('normalizeLoadedTemplate', () => { | 
					
						
							|  |  |  |       it('should store the viewEncapsulationin the result', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            var viewEncapsulation = ViewEncapsulation.Native; | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, new CompileTemplateMetadata( | 
					
						
							|  |  |  |                             {encapsulation: viewEncapsulation, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.encapsulation).toBe(viewEncapsulation); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should keep the template as html', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), 'a', | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.template).toEqual('a') | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should collect ngContent', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '<ng-content select="a"></ng-content>', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.ngContentSelectors).toEqual(['a']); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should normalize ngContent wildcard selector', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                '<ng-content></ng-content><ng-content select></ng-content><ng-content select="*"></ng-content>', | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.ngContentSelectors).toEqual(['*', '*', '*']); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should collect top level styles in the template', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '<style>a</style>', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.styles).toEqual(['a']); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should collect styles inside in elements', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '<div><style>a</style></div>', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.styles).toEqual(['a']); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should collect styleUrls in the template', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '<link rel="stylesheet" href="aUrl">', 'package:some/module/'); | 
					
						
							|  |  |  |            expect(template.styleUrls).toEqual(['package:some/module/aUrl']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should collect styleUrls in elements', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '<div><link rel="stylesheet" href="aUrl"></div>', 'package:some/module/'); | 
					
						
							|  |  |  |            expect(template.styleUrls).toEqual(['package:some/module/aUrl']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should ignore link elements with non stylesheet rel attribute', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-12-03 15:53:44 -08:00
										 |  |  |                '<link href="b" rel="a">', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |            expect(template.styleUrls).toEqual([]); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-14 09:39:40 -07:00
										 |  |  |       it('should ignore link elements with absolute urls but non package: scheme', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							|  |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-12-03 15:53:44 -08:00
										 |  |  |                '<link href="http://some/external.css" rel="stylesheet">', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-10-14 09:39:40 -07:00
										 |  |  |            expect(template.styleUrls).toEqual([]); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |       it('should extract @import style urls into styleAbsUrl', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, new CompileTemplateMetadata( | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                             {encapsulation: null, styles: ['@import "test.css";'], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '', 'package:some/module/id'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.styles).toEqual(['']); | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |            expect(template.styleUrls).toEqual(['package:some/module/test.css']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-14 09:39:40 -07:00
										 |  |  |       it('should not resolve relative urls in inline styles', | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, new CompileTemplateMetadata({ | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |                  encapsulation: null, | 
					
						
							|  |  |  |                  styles: ['.foo{background-image: url(\'double.jpg\');'], | 
					
						
							|  |  |  |                  styleUrls: [] | 
					
						
							|  |  |  |                }), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '', 'package:some/module/id'); | 
					
						
							| 
									
										
										
										
											2015-10-14 09:39:40 -07:00
										 |  |  |            expect(template.styles).toEqual(['.foo{background-image: url(\'double.jpg\');']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should resolve relative style urls in styleUrls', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                dirType, new CompileTemplateMetadata( | 
					
						
							|  |  |  |                             {encapsulation: null, styles: [], styleUrls: ['test.css']}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '', 'package:some/module/id'); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |            expect(template.styles).toEqual([]); | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |            expect(template.styleUrls).toEqual(['package:some/module/test.css']); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-27 14:00:15 -07:00
										 |  |  |       it('should resolve relative style urls in styleUrls with http directive url', | 
					
						
							|  |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							|  |  |  |                dirTypeWithHttpUrl, new CompileTemplateMetadata( | 
					
						
							|  |  |  |                                        {encapsulation: null, styles: [], styleUrls: ['test.css']}), | 
					
						
							|  |  |  |                '', 'http://some/module/id'); | 
					
						
							|  |  |  |            expect(template.styles).toEqual([]); | 
					
						
							|  |  |  |            expect(template.styleUrls).toEqual(['http://some/module/test.css']); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-16 15:47:48 +08:00
										 |  |  |       it('should normalize ViewEncapsulation.Emulated to ViewEncapsulation.None if there are no styles nor stylesheets', | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							|  |  |  |                dirType, new CompileTemplateMetadata( | 
					
						
							|  |  |  |                             {encapsulation: ViewEncapsulation.Emulated, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                '', 'package:some/module/id'); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |            expect(template.encapsulation).toEqual(ViewEncapsulation.None); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 |  |  |       it('should ignore ng-content in elements with ngNonBindable', | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							|  |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 |  |  |                '<div ngNonBindable><ng-content select="a"></ng-content></div>', | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |            expect(template.ngContentSelectors).toEqual([]); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 |  |  |       it('should still collect <style> in elements with ngNonBindable', | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |          inject([TemplateNormalizer], (normalizer: TemplateNormalizer) => { | 
					
						
							|  |  |  |            var template = normalizer.normalizeLoadedTemplate( | 
					
						
							|  |  |  |                dirType, | 
					
						
							|  |  |  |                new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), | 
					
						
							| 
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 |  |  |                '<div ngNonBindable><style>div {color:red}</style></div>', 'package:some/module/'); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |            expect(template.styles).toEqual(['div {color:red}']); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |