| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {Inject, Injectable} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-05-19 14:31:21 -07:00
										 |  |  | import {DOCUMENT} from '../src/dom/dom_tokens'; | 
					
						
							|  |  |  | import {getDOM} from '../src/dom/dom_adapter'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {TestComponentRenderer} from '@angular/compiler/testing'; | 
					
						
							| 
									
										
										
										
											2016-05-19 14:31:21 -07:00
										 |  |  | import {el} from './browser_util'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * A DOM based implementation of the TestComponentRenderer. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | export class DOMTestComponentRenderer extends TestComponentRenderer { | 
					
						
							|  |  |  |   constructor(@Inject(DOCUMENT) private _doc) { super(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   insertRootElement(rootElId: string) { | 
					
						
							|  |  |  |     let rootEl = el(`<div id="${rootElId}"></div>`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // TODO(juliemr): can/should this be optional?
 | 
					
						
							|  |  |  |     let oldRoots = getDOM().querySelectorAll(this._doc, '[id^=root]'); | 
					
						
							|  |  |  |     for (let i = 0; i < oldRoots.length; i++) { | 
					
						
							|  |  |  |       getDOM().remove(oldRoots[i]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     getDOM().appendChild(this._doc.body, rootEl); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |