| 
									
										
										
										
											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-05-17 18:49:21 -07:00
										 |  |  | import {ɵɵdefineComponent, ɵɵdefineDirective} from '../../src/render3/index'; | 
					
						
							|  |  |  | import {ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵelementEnd, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵlistener, ɵɵtext} 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 22:08:31 -04:00
										 |  |  | import {renderToHtml} from './render_util'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('outputs', () => { | 
					
						
							|  |  |  |   let buttonToggle: ButtonToggle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class ButtonToggle { | 
					
						
							|  |  |  |     change = new EventEmitter(); | 
					
						
							|  |  |  |     resetStream = new EventEmitter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => buttonToggle = new ButtonToggle(); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |     static ɵcmp = ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |       type: ButtonToggle, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |       selectors: [['button-toggle']], | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       template: function(rf: RenderFlags, ctx: any) {}, | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       decls: 0, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       vars: 0, | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |       outputs: {change: 'change', resetStream: 'reset'} | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |   let otherDir: OtherDir; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class OtherDir { | 
					
						
							|  |  |  |     changeStream = new EventEmitter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |     static ɵfac = () => otherDir = new OtherDir; | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |     static ɵdir = ɵɵdefineDirective( | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |         {type: OtherDir, selectors: [['', 'otherDir', '']], outputs: {changeStream: 'change'}}); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:32:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 22:08:31 -04:00
										 |  |  |   const deps = [ButtonToggle, OtherDir]; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |   it('should work with outputs at same index in if block', () => { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * <button (click)="onClick()">Click me</button>             // outputs: null
 | 
					
						
							|  |  |  |      * % if (condition) { | 
					
						
							|  |  |  |      *   <button-toggle (change)="onChange()"></button-toggle>   // outputs: {change: [0, 'change']} | 
					
						
							|  |  |  |      * % } else { | 
					
						
							|  |  |  |      *   <div otherDir (change)="onChange()"></div>             // outputs: {change: [0,
 | 
					
						
							|  |  |  |      * 'changeStream']} | 
					
						
							|  |  |  |      * % } | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |     function Template(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵelementStart(0, 'button'); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵlistener('click', function() { return ctx.onClick(); }); | 
					
						
							|  |  |  |           ɵɵtext(1, 'Click me'); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵelementEnd(); | 
					
						
							|  |  |  |         ɵɵcontainer(2); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |       if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainerRefreshStart(2); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |         { | 
					
						
							|  |  |  |           if (ctx.condition) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             let rf1 = ɵɵembeddedViewStart(0, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelementStart(0, 'button-toggle'); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 ɵɵlistener('change', function() { return ctx.onChange(); }); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-02-16 11:36:50 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             if (ɵɵembeddedViewStart(1, 1, 0)) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |               ɵɵelementStart(0, 'div', 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                 ɵɵlistener('change', function() { return ctx.onChange(); }); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-02-16 11:36:50 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             ɵɵembeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |         ɵɵcontainerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let counter = 0; | 
					
						
							|  |  |  |     const ctx = {condition: true, onChange: () => counter++, onClick: () => {}}; | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |     const attrs = [['otherDir', '']]; | 
					
						
							|  |  |  |     renderToHtml(Template, ctx, 3, 0, deps, null, null, false, attrs); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     buttonToggle !.change.next(); | 
					
						
							|  |  |  |     expect(counter).toEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ctx.condition = false; | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |     renderToHtml(Template, ctx, 3, 0, deps, null, null, false, attrs); | 
					
						
							| 
									
										
										
										
											2017-12-08 11:48:54 -08:00
										 |  |  |     expect(counter).toEqual(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     otherDir !.changeStream.next(); | 
					
						
							|  |  |  |     expect(counter).toEqual(2); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | }); |