| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   dispatchEvent, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   IS_DARTIUM, | 
					
						
							|  |  |  |   beforeEachBindings, | 
					
						
							|  |  |  |   it, | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |   xit, | 
					
						
							|  |  |  |   TestComponentBuilder | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | } from 'angular2/test_lib'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {Injectable} from 'angular2/di'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   Directive, | 
					
						
							|  |  |  |   Component, | 
					
						
							|  |  |  |   View, | 
					
						
							|  |  |  | } from 'angular2/annotations'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import * as viewAnn from 'angular2/src/core/annotations_impl/view'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {NgIf} from 'angular2/src/directives/ng_if'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'child-comp'}) | 
					
						
							| 
									
										
										
										
											2015-06-14 18:29:58 +02:00
										 |  |  | @View({template: `<span>Original {{childBinding}}</span>`, directives: []}) | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class ChildComp { | 
					
						
							|  |  |  |   childBinding: string; | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |   constructor() { this.childBinding = 'Child'; } | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'child-comp'}) | 
					
						
							|  |  |  | @View({template: `<span>Mock</span>`}) | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | class MockChildComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  | @Component({selector: 'parent-comp'}) | 
					
						
							|  |  |  | @View({template: `Parent(<child-comp></child-comp>)`, directives: [ChildComp]}) | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class ParentComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'my-if-comp'}) | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  | @View({template: `MyIf(<span *ng-if="showMore">More</span>)`, directives: [NgIf]}) | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class MyIfComp { | 
					
						
							|  |  |  |   showMore: boolean = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('test component builder', function() { | 
					
						
							|  |  |  |     it('should instantiate a component with valid DOM', | 
					
						
							|  |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |          tcb.createAsync(ChildComp).then((rootTestComponent) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |            rootTestComponent.detectChanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 14:26:02 -07:00
										 |  |  |            expect(rootTestComponent.nativeElement).toHaveText('Original Child'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |     it('should allow changing members of the component', | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |          tcb.createAsync(MyIfComp).then((rootTestComponent) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |            rootTestComponent.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-06-23 14:26:02 -07:00
										 |  |  |            expect(rootTestComponent.nativeElement).toHaveText('MyIf()'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |            rootTestComponent.componentInstance.showMore = true; | 
					
						
							|  |  |  |            rootTestComponent.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-06-23 14:26:02 -07:00
										 |  |  |            expect(rootTestComponent.nativeElement).toHaveText('MyIf(More)'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override a template', | 
					
						
							|  |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |          tcb.overrideTemplate(MockChildComp, '<span>Mock</span>') | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |              .createAsync(MockChildComp) | 
					
						
							|  |  |  |              .then((rootTestComponent) => { | 
					
						
							|  |  |  |                rootTestComponent.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-06-23 14:26:02 -07:00
										 |  |  |                expect(rootTestComponent.nativeElement).toHaveText('Mock'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override a view', | 
					
						
							|  |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          tcb.overrideView(ChildComp, | 
					
						
							|  |  |  |                           new viewAnn.View({template: '<span>Modified {{childBinding}}</span>'})) | 
					
						
							|  |  |  |              .createAsync(ChildComp) | 
					
						
							|  |  |  |              .then((rootTestComponent) => { | 
					
						
							|  |  |  |                rootTestComponent.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-06-23 14:26:02 -07:00
										 |  |  |                expect(rootTestComponent.nativeElement).toHaveText('Modified Child'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override component dependencies', | 
					
						
							|  |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          tcb.overrideDirective(ParentComp, ChildComp, MockChildComp) | 
					
						
							|  |  |  |              .createAsync(ParentComp) | 
					
						
							|  |  |  |              .then((rootTestComponent) => { | 
					
						
							|  |  |  |                rootTestComponent.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-06-23 14:26:02 -07:00
										 |  |  |                expect(rootTestComponent.nativeElement).toHaveText('Parent(Mock)'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |