| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {EventEmitter} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 16:42:13 -07:00
										 |  |  | import {defineComponent, defineDirective, tick} from '../../src/render3/index'; | 
					
						
							| 
									
										
										
										
											2018-03-27 11:01:52 -07:00
										 |  |  | import {NO_CHANGE, bind, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, listener, load, loadDirective, text, textBinding} from '../../src/render3/instructions'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 11:01:52 -07:00
										 |  |  | import {ComponentFixture, renderToHtml} from './render_util'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('elementProperty', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support bindings to properties', () => { | 
					
						
							|  |  |  |     function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |       if (cm) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementStart(0, 'span'); | 
					
						
							|  |  |  |         elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |       elementProperty(0, 'id', bind(ctx)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'testId')).toEqual('<span id="testId"></span>'); | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'otherId')).toEqual('<span id="otherId"></span>'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support creation time bindings to properties', () => { | 
					
						
							|  |  |  |     function expensive(ctx: string): any { | 
					
						
							|  |  |  |       if (ctx === 'cheapId') { | 
					
						
							|  |  |  |         return ctx; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         throw 'Too expensive!'; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function Template(ctx: string, cm: boolean) { | 
					
						
							|  |  |  |       if (cm) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementStart(0, 'span'); | 
					
						
							|  |  |  |         elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |       elementProperty(0, 'id', cm ? expensive(ctx) : NO_CHANGE); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'cheapId')).toEqual('<span id="cheapId"></span>'); | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'expensiveId')).toEqual('<span id="cheapId"></span>'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support interpolation for properties', () => { | 
					
						
							|  |  |  |     function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |       if (cm) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementStart(0, 'span'); | 
					
						
							|  |  |  |         elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-02-14 11:22:14 -08:00
										 |  |  |       elementProperty(0, 'id', interpolation1('_', ctx, '_')); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'testId')).toEqual('<span id="_testId_"></span>'); | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'otherId')).toEqual('<span id="_otherId_"></span>'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 16:42:13 -07:00
										 |  |  |   it('should support host bindings on root component', () => { | 
					
						
							|  |  |  |     class HostBindingComp { | 
					
						
							|  |  |  |       id = 'my-id'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngComponentDef = defineComponent({ | 
					
						
							|  |  |  |         type: HostBindingComp, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['host-binding-comp']], | 
					
						
							| 
									
										
										
										
											2018-03-16 16:42:13 -07:00
										 |  |  |         factory: () => new HostBindingComp(), | 
					
						
							|  |  |  |         hostBindings: (dirIndex: number, elIndex: number) => { | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           const instance = loadDirective(dirIndex) as HostBindingComp; | 
					
						
							| 
									
										
										
										
											2018-03-16 16:42:13 -07:00
										 |  |  |           elementProperty(elIndex, 'id', bind(instance.id)); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         template: (ctx: HostBindingComp, cm: boolean) => {} | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const fixture = new ComponentFixture(HostBindingComp); | 
					
						
							|  |  |  |     expect(fixture.hostElement.id).toBe('my-id'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fixture.component.id = 'other-id'; | 
					
						
							|  |  |  |     tick(fixture.component); | 
					
						
							|  |  |  |     expect(fixture.hostElement.id).toBe('other-id'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   describe('input properties', () => { | 
					
						
							|  |  |  |     let button: MyButton; | 
					
						
							|  |  |  |     let otherDir: OtherDir; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |     let otherDisabledDir: OtherDisabledDir; | 
					
						
							|  |  |  |     let idDir: IdDir; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     class MyButton { | 
					
						
							|  |  |  |       disabled: boolean; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |         type: MyButton, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['', 'myButton', '']], | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         factory: () => button = new MyButton(), | 
					
						
							|  |  |  |         inputs: {disabled: 'disabled'} | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class OtherDir { | 
					
						
							|  |  |  |       id: boolean; | 
					
						
							|  |  |  |       clickStream = new EventEmitter(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |         type: OtherDir, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['', 'otherDir', '']], | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         factory: () => otherDir = new OtherDir(), | 
					
						
							|  |  |  |         inputs: {id: 'id'}, | 
					
						
							|  |  |  |         outputs: {clickStream: 'click'} | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |     class OtherDisabledDir { | 
					
						
							|  |  |  |       disabled: boolean; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |         type: OtherDisabledDir, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['', 'otherDisabledDir', '']], | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         factory: () => otherDisabledDir = new OtherDisabledDir(), | 
					
						
							|  |  |  |         inputs: {disabled: 'disabled'} | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class IdDir { | 
					
						
							|  |  |  |       idNumber: number; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |         type: IdDir, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['', 'idDir', '']], | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         factory: () => idDir = new IdDir(), | 
					
						
							|  |  |  |         inputs: {idNumber: 'id'} | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 12:58:41 -07:00
										 |  |  |     const deps = [MyButton, OtherDir, OtherDisabledDir, IdDir]; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     it('should check input properties before setting (directives)', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       /** <button myButton otherDir [id]="id" [disabled]="isDisabled">Click me</button> */ | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'button', ['otherDir', '', 'myButton', '']); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           { text(1, 'Click me'); } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'disabled', bind(ctx.isDisabled)); | 
					
						
							|  |  |  |         elementProperty(0, 'id', bind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const ctx: any = {isDisabled: true, id: 0}; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, ctx, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button mybutton="" otherdir="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(true); | 
					
						
							|  |  |  |       expect(otherDir !.id).toEqual(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ctx.isDisabled = false; | 
					
						
							|  |  |  |       ctx.id = 1; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, ctx, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button mybutton="" otherdir="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(false); | 
					
						
							|  |  |  |       expect(otherDir !.id).toEqual(1); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support mixed element properties and input properties', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <button myButton [id]="id" [disabled]="isDisabled">Click me</button> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'button', ['myButton', '']); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           { text(1, 'Click me'); } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'disabled', bind(ctx.isDisabled)); | 
					
						
							|  |  |  |         elementProperty(0, 'id', bind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const ctx: any = {isDisabled: true, id: 0}; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(renderToHtml(Template, ctx, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button id="0" mybutton="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ctx.isDisabled = false; | 
					
						
							|  |  |  |       ctx.id = 1; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, ctx, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button id="1" mybutton="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should check that property is not an input property before setting (component)', () => { | 
					
						
							|  |  |  |       let comp: Comp; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       class Comp { | 
					
						
							|  |  |  |         id: number; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static ngComponentDef = defineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |           type: Comp, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |           selectors: [['comp']], | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           template: function(ctx: any, cm: boolean) {}, | 
					
						
							|  |  |  |           factory: () => comp = new Comp(), | 
					
						
							|  |  |  |           inputs: {id: 'id'} | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <comp [id]="id"></comp> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'comp'); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'id', bind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 12:58:41 -07:00
										 |  |  |       const deps = [Comp]; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {id: 1}, deps)).toEqual(`<comp></comp>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(comp !.id).toEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {id: 2}, deps)).toEqual(`<comp></comp>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(comp !.id).toEqual(2); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support two input properties with the same name', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <button myButton otherDisabledDir [disabled]="isDisabled">Click me</button> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'button', ['myButton', '', 'otherDisabledDir', '']); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           { text(1, 'Click me'); } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'disabled', bind(ctx.isDisabled)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const ctx: any = {isDisabled: true}; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, ctx, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button mybutton="" otherdisableddir="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(true); | 
					
						
							|  |  |  |       expect(otherDisabledDir !.disabled).toEqual(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ctx.isDisabled = false; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, ctx, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button mybutton="" otherdisableddir="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(false); | 
					
						
							|  |  |  |       expect(otherDisabledDir !.disabled).toEqual(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should set input property if there is an output first', () => { | 
					
						
							|  |  |  |       /** <button otherDir [id]="id" (click)="onClick()">Click me</button> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'button', ['otherDir', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |             listener('click', ctx.onClick.bind(ctx)); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |             text(1, 'Click me'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'id', bind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let counter = 0; | 
					
						
							|  |  |  |       const ctx: any = {id: 1, onClick: () => counter++}; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, ctx, deps)).toEqual(`<button otherdir="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(otherDir !.id).toEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       otherDir !.clickStream.next(); | 
					
						
							|  |  |  |       expect(counter).toEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ctx.id = 2; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       renderToHtml(Template, ctx, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(otherDir !.id).toEqual(2); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should support unrelated element properties at same index in if-else block', () => { | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * <button idDir [id]="id1">Click me</button>             // inputs: {'id': [0, 'idNumber']}
 | 
					
						
							|  |  |  |        * % if (condition) { | 
					
						
							|  |  |  |        *   <button [id]="id2">Click me too</button>             // inputs: null
 | 
					
						
							|  |  |  |        * % } else { | 
					
						
							|  |  |  |        *   <button otherDir [id]="id3">Click me too</button>   // inputs: {'id': [0, 'id']}
 | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'button', ['idDir', '']); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           { text(1, 'Click me'); } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           container(2); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'id', bind(ctx.id1)); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |         containerRefreshStart(2); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         { | 
					
						
							|  |  |  |           if (ctx.condition) { | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             if (embeddedViewStart(0)) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementStart(0, 'button'); | 
					
						
							|  |  |  |               { text(1, 'Click me too'); } | 
					
						
							|  |  |  |               elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |             elementProperty(0, 'id', bind(ctx.id2)); | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             if (embeddedViewStart(1)) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |               elementStart(0, 'button', ['otherDir', '']); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |               { text(1, 'Click me too'); } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |             elementProperty(0, 'id', bind(ctx.id3)); | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {condition: true, id1: 'one', id2: 'two', id3: 'three'}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button iddir="">Click me</button><button id="two">Click me too</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       expect(idDir !.idNumber).toEqual('one'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect( | 
					
						
							|  |  |  |           renderToHtml(Template, {condition: false, id1: 'four', id2: 'two', id3: 'three'}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<button iddir="">Click me</button><button otherdir="">Click me too</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       expect(idDir !.idNumber).toEqual('four'); | 
					
						
							|  |  |  |       expect(otherDir !.id).toEqual('three'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('attributes and input properties', () => { | 
					
						
							|  |  |  |     let myDir: MyDir; | 
					
						
							|  |  |  |     class MyDir { | 
					
						
							|  |  |  |       role: string; | 
					
						
							|  |  |  |       direction: string; | 
					
						
							|  |  |  |       changeStream = new EventEmitter(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |         type: MyDir, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['', 'myDir', '']], | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         factory: () => myDir = new MyDir(), | 
					
						
							|  |  |  |         inputs: {role: 'role', direction: 'dir'}, | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |         outputs: {changeStream: 'change'}, | 
					
						
							|  |  |  |         exportAs: 'myDir' | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let dirB: MyDirB; | 
					
						
							|  |  |  |     class MyDirB { | 
					
						
							|  |  |  |       roleB: string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |         type: MyDirB, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |         selectors: [['', 'myDirB', '']], | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         factory: () => dirB = new MyDirB(), | 
					
						
							|  |  |  |         inputs: {roleB: 'role'} | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 12:58:41 -07:00
										 |  |  |     const deps = [MyDir, MyDirB]; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     it('should set input property based on attribute if existing', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <div role="button" myDir></div> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'button', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {}, deps)).toEqual(`<div mydir="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('button'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should set input property and attribute if both defined', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <div role="button" [role]="role" myDir></div> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'button', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         elementProperty(0, 'role', bind(ctx.role)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {role: 'listbox'}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<div mydir="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('listbox'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       renderToHtml(Template, {role: 'button'}, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('button'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should set two directive input properties based on same attribute', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <div role="button" myDir myDirB></div> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'button', 'myDir', '', 'myDirB', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<div mydir="" mydirb="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('button'); | 
					
						
							|  |  |  |       expect(dirB !.roleB).toEqual('button'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should process two attributes on same directive', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <div role="button" dir="rtl" myDir></div> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'button', 'dir', 'rtl', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<div dir="rtl" mydir="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('button'); | 
					
						
							|  |  |  |       expect(myDir !.direction).toEqual('rtl'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should process attributes and outputs properly together', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <div role="button" (change)="onChange()" myDir></div> */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'button', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           { listener('change', ctx.onChange.bind(ctx)); } | 
					
						
							|  |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let counter = 0; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {onChange: () => counter++}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<div mydir="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('button'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       myDir !.changeStream.next(); | 
					
						
							|  |  |  |       expect(counter).toEqual(1); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should process attributes properly for directives with later indices', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * <div role="button" dir="rtl" myDir></div> | 
					
						
							|  |  |  |        * <div role="listbox" myDirB></div> | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'button', 'dir', 'rtl', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(1, 'div', ['role', 'listbox', 'myDirB', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {}, deps)) | 
					
						
							|  |  |  |           .toEqual( | 
					
						
							|  |  |  |               `<div dir="rtl" mydir="" role="button"></div><div mydirb="" role="listbox"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('button'); | 
					
						
							|  |  |  |       expect(myDir !.direction).toEqual('rtl'); | 
					
						
							|  |  |  |       expect(dirB !.roleB).toEqual('listbox'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |     it('should support attributes at same index inside an if-else block', () => { | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * <div role="listbox" myDir></div>          // initialInputs: [['role', 'listbox']]
 | 
					
						
							|  |  |  |        * | 
					
						
							|  |  |  |        * % if (condition) { | 
					
						
							|  |  |  |        *   <div role="button" myDirB></div>       // initialInputs: [['role', 'button']]
 | 
					
						
							|  |  |  |        * % } else { | 
					
						
							|  |  |  |        *   <div role="menu"></div>               // initialInputs: [null]
 | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           elementStart(0, 'div', ['role', 'listbox', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           elementEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           container(1); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |         containerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         { | 
					
						
							|  |  |  |           if (ctx.condition) { | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             if (embeddedViewStart(0)) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |               elementStart(0, 'div', ['role', 'button', 'myDirB', '']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             if (embeddedViewStart(1)) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementStart(0, 'div', ['role', 'menu']); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |               {} | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {condition: true}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<div mydir="" role="listbox"></div><div mydirb="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       expect(myDir !.role).toEqual('listbox'); | 
					
						
							|  |  |  |       expect(dirB !.roleB).toEqual('button'); | 
					
						
							|  |  |  |       expect((dirB !as any).role).toBeUndefined(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |       expect(renderToHtml(Template, {condition: false}, deps)) | 
					
						
							|  |  |  |           .toEqual(`<div mydir="" role="listbox"></div><div role="menu"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       expect(myDir !.role).toEqual('listbox'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     it('should process attributes properly inside a for loop', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class Comp { | 
					
						
							|  |  |  |         static ngComponentDef = defineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |           type: Comp, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |           selectors: [['comp']], | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           /** <div role="button" dir #dir="myDir"></div> {{ dir.role }} */ | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           template: function(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |             if (cm) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |               elementStart(0, 'div', ['role', 'button', 'myDir', ''], ['dir', 'myDir']); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementEnd(); | 
					
						
							| 
									
										
										
										
											2018-03-27 11:01:52 -07:00
										 |  |  |               text(2); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-03-27 11:01:52 -07:00
										 |  |  |             const tmp = load(1) as any; | 
					
						
							|  |  |  |             textBinding(2, bind(tmp.role)); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           factory: () => new Comp(), | 
					
						
							| 
									
										
										
										
											2018-03-29 12:58:41 -07:00
										 |  |  |           directives: () => [MyDir] | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * % for (let i = 0; i < 3; i++) { | 
					
						
							|  |  |  |        *     <comp></comp> | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       function Template(ctx: any, cm: boolean) { | 
					
						
							|  |  |  |         if (cm) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |           container(0); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         containerRefreshStart(0); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         { | 
					
						
							|  |  |  |           for (let i = 0; i < 2; i++) { | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             if (embeddedViewStart(0)) { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |               elementStart(0, 'comp'); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |               elementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  |             embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |         containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 12:58:41 -07:00
										 |  |  |       expect(renderToHtml(Template, {}, [Comp])) | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           .toEqual( | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |               `<comp><div mydir="" role="button"></div>button</comp><comp><div mydir="" role="button"></div>button</comp>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |