| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | import {ViewEncapsulation, ɵɵdefineInjectable, ɵɵdefineInjector} from '../../src/core'; | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  | import {createInjector} from '../../src/di/r3_injector'; | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  | import {AttributeMarker, ComponentFactory, LifecycleHooksFeature, getRenderedText, markDirty, ɵɵdefineComponent, ɵɵdirectiveInject, ɵɵproperty, ɵɵselect, ɵɵtemplate} from '../../src/render3/index'; | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  | import {tick, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵnextContext, ɵɵtext, ɵɵtextInterpolate} from '../../src/render3/instructions/all'; | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  | import {ComponentDef, RenderFlags} from '../../src/render3/interfaces/definition'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  | import {NgIf} from './common_with_def'; | 
					
						
							| 
									
										
										
										
											2018-12-10 23:40:19 -08:00
										 |  |  | import {ComponentFixture, MockRendererFactory, containerEl, createComponent, renderComponent, renderToHtml, requestAnimationFrame, toHtml} from './render_util'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('component', () => { | 
					
						
							|  |  |  |   class CounterComponent { | 
					
						
							|  |  |  |     count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     increment() { this.count++; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |     static ngFactoryDef = () => new CounterComponent; | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |     static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |       type: CounterComponent, | 
					
						
							| 
									
										
										
										
											2018-07-31 11:14:06 -07:00
										 |  |  |       encapsulation: ViewEncapsulation.None, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |       selectors: [['counter']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       consts: 1, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       vars: 1, | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       template: function(rf: RenderFlags, ctx: CounterComponent) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵtext(0); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |           ɵɵselect(0); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |           ɵɵtextInterpolate(ctx.count); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       }, | 
					
						
							|  |  |  |       inputs: {count: 'count'}, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('renderComponent', () => { | 
					
						
							|  |  |  |     it('should render on initial call', () => { | 
					
						
							|  |  |  |       renderComponent(CounterComponent); | 
					
						
							| 
									
										
										
										
											2018-01-03 11:42:48 +01:00
										 |  |  |       expect(toHtml(containerEl)).toEqual('0'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should re-render on input change or method invocation', () => { | 
					
						
							|  |  |  |       const component = renderComponent(CounterComponent); | 
					
						
							| 
									
										
										
										
											2018-01-03 11:42:48 +01:00
										 |  |  |       expect(toHtml(containerEl)).toEqual('0'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       component.count = 123; | 
					
						
							| 
									
										
										
										
											2018-02-03 20:34:30 -08:00
										 |  |  |       markDirty(component); | 
					
						
							| 
									
										
										
										
											2018-01-03 11:42:48 +01:00
										 |  |  |       expect(toHtml(containerEl)).toEqual('0'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       requestAnimationFrame.flush(); | 
					
						
							| 
									
										
										
										
											2018-01-03 11:42:48 +01:00
										 |  |  |       expect(toHtml(containerEl)).toEqual('123'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       component.increment(); | 
					
						
							| 
									
										
										
										
											2018-02-03 20:34:30 -08:00
										 |  |  |       markDirty(component); | 
					
						
							| 
									
										
										
										
											2018-01-03 11:42:48 +01:00
										 |  |  |       expect(toHtml(containerEl)).toEqual('123'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       requestAnimationFrame.flush(); | 
					
						
							| 
									
										
										
										
											2018-01-03 11:42:48 +01:00
										 |  |  |       expect(toHtml(containerEl)).toEqual('124'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |     class MyService { | 
					
						
							|  |  |  |       constructor(public value: string) {} | 
					
						
							| 
									
										
										
										
											2019-06-07 10:12:07 -07:00
										 |  |  |       static ngInjectableDef = ɵɵdefineInjectable({ | 
					
						
							|  |  |  |         token: MyService, | 
					
						
							|  |  |  |         providedIn: 'root', | 
					
						
							|  |  |  |         factory: () => new MyService('no-injector'), | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |     class MyComponent { | 
					
						
							|  |  |  |       constructor(public myService: MyService) {} | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       static ngFactoryDef = () => new MyComponent(ɵɵdirectiveInject(MyService)); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |         type: MyComponent, | 
					
						
							| 
									
										
										
										
											2018-07-31 11:14:06 -07:00
										 |  |  |         encapsulation: ViewEncapsulation.None, | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |         selectors: [['my-component']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |         consts: 1, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |         vars: 1, | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |         template: function(fs: RenderFlags, ctx: MyComponent) { | 
					
						
							|  |  |  |           if (fs & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵtext(0); | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |           if (fs & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |             ɵɵselect(0); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |             ɵɵtextInterpolate(ctx.myService.value); | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class MyModule { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       static ngInjectorDef = ɵɵdefineInjector({ | 
					
						
							| 
									
										
										
										
											2018-04-12 15:54:16 -07:00
										 |  |  |         factory: () => new MyModule(), | 
					
						
							|  |  |  |         providers: [{provide: MyService, useValue: new MyService('injector')}] | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support bootstrapping without injector', () => { | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(MyComponent); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('no-injector'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support bootstrapping with injector', () => { | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(MyComponent, {injector: createInjector(MyModule)}); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual('injector'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 14:57:45 -08:00
										 |  |  |   it('should instantiate components at high indices', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // {{ name }}
 | 
					
						
							|  |  |  |     class Comp { | 
					
						
							|  |  |  |       // @Input
 | 
					
						
							|  |  |  |       name = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       static ngFactoryDef = () => new Comp(); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-26 14:57:45 -08:00
										 |  |  |         type: Comp, | 
					
						
							|  |  |  |         selectors: [['comp']], | 
					
						
							|  |  |  |         consts: 1, | 
					
						
							|  |  |  |         vars: 1, | 
					
						
							|  |  |  |         template: (rf: RenderFlags, ctx: Comp) => { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵtext(0); | 
					
						
							| 
									
										
										
										
											2018-11-26 14:57:45 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |           if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |             ɵɵselect(0); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |             ɵɵtextInterpolate(ctx.name); | 
					
						
							| 
									
										
										
										
											2018-11-26 14:57:45 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         inputs: {name: 'name'} | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Artificially inflating the slot IDs of this app component to mimic an app
 | 
					
						
							|  |  |  |     // with a very large view
 | 
					
						
							|  |  |  |     const App = createComponent('app', (rf: RenderFlags, ctx: any) => { | 
					
						
							|  |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵelement(4097, 'comp'); | 
					
						
							| 
									
										
										
										
											2018-11-26 14:57:45 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |         ɵɵselect(4097); | 
					
						
							|  |  |  |         ɵɵproperty('name', ctx.name); | 
					
						
							| 
									
										
										
										
											2018-11-26 14:57:45 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     }, 4098, 1, [Comp]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |     expect(fixture.html).toEqual('<comp></comp>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fixture.component.name = 'some name'; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(fixture.html).toEqual('<comp>some name</comp>'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-12-11 16:30:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 23:40:19 -08:00
										 |  |  | it('should not invoke renderer destroy method for embedded views', () => { | 
					
						
							|  |  |  |   let comp: Comp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function MyComponent_div_Template_2(rf: any, ctx: any) { | 
					
						
							|  |  |  |     if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵelementStart(0, 'div'); | 
					
						
							|  |  |  |       ɵɵtext(1, 'Child view'); | 
					
						
							|  |  |  |       ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-12-10 23:40:19 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class Comp { | 
					
						
							|  |  |  |     visible = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |     static ngFactoryDef = | 
					
						
							|  |  |  |         () => { | 
					
						
							|  |  |  |           comp = new Comp(); | 
					
						
							|  |  |  |           return comp; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |     static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-12-10 23:40:19 -08:00
										 |  |  |       type: Comp, | 
					
						
							|  |  |  |       selectors: [['comp']], | 
					
						
							|  |  |  |       consts: 3, | 
					
						
							|  |  |  |       vars: 1, | 
					
						
							|  |  |  |       directives: [NgIf], | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        *  <div>Root view</div> | 
					
						
							|  |  |  |        *  <div *ngIf="visible">Child view</div> | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       template: function(rf: RenderFlags, ctx: Comp) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵelementStart(0, 'div'); | 
					
						
							|  |  |  |           ɵɵtext(1, 'Root view'); | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							|  |  |  |           ɵɵtemplate( | 
					
						
							|  |  |  |               2, MyComponent_div_Template_2, 2, 0, 'div', [AttributeMarker.Template, 'ngIf']); | 
					
						
							| 
									
										
										
										
											2018-12-10 23:40:19 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |           ɵɵselect(2); | 
					
						
							|  |  |  |           ɵɵproperty('ngIf', ctx.visible); | 
					
						
							| 
									
										
										
										
											2018-12-10 23:40:19 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const rendererFactory = new MockRendererFactory(['destroy']); | 
					
						
							|  |  |  |   const fixture = new ComponentFixture(Comp, {rendererFactory}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   comp !.visible = false; | 
					
						
							|  |  |  |   fixture.update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   comp !.visible = true; | 
					
						
							|  |  |  |   fixture.update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const renderer = rendererFactory.lastRenderer !; | 
					
						
							|  |  |  |   const destroySpy = renderer.spies['destroy']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // we should never see `destroy` method being called
 | 
					
						
							|  |  |  |   // in case child views are created/removed
 | 
					
						
							|  |  |  |   expect(destroySpy.calls.count()).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  | describe('component with a container', () => { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |   function showItems(rf: RenderFlags, ctx: {items: string[]}) { | 
					
						
							|  |  |  |     if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵcontainer(0); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |     if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵcontainerRefreshStart(0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       { | 
					
						
							|  |  |  |         for (const item of ctx.items) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           const rf0 = ɵɵembeddedViewStart(0, 1, 1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							|  |  |  |             if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵtext(0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (rf0 & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |               ɵɵselect(0); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |               ɵɵtextInterpolate(item); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class WrapperComponent { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |     // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |     items !: string[]; | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |     static ngFactoryDef = () => new WrapperComponent; | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |     static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |       type: WrapperComponent, | 
					
						
							| 
									
										
										
										
											2018-07-31 11:14:06 -07:00
										 |  |  |       encapsulation: ViewEncapsulation.None, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |       selectors: [['wrapper']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       consts: 1, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       vars: 0, | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       template: function ChildComponentTemplate(rf: RenderFlags, ctx: {items: string[]}) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵcontainer(0); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵcontainerRefreshStart(0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             const rf0 = ɵɵembeddedViewStart(0, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             { showItems(rf0, {items: ctx.items}); } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       inputs: {items: 'items'} | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |   function template(rf: RenderFlags, ctx: {items: string[]}) { | 
					
						
							|  |  |  |     if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵelement(0, 'wrapper'); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |     if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |       ɵɵselect(0); | 
					
						
							|  |  |  |       ɵɵproperty('items', ctx.items); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 12:58:41 -07:00
										 |  |  |   const defs = [WrapperComponent]; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |   it('should re-render on input change', () => { | 
					
						
							|  |  |  |     const ctx: {items: string[]} = {items: ['a']}; | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |     expect(renderToHtml(template, ctx, 1, 1, defs)).toEqual('<wrapper>a</wrapper>'); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ctx.items = [...ctx.items, 'b']; | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |     expect(renderToHtml(template, ctx, 1, 1, defs)).toEqual('<wrapper>ab</wrapper>'); | 
					
						
							| 
									
										
										
										
											2018-01-25 15:32:21 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-12-11 16:30:46 +01:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('recursive components', () => { | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |   let events: string[]; | 
					
						
							|  |  |  |   let count: number; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							|  |  |  |     events = []; | 
					
						
							|  |  |  |     count = 0; | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   class TreeNode { | 
					
						
							|  |  |  |     constructor( | 
					
						
							|  |  |  |         public value: number, public depth: number, public left: TreeNode|null, | 
					
						
							|  |  |  |         public right: TreeNode|null) {} | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * {{ data.value }} | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * % if (data.left != null) { | 
					
						
							|  |  |  |    *   <tree-comp [data]="data.left"></tree-comp> | 
					
						
							|  |  |  |    * % } | 
					
						
							|  |  |  |    * % if (data.right != null) { | 
					
						
							|  |  |  |    *   <tree-comp [data]="data.right"></tree-comp> | 
					
						
							|  |  |  |    * % } | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |   class TreeComponent { | 
					
						
							|  |  |  |     data: TreeNode = _buildTree(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ngDoCheck() { events.push('check' + this.data.value); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |     ngOnDestroy() { events.push('destroy' + this.data.value); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |     static ngFactoryDef = () => new TreeComponent(); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |     static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |       type: TreeComponent, | 
					
						
							| 
									
										
										
										
											2018-07-31 11:14:06 -07:00
										 |  |  |       encapsulation: ViewEncapsulation.None, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |       selectors: [['tree-comp']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       consts: 3, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       vars: 1, | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       template: (rf: RenderFlags, ctx: TreeComponent) => { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵtext(0); | 
					
						
							|  |  |  |           ɵɵcontainer(1); | 
					
						
							|  |  |  |           ɵɵcontainer(2); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |           ɵɵselect(0); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |           ɵɵtextInterpolate(ctx.data.value); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵcontainerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							|  |  |  |             if (ctx.data.left != null) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               let rf0 = ɵɵembeddedViewStart(0, 1, 1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 ɵɵelement(0, 'tree-comp'); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf0 & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |                 ɵɵselect(0); | 
					
						
							|  |  |  |                 ɵɵproperty('data', ctx.data.left); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵcontainerRefreshEnd(); | 
					
						
							|  |  |  |           ɵɵcontainerRefreshStart(2); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							|  |  |  |             if (ctx.data.right != null) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               let rf0 = ɵɵembeddedViewStart(0, 1, 1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 ɵɵelement(0, 'tree-comp'); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf0 & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |                 ɵɵselect(0); | 
					
						
							|  |  |  |                 ɵɵproperty('data', ctx.data.right); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       inputs: {data: 'data'} | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-21 12:12:06 -07:00
										 |  |  |   (TreeComponent.ngComponentDef as ComponentDef<TreeComponent>).directiveDefs = | 
					
						
							| 
									
										
										
										
											2018-04-14 09:18:38 -07:00
										 |  |  |       () => [TreeComponent.ngComponentDef]; | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * {{ data.value }} | 
					
						
							|  |  |  |    *  <ng-if-tree [data]="data.left" *ngIf="data.left"></ng-if-tree> | 
					
						
							|  |  |  |    *  <ng-if-tree [data]="data.right" *ngIf="data.right"></ng-if-tree> | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   class NgIfTree { | 
					
						
							|  |  |  |     data: TreeNode = _buildTree(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-18 16:58:51 -08:00
										 |  |  |     ngDoCheck() { events.push('check' + this.data.value); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |     ngOnDestroy() { events.push('destroy' + this.data.value); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |     static ngFactoryDef = () => new NgIfTree(); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |     static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       type: NgIfTree, | 
					
						
							| 
									
										
										
										
											2018-07-31 11:14:06 -07:00
										 |  |  |       encapsulation: ViewEncapsulation.None, | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       selectors: [['ng-if-tree']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       consts: 3, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       vars: 3, | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       template: (rf: RenderFlags, ctx: NgIfTree) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵtext(0); | 
					
						
							|  |  |  |           ɵɵtemplate( | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |               1, IfTemplate, 1, 1, 'ng-if-tree', | 
					
						
							|  |  |  |               [AttributeMarker.Bindings, 'data', AttributeMarker.Template, 'ngIf']); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵtemplate( | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |               2, IfTemplate2, 1, 1, 'ng-if-tree', | 
					
						
							|  |  |  |               [AttributeMarker.Bindings, 'data', AttributeMarker.Template, 'ngIf']); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-31 14:41:07 -07:00
										 |  |  |           ɵɵselect(0); | 
					
						
							| 
									
										
										
										
											2019-08-27 16:44:11 +02:00
										 |  |  |           ɵɵtextInterpolate(ctx.data.value); | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |           ɵɵselect(1); | 
					
						
							| 
									
										
										
										
											2019-06-18 17:58:15 +02:00
										 |  |  |           ɵɵproperty('ngIf', ctx.data.left); | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |           ɵɵselect(2); | 
					
						
							|  |  |  |           ɵɵproperty('ngIf', ctx.data.right); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       inputs: {data: 'data'}, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |   function IfTemplate(rf: RenderFlags, left: any) { | 
					
						
							|  |  |  |     if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵelementStart(0, 'ng-if-tree'); | 
					
						
							|  |  |  |       ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |     if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       const parent = ɵɵnextContext(); | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |       ɵɵselect(0); | 
					
						
							|  |  |  |       ɵɵproperty('data', parent.data.left); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |   function IfTemplate2(rf: RenderFlags, right: any) { | 
					
						
							|  |  |  |     if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       ɵɵelementStart(0, 'ng-if-tree'); | 
					
						
							|  |  |  |       ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |     if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       const parent = ɵɵnextContext(); | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |       ɵɵselect(0); | 
					
						
							|  |  |  |       ɵɵproperty('data', parent.data.right); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-21 12:12:06 -07:00
										 |  |  |   (NgIfTree.ngComponentDef as ComponentDef<NgIfTree>).directiveDefs = | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       () => [NgIfTree.ngComponentDef, NgIf.ngDirectiveDef]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  |   function _buildTree(currDepth: number): TreeNode { | 
					
						
							|  |  |  |     const children = currDepth < 2 ? _buildTree(currDepth + 1) : null; | 
					
						
							|  |  |  |     const children2 = currDepth < 2 ? _buildTree(currDepth + 1) : null; | 
					
						
							|  |  |  |     return new TreeNode(count++, currDepth, children, children2); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should check each component just once', () => { | 
					
						
							|  |  |  |     const comp = renderComponent(TreeComponent, {hostFeatures: [LifecycleHooksFeature]}); | 
					
						
							|  |  |  |     expect(getRenderedText(comp)).toEqual('6201534'); | 
					
						
							|  |  |  |     expect(events).toEqual(['check6', 'check2', 'check0', 'check1', 'check5', 'check3', 'check4']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     events = []; | 
					
						
							|  |  |  |     tick(comp); | 
					
						
							|  |  |  |     expect(events).toEqual(['check6', 'check2', 'check0', 'check1', 'check5', 'check3', 'check4']); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-05-09 16:49:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |   // This tests that the view tree is set up properly for recursive components
 | 
					
						
							|  |  |  |   it('should call onDestroys properly', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * % if (!skipContent) { | 
					
						
							|  |  |  |      *   <tree-comp></tree-comp> | 
					
						
							|  |  |  |      * % } | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainer(0); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainerRefreshStart(0); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |         if (!ctx.skipContent) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           const rf0 = ɵɵembeddedViewStart(0, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |           if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵelementStart(0, 'tree-comp'); | 
					
						
							|  |  |  |             ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |     }, 1, 0, [TreeComponent]); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |     expect(getRenderedText(fixture.component)).toEqual('6201534'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     events = []; | 
					
						
							|  |  |  |     fixture.component.skipContent = true; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(events).toEqual( | 
					
						
							|  |  |  |         ['destroy0', 'destroy1', 'destroy2', 'destroy3', 'destroy4', 'destroy5', 'destroy6']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should call onDestroys properly with ngIf', () => { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * % if (!skipContent) { | 
					
						
							|  |  |  |      *   <ng-if-tree></ng-if-tree> | 
					
						
							|  |  |  |      * % } | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainer(0); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainerRefreshStart(0); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |         if (!ctx.skipContent) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           const rf0 = ɵɵembeddedViewStart(0, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |           if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵelementStart(0, 'ng-if-tree'); | 
					
						
							|  |  |  |             ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |     }, 1, 0, [NgIfTree]); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |     expect(getRenderedText(fixture.component)).toEqual('6201534'); | 
					
						
							| 
									
										
										
										
											2018-12-18 16:58:51 -08:00
										 |  |  |     expect(events).toEqual(['check6', 'check2', 'check0', 'check1', 'check5', 'check3', 'check4']); | 
					
						
							| 
									
										
										
										
											2018-07-17 11:45:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     events = []; | 
					
						
							|  |  |  |     fixture.component.skipContent = true; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(events).toEqual( | 
					
						
							|  |  |  |         ['destroy0', 'destroy1', 'destroy2', 'destroy3', 'destroy4', 'destroy5', 'destroy6']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 16:49:39 -07:00
										 |  |  |   it('should map inputs minified & unminified names', async() => { | 
					
						
							|  |  |  |     class TestInputsComponent { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |       minifiedName !: string; | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       static ngFactoryDef = () => new TestInputsComponent(); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-05-09 16:49:39 -07:00
										 |  |  |         type: TestInputsComponent, | 
					
						
							| 
									
										
										
										
											2018-07-31 11:14:06 -07:00
										 |  |  |         encapsulation: ViewEncapsulation.None, | 
					
						
							| 
									
										
										
										
											2018-05-09 16:49:39 -07:00
										 |  |  |         selectors: [['test-inputs']], | 
					
						
							|  |  |  |         inputs: {minifiedName: 'unminifiedName'}, | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |         consts: 0, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |         vars: 0, | 
					
						
							| 
									
										
										
										
											2018-05-09 16:49:39 -07:00
										 |  |  |         template: function(rf: RenderFlags, ctx: TestInputsComponent): void { | 
					
						
							|  |  |  |           // Template not needed for this test
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const testInputsComponentFactory = new ComponentFactory(TestInputsComponent.ngComponentDef); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect([ | 
					
						
							|  |  |  |       {propName: 'minifiedName', templateName: 'unminifiedName'} | 
					
						
							|  |  |  |     ]).toEqual(testInputsComponentFactory.inputs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 11:48:09 -07:00
										 |  |  | }); |