| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   afterEach, | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   beforeEachBindings | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  | import {Component, View, provide} from 'angular2/core'; | 
					
						
							| 
									
										
										
										
											2015-11-06 17:34:07 -08:00
										 |  |  | import {PromiseWrapper} from 'angular2/src/facade/async'; | 
					
						
							| 
									
										
										
										
											2015-11-05 14:07:57 -08:00
										 |  |  | import {SpyProtoViewFactory} from '../core/spies'; | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   CompiledHostTemplate, | 
					
						
							| 
									
										
										
										
											2015-11-02 08:39:14 -08:00
										 |  |  |   CompiledComponentTemplate, | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |   BeginComponentCmd | 
					
						
							| 
									
										
										
										
											2015-10-02 07:37:23 -07:00
										 |  |  | } from 'angular2/src/core/linker/template_commands'; | 
					
						
							| 
									
										
										
										
											2015-11-05 14:07:57 -08:00
										 |  |  | import {RuntimeCompiler} from 'angular2/src/compiler/runtime_compiler'; | 
					
						
							| 
									
										
										
										
											2015-10-02 07:37:23 -07:00
										 |  |  | import {ProtoViewFactory} from 'angular2/src/core/linker/proto_view_factory'; | 
					
						
							|  |  |  | import {AppProtoView} from 'angular2/src/core/linker/view'; | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('RuntimeCompiler', () => { | 
					
						
							|  |  |  |     var compiler: RuntimeCompiler; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(inject([RuntimeCompiler], (_compiler) => { compiler = _compiler; })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('compileInHost', () => { | 
					
						
							|  |  |  |       var protoViewFactorySpy; | 
					
						
							|  |  |  |       var someProtoView; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beforeEachBindings(() => { | 
					
						
							|  |  |  |         protoViewFactorySpy = new SpyProtoViewFactory(); | 
					
						
							| 
									
										
										
										
											2015-11-02 08:39:14 -08:00
										 |  |  |         someProtoView = new AppProtoView(null, null, null, null, null, null, null); | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |         protoViewFactorySpy.spy('createHost').andReturn(someProtoView); | 
					
						
							| 
									
										
										
										
											2015-10-12 11:30:34 -07:00
										 |  |  |         return [provide(ProtoViewFactory, {useValue: protoViewFactorySpy})]; | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should compile the template via TemplateCompiler', | 
					
						
							|  |  |  |          inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |            var cht: CompiledHostTemplate; | 
					
						
							|  |  |  |            protoViewFactorySpy.spy('createHost') | 
					
						
							|  |  |  |                .andCallFake((_cht) => { | 
					
						
							|  |  |  |                  cht = _cht; | 
					
						
							|  |  |  |                  return someProtoView; | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |            compiler.compileInHost(SomeComponent) | 
					
						
							|  |  |  |                .then((_) => { | 
					
						
							| 
									
										
										
										
											2015-11-02 08:39:14 -08:00
										 |  |  |                  var beginComponentCmd = <BeginComponentCmd>cht.template.commands[0]; | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |                  expect(beginComponentCmd.name).toEqual('some-comp'); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should cache the result', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |          PromiseWrapper | 
					
						
							|  |  |  |              .all([compiler.compileInHost(SomeComponent), compiler.compileInHost(SomeComponent)]) | 
					
						
							|  |  |  |              .then((protoViewRefs) => { | 
					
						
							|  |  |  |                expect(protoViewRefs[0]).toBe(protoViewRefs[1]); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should clear the cache', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => {compiler.compileInHost(SomeComponent) | 
					
						
							|  |  |  |                                                     .then((protoViewRef1) => { | 
					
						
							|  |  |  |                                                       compiler.clearCache(); | 
					
						
							|  |  |  |                                                       compiler.compileInHost(SomeComponent) | 
					
						
							|  |  |  |                                                           .then((protoViewRef2) => { | 
					
						
							|  |  |  |                                                             expect(protoViewRef1) | 
					
						
							|  |  |  |                                                                 .not.toBe(protoViewRef2); | 
					
						
							|  |  |  |                                                             async.done(); | 
					
						
							|  |  |  |                                                           }); | 
					
						
							|  |  |  |                                                     })})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'some-comp'}) | 
					
						
							|  |  |  | @View({template: ''}) | 
					
						
							|  |  |  | class SomeComponent { | 
					
						
							| 
									
										
										
										
											2015-10-02 07:37:23 -07:00
										 |  |  | } |