| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 19:16:25 -07:00
										 |  |  | import {ɵgetDOM as getDOM} from '@angular/common'; | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  | import {getDebugNode} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  | import {asTextData, elementDef, NodeFlags, Services, textDef} from '@angular/core/src/view/index'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  | import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRootNodes} from './helper'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 16:28:41 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |   describe(`View Text`, () => { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     describe('create', () => { | 
					
						
							|  |  |  |       it('should create text nodes without parents', () => { | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  |         const rootNodes = createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])])).rootNodes; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |         expect(rootNodes.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2019-08-23 13:28:33 -07:00
										 |  |  |         expect(rootNodes[0].textContent).toBe('a'); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should create views with multiple root text nodes', () => { | 
					
						
							| 
									
										
										
										
											2017-01-31 08:51:42 -08:00
										 |  |  |         const rootNodes = createAndGetRootNodes(compViewDef([ | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  |                             textDef(0, null, ['a']), | 
					
						
							|  |  |  |                             textDef(1, null, ['b']), | 
					
						
							| 
									
										
										
										
											2017-01-31 08:51:42 -08:00
										 |  |  |                           ])).rootNodes; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |         expect(rootNodes.length).toBe(2); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should create text nodes with parents', () => { | 
					
						
							|  |  |  |         const rootNodes = createAndGetRootNodes(compViewDef([ | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  |                             elementDef(0, NodeFlags.None, null, null, 1, 'div'), | 
					
						
							|  |  |  |                             textDef(1, null, ['a']), | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |                           ])).rootNodes; | 
					
						
							|  |  |  |         expect(rootNodes.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2019-08-24 08:01:24 -07:00
										 |  |  |         const textNode = rootNodes[0].firstChild; | 
					
						
							| 
									
										
										
										
											2019-08-23 13:28:33 -07:00
										 |  |  |         expect(textNode.textContent).toBe('a'); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |       it('should add debug information to the renderer', () => { | 
					
						
							| 
									
										
										
										
											2019-10-17 02:46:50 +02:00
										 |  |  |         const someContext = {}; | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |         const {view, rootNodes} = | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  |             createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])]), someContext); | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |         expect(getDebugNode(rootNodes[0])!.nativeNode).toBe(asTextData(view, 0).renderText); | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('change text', () => { | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |       ARG_TYPE_VALUES.forEach((inlineDynamic) => { | 
					
						
							| 
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 |  |  |         it(`should update via strategy ${inlineDynamic}`, () => { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |           const {view, rootNodes} = createAndGetRootNodes(compViewDef( | 
					
						
							|  |  |  |               [ | 
					
						
							| 
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 |  |  |                 textDef(0, null, ['0', '1', '2']), | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |               ], | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |               null!, (check, view) => { | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |                 checkNodeInlineOrDynamic(check, view, 0, inlineDynamic, ['a', 'b']); | 
					
						
							| 
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 |  |  |               })); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |           Services.checkAndUpdateView(view); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-23 13:28:33 -07:00
										 |  |  |           expect(rootNodes[0].textContent).toBe('0a1b2'); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |