| 
									
										
										
										
											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'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  | import {ɵɵdefineComponent, ɵɵdefineDirective} from '../../src/render3/index'; | 
					
						
							|  |  |  | import {ɵɵbind, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵelement, ɵɵelementEnd, ɵɵelementProperty, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵinterpolation1, ɵɵlistener, ɵɵload, ɵɵreference, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all'; | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  | import {RenderFlags} from '../../src/render3/interfaces/definition'; | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 19:10:32 -07:00
										 |  |  | import {ComponentFixture, createComponent, renderToHtml} from './render_util'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('elementProperty', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support bindings to properties', () => { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |     const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         ɵɵelement(0, 'span'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |     }, 1, 1); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |     fixture.component.id = 'testId'; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(fixture.html).toEqual('<span id="testId"></span>'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |     fixture.component.id = 'otherId'; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(fixture.html).toEqual('<span id="otherId"></span>'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support creation time bindings to properties', () => { | 
					
						
							|  |  |  |     function expensive(ctx: string): any { | 
					
						
							|  |  |  |       if (ctx === 'cheapId') { | 
					
						
							|  |  |  |         return ctx; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         throw 'Too expensive!'; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |     function Template(rf: RenderFlags, ctx: string) { | 
					
						
							|  |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         ɵɵelement(0, 'span'); | 
					
						
							|  |  |  |         ɵɵelementProperty(0, 'id', expensive(ctx)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |     expect(renderToHtml(Template, 'cheapId', 1)).toEqual('<span id="cheapId"></span>'); | 
					
						
							|  |  |  |     expect(renderToHtml(Template, 'expensiveId', 1)).toEqual('<span id="cheapId"></span>'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support interpolation for properties', () => { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |     const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         ɵɵelement(0, 'span'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         ɵɵelementProperty(0, 'id', ɵɵinterpolation1('_', ctx.id, '_')); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |     }, 1, 1); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |     const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |     fixture.component.id = 'testId'; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(fixture.html).toEqual('<span id="_testId_"></span>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fixture.component.id = 'otherId'; | 
					
						
							|  |  |  |     fixture.update(); | 
					
						
							|  |  |  |     expect(fixture.html).toEqual('<span id="_otherId_"></span>'); | 
					
						
							| 
									
										
										
										
											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 { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |       disabled !: boolean; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |       static ngDirectiveDef = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         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 { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							| 
									
										
										
										
											2017-10-24 14:54:08 +03:00
										 |  |  |       id !: number; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       clickStream = new EventEmitter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |       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 { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |       disabled !: boolean; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |       static ngDirectiveDef = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         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 { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							| 
									
										
										
										
											2017-10-24 14:54:08 +03:00
										 |  |  |       idNumber !: string; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |       static ngDirectiveDef = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementStart(0, 'button', ['otherDir', '', 'myButton', '']); | 
					
						
							|  |  |  |           { ɵɵtext(1, 'Click me'); } | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'disabled', ɵɵbind(ctx.isDisabled)); | 
					
						
							|  |  |  |           ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 2, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.isDisabled = true; | 
					
						
							|  |  |  |       fixture.component.id = 0; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.isDisabled = false; | 
					
						
							|  |  |  |       fixture.component.id = 1; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementStart(0, 'button', ['myButton', '']); | 
					
						
							|  |  |  |           { ɵɵtext(1, 'Click me'); } | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'disabled', ɵɵbind(ctx.isDisabled)); | 
					
						
							|  |  |  |           ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 2, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.isDisabled = true; | 
					
						
							|  |  |  |       fixture.component.id = 0; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual(`<button id="0" mybutton="">Click me</button>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(button !.disabled).toEqual(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.isDisabled = false; | 
					
						
							|  |  |  |       fixture.component.id = 1; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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 { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |         // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |         id !: number; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |           type: Comp, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |           selectors: [['comp']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |           consts: 0, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           vars: 0, | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           template: function(rf: RenderFlags, ctx: any) {}, | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           factory: () => comp = new Comp(), | 
					
						
							|  |  |  |           inputs: {id: 'id'} | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** <comp [id]="id"></comp> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'comp'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 1, [Comp]); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.id = 1; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual(`<comp></comp>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(comp !.id).toEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.id = 2; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementStart(0, 'button', ['myButton', '', 'otherDisabledDir', '']); | 
					
						
							|  |  |  |           { ɵɵtext(1, 'Click me'); } | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'disabled', ɵɵbind(ctx.isDisabled)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 1, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.isDisabled = true; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.isDisabled = false; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementStart(0, 'button', ['otherDir', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |             ɵɵlistener('click', () => ctx.onClick()); | 
					
						
							|  |  |  |             ɵɵtext(1, 'Click me'); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 1, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       let counter = 0; | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.id = 1; | 
					
						
							|  |  |  |       fixture.component.onClick = () => counter++; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.id = 2; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       fixture.html; | 
					
						
							| 
									
										
										
										
											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']}
 | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementStart(0, 'button', ['idDir', '']); | 
					
						
							|  |  |  |           { ɵɵtext(1, 'Click me'); } | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							|  |  |  |           ɵɵcontainer(2); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id1)); | 
					
						
							|  |  |  |           ɵɵcontainerRefreshStart(2); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							|  |  |  |             if (ctx.condition) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               let rf0 = ɵɵembeddedViewStart(0, 2, 1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelementStart(0, 'button'); | 
					
						
							|  |  |  |                 { ɵɵtext(1, 'Click me too'); } | 
					
						
							|  |  |  |                 ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf0 & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id2)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               let rf1 = ɵɵembeddedViewStart(1, 2, 1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelementStart(0, 'button', ['otherDir', '']); | 
					
						
							|  |  |  |                 { ɵɵtext(1, 'Click me too'); } | 
					
						
							|  |  |  |                 ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf1 & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelementProperty(0, 'id', ɵɵbind(ctx.id3)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 3, 1, deps); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.condition = true; | 
					
						
							|  |  |  |       fixture.component.id1 = 'one'; | 
					
						
							|  |  |  |       fixture.component.id2 = 'two'; | 
					
						
							|  |  |  |       fixture.component.id3 = 3; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           .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-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.condition = false; | 
					
						
							|  |  |  |       fixture.component.id1 = 'four'; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           .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'); | 
					
						
							| 
									
										
										
										
											2017-10-24 14:54:08 +03:00
										 |  |  |       expect(otherDir !.id).toEqual(3); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('attributes and input properties', () => { | 
					
						
							|  |  |  |     let myDir: MyDir; | 
					
						
							|  |  |  |     class MyDir { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |       role !: string; | 
					
						
							|  |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |       direction !: string; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       changeStream = new EventEmitter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |       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'}, | 
					
						
							| 
									
										
										
										
											2019-01-10 22:24:32 +01:00
										 |  |  |         exportAs: ['myDir'] | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let dirB: MyDirB; | 
					
						
							|  |  |  |     class MyDirB { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |       // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |       roleB !: string; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |       static ngDirectiveDef = ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |         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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'div', ['role', 'button', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 0, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       expect(fixture.html).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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'div', ['role', 'button', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementProperty(0, 'role', ɵɵbind(ctx.role)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 1, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.role = 'listbox'; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).toEqual(`<div mydir="" role="button"></div>`); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       expect(myDir !.role).toEqual('listbox'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.role = 'button'; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							| 
									
										
										
										
											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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'div', ['role', 'button', 'myDir', '', 'myDirB', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 0, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       expect(fixture.html).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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'div', ['role', 'button', 'dir', 'rtl', 'myDir', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 0, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       expect(fixture.html).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> */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelementStart(0, 'div', ['role', 'button', 'myDir', '']); | 
					
						
							|  |  |  |           { ɵɵlistener('change', () => ctx.onChange()); } | 
					
						
							|  |  |  |           ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 0, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       let counter = 0; | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.onChange = () => counter++; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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> | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'div', ['role', 'button', 'dir', 'rtl', 'myDir', '']); | 
					
						
							|  |  |  |           ɵɵelement(1, 'div', ['role', 'listbox', 'myDirB', '']); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 0, deps); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           .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]
 | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵelement(0, 'div', ['role', 'listbox', 'myDir', '']); | 
					
						
							|  |  |  |           ɵɵcontainer(1); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵcontainerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							|  |  |  |             if (ctx.condition) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               let rf1 = ɵɵembeddedViewStart(0, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelement(0, 'div', ['role', 'button', 'myDirB', '']); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               let rf2 = ɵɵembeddedViewStart(1, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf2 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelement(0, 'div', ['role', 'menu']); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 0, deps); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       fixture.component.condition = true; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  |           .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-08-16 18:53:21 -07:00
										 |  |  |       fixture.component.condition = false; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(fixture.html).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 { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |         static ngComponentDef = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |           type: Comp, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |           selectors: [['comp']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |           consts: 3, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           vars: 1, | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |           /** <div role="button" dir #dir="myDir"></div> {{ dir.role }} */ | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           template: function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               ɵɵelement(0, 'div', ['role', 'button', 'myDir', ''], ['dir', 'myDir']); | 
					
						
							|  |  |  |               ɵɵtext(2); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               const tmp = ɵɵreference(1) as any; | 
					
						
							|  |  |  |               ɵɵtextBinding(2, ɵɵbind(tmp.role)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											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> | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const App = createComponent('app', function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵcontainer(0); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵcontainerRefreshStart(0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           { | 
					
						
							|  |  |  |             for (let i = 0; i < 2; i++) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               let rf1 = ɵɵembeddedViewStart(0, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |                 ɵɵelement(0, 'comp'); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 1, 0, [Comp]); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |       const fixture = new ComponentFixture(App); | 
					
						
							|  |  |  |       expect(fixture.html) | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |