| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   dispatchEvent, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   beforeEachBindings, | 
					
						
							|  |  |  |   it, | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |   xit, | 
					
						
							|  |  |  |   TestComponentBuilder | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 15:55:43 -08:00
										 |  |  | import {Injectable, provide} from 'angular2/core'; | 
					
						
							|  |  |  | import {NgIf} from 'angular2/common'; | 
					
						
							| 
									
										
										
										
											2015-09-03 22:01:36 -07:00
										 |  |  | import {Directive, Component, View, ViewMetadata} from 'angular2/src/core/metadata'; | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | @Component({selector: 'child-child-comp'}) | 
					
						
							|  |  |  | @View({template: `<span>ChildChild</span>`}) | 
					
						
							|  |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | class ChildChildComp { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'child-comp'}) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | @View({ | 
					
						
							|  |  |  |   template: `<span>Original {{childBinding}}(<child-child-comp></child-child-comp>)</span>`, | 
					
						
							|  |  |  |   directives: [ChildChildComp] | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class ChildWithChildComp { | 
					
						
							|  |  |  |   childBinding: string; | 
					
						
							|  |  |  |   constructor() { this.childBinding = 'Child'; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'child-child-comp'}) | 
					
						
							|  |  |  | @View({template: `<span>ChildChild Mock</span>`}) | 
					
						
							|  |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | class MockChildChildComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FancyService { | 
					
						
							|  |  |  |   value: string = 'real value'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockFancyService extends FancyService { | 
					
						
							|  |  |  |   value: string = 'mocked out value'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'my-service-comp', bindings: [FancyService]}) | 
					
						
							|  |  |  | @View({template: `injected value: {{fancyService.value}}`}) | 
					
						
							|  |  |  | class TestBindingsComp { | 
					
						
							|  |  |  |   constructor(private fancyService: FancyService) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  | @Component({selector: 'my-service-comp', viewProviders: [FancyService]}) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | @View({template: `injected value: {{fancyService.value}}`}) | 
					
						
							|  |  |  | class TestViewBindingsComp { | 
					
						
							|  |  |  |   constructor(private fancyService: FancyService) {} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   describe('test component builder', function() { | 
					
						
							|  |  |  |     it('should instantiate a component with valid DOM', | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |          tcb.createAsync(ChildComp).then((componentFixture) => { | 
					
						
							|  |  |  |            componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |            expect(componentFixture.debugElement.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-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |          tcb.createAsync(MyIfComp).then((componentFixture) => { | 
					
						
							|  |  |  |            componentFixture.detectChanges(); | 
					
						
							|  |  |  |            expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf()'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |            componentFixture.debugElement.componentInstance.showMore = true; | 
					
						
							|  |  |  |            componentFixture.detectChanges(); | 
					
						
							|  |  |  |            expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf(More)'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override a template', | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |          tcb.overrideTemplate(MockChildComp, '<span>Mock</span>') | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |              .createAsync(MockChildComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement).toHaveText('Mock'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override a view', | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |          tcb.overrideView(ChildComp, | 
					
						
							| 
									
										
										
										
											2015-08-14 10:03:45 -07:00
										 |  |  |                           new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'})) | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |              .createAsync(ChildComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement).toHaveText('Modified Child'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override component dependencies', | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |          tcb.overrideDirective(ParentComp, ChildComp, MockChildComp) | 
					
						
							|  |  |  |              .createAsync(ParentComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement).toHaveText('Parent(Mock)'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should override child component's dependencies", | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |          tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp) | 
					
						
							|  |  |  |              .overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp) | 
					
						
							|  |  |  |              .createAsync(ParentComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  |                    .toHaveText('Parent(Original Child(ChildChild Mock))'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |     it('should override a provider', | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |          tcb.overrideProviders(TestBindingsComp, | 
					
						
							| 
									
										
										
										
											2015-10-12 11:30:34 -07:00
										 |  |  |                                [provide(FancyService, {useClass: MockFancyService})]) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  |              .createAsync(TestBindingsComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  |                    .toHaveText('injected value: mocked out value'); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override a viewBinding', | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |          tcb.overrideViewProviders(TestViewBindingsComp, | 
					
						
							| 
									
										
										
										
											2015-10-12 11:30:34 -07:00
										 |  |  |                                    [provide(FancyService, {useClass: MockFancyService})]) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  |              .createAsync(TestViewBindingsComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  |                    .toHaveText('injected value: mocked out value'); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |