| 
									
										
										
										
											2019-09-08 17:26:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-09-08 17:26:23 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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 {Component} from '@angular/core'; | 
					
						
							|  |  |  | import {getLContext} from '@angular/core/src/render3/context_discovery'; | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  | import {LViewDebug} from '@angular/core/src/render3/instructions/lview_debug'; | 
					
						
							|  |  |  | import {TNodeType} from '@angular/core/src/render3/interfaces/node'; | 
					
						
							|  |  |  | import {HEADER_OFFSET} from '@angular/core/src/render3/interfaces/view'; | 
					
						
							| 
									
										
										
										
											2019-09-08 17:26:23 +02:00
										 |  |  | import {TestBed} from '@angular/core/testing'; | 
					
						
							|  |  |  | import {expect} from '@angular/platform-browser/testing/src/matchers'; | 
					
						
							|  |  |  | import {onlyInIvy} from '@angular/private/testing'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  | import {matchDomElement, matchDomText, matchTI18n, matchTNode} from '../render3/matchers'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | onlyInIvy('Ivy specific').describe('Debug Representation', () => { | 
					
						
							|  |  |  |   it('should generate a human readable version', () => { | 
					
						
							| 
									
										
										
										
											2019-09-08 17:26:23 +02:00
										 |  |  |     @Component({selector: 'my-comp', template: '<div id="123">Hello World</div>'}) | 
					
						
							|  |  |  |     class MyComponent { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TestBed.configureTestingModule({declarations: [MyComponent]}); | 
					
						
							|  |  |  |     const fixture = TestBed.createComponent(MyComponent); | 
					
						
							|  |  |  |     fixture.detectChanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 19:32:58 +02:00
										 |  |  |     const hostView = getLContext(fixture.componentInstance)!.lView.debug!; | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |     expect(hostView.hostHTML).toEqual(null); | 
					
						
							| 
									
										
										
										
											2019-09-08 17:26:23 +02:00
										 |  |  |     const myCompView = hostView.childViews[0] as LViewDebug; | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |     expect(myCompView.hostHTML).toContain('<div id="123">Hello World</div>'); | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     expect(myCompView.nodes![0].html).toEqual('<div id="123">'); | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |     expect(myCompView.nodes![0].children![0].html).toEqual('Hello World'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('LViewDebug', () => { | 
					
						
							|  |  |  |     describe('range', () => { | 
					
						
							|  |  |  |       it('should show ranges', () => { | 
					
						
							|  |  |  |         @Component({selector: 'my-comp', template: '<div i18n>Hello {{name}}</div>'}) | 
					
						
							|  |  |  |         class MyComponent { | 
					
						
							|  |  |  |           name = 'World'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         TestBed.configureTestingModule({declarations: [MyComponent]}); | 
					
						
							|  |  |  |         const fixture = TestBed.createComponent(MyComponent); | 
					
						
							|  |  |  |         fixture.detectChanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 19:32:58 +02:00
										 |  |  |         const hostView = getLContext(fixture.componentInstance)!.lView.debug!; | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |         const myComponentView = hostView.childViews[0] as LViewDebug; | 
					
						
							|  |  |  |         expect(myComponentView.decls).toEqual({ | 
					
						
							|  |  |  |           start: HEADER_OFFSET, | 
					
						
							|  |  |  |           end: HEADER_OFFSET + 2, | 
					
						
							|  |  |  |           length: 2, | 
					
						
							|  |  |  |           content: [ | 
					
						
							| 
									
										
										
										
											2020-10-12 16:57:07 -07:00
										 |  |  |             {index: HEADER_OFFSET + 0, t: matchTNode({value: 'div'}), l: matchDomElement('div')}, | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |             {index: HEADER_OFFSET + 1, t: matchTI18n(), l: null}, | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         expect(myComponentView.vars).toEqual({ | 
					
						
							|  |  |  |           start: HEADER_OFFSET + 2, | 
					
						
							|  |  |  |           end: HEADER_OFFSET + 3, | 
					
						
							|  |  |  |           length: 1, | 
					
						
							|  |  |  |           content: [{index: HEADER_OFFSET + 2, t: null, l: 'World'}] | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-09-25 15:01:56 -07:00
										 |  |  |         expect(myComponentView.expando).toEqual({ | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |           start: HEADER_OFFSET + 3, | 
					
						
							|  |  |  |           end: HEADER_OFFSET + 4, | 
					
						
							|  |  |  |           length: 1, | 
					
						
							|  |  |  |           content: [{ | 
					
						
							|  |  |  |             index: HEADER_OFFSET + 3, | 
					
						
							| 
									
										
										
										
											2020-10-12 21:38:06 -07:00
										 |  |  |             t: matchTNode({type: TNodeType.Text, value: '{{?}}'}), | 
					
						
							| 
									
										
										
										
											2020-08-05 19:16:20 -07:00
										 |  |  |             l: matchDomText('Hello World') | 
					
						
							|  |  |  |           }] | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-09-08 17:26:23 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | }); |