| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {ddescribe, describe, it, iit, expect, beforeEach} from '@angular/core/testing'; | 
					
						
							|  |  |  | import {ViewResolver} from '@angular/compiler/src/view_resolver'; | 
					
						
							|  |  |  | import {Component, ViewMetadata} from '@angular/core/src/metadata'; | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SomeDir {} | 
					
						
							|  |  |  | class SomePipe {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'sample', | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |   template: "some template", | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  |   directives: [SomeDir], | 
					
						
							|  |  |  |   pipes: [SomePipe], | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |   styles: ["some styles"] | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | class ComponentWithView { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'sample', | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |   template: "some template", | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  |   directives: [SomeDir], | 
					
						
							|  |  |  |   pipes: [SomePipe], | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |   styles: ["some styles"] | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | }) | 
					
						
							|  |  |  | class ComponentWithTemplate { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | @Component({selector: 'sample', template: "some template"}) | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | class ComponentWithViewTemplate { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | @Component({selector: 'sample', templateUrl: "some template url", template: "some template"}) | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | class ComponentWithViewTemplateUrl { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 19:14:45 -07:00
										 |  |  | @Component({selector: 'sample'}) | 
					
						
							|  |  |  | class ComponentWithoutView { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SimpleClass {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |   describe("ViewResolver", () => { | 
					
						
							| 
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 |  |  |     var resolver: ViewResolver; | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { resolver = new ViewResolver(); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should read out the View metadata from the Component metadata', () => { | 
					
						
							|  |  |  |       var viewMetadata = resolver.resolve(ComponentWithTemplate); | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |       expect(viewMetadata) | 
					
						
							|  |  |  |           .toEqual(new ViewMetadata({ | 
					
						
							|  |  |  |             template: "some template", | 
					
						
							|  |  |  |             directives: [SomeDir], | 
					
						
							|  |  |  |             pipes: [SomePipe], | 
					
						
							|  |  |  |             styles: ["some styles"] | 
					
						
							|  |  |  |           })); | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw when Component has no View decorator and no template is set', () => { | 
					
						
							|  |  |  |       expect(() => resolver.resolve(ComponentWithoutView)) | 
					
						
							|  |  |  |           .toThrowErrorWith( | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |               "Component 'ComponentWithoutView' must have either 'template' or 'templateUrl' set"); | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw when simple class has no View decorator and no template is set', () => { | 
					
						
							|  |  |  |       expect(() => resolver.resolve(SimpleClass)) | 
					
						
							| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  |           .toThrowErrorWith("Could not compile 'SimpleClass' because it is not a component."); | 
					
						
							| 
									
										
										
										
											2015-10-06 17:03:37 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |