2016-06-23 12:47:54 -04: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
|
|
|
|
*/
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {Inject, Injectable} from '@angular/core';
|
2016-07-11 19:04:32 -04:00
|
|
|
import {TestComponentRenderer} from '@angular/core/testing';
|
2016-06-10 13:21:53 -04:00
|
|
|
import {DOCUMENT} from '@angular/platform-browser';
|
2016-08-30 21:07:40 -04:00
|
|
|
import {getDOM} from './private_import_platform-browser';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
/**
|
|
|
|
* A DOM based implementation of the TestComponentRenderer.
|
|
|
|
*/
|
|
|
|
@Injectable()
|
|
|
|
export class DOMTestComponentRenderer extends TestComponentRenderer {
|
2016-06-08 18:45:15 -04:00
|
|
|
constructor(@Inject(DOCUMENT) private _doc: any /** TODO #9100 */) { super(); }
|
2016-04-28 20:50:03 -04:00
|
|
|
|
|
|
|
insertRootElement(rootElId: string) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const rootEl = <HTMLElement>getDOM().firstChild(
|
2016-06-23 19:42:25 -04:00
|
|
|
getDOM().content(getDOM().createTemplate(`<div id="${rootElId}"></div>`)));
|
2016-04-28 20:50:03 -04:00
|
|
|
|
|
|
|
// TODO(juliemr): can/should this be optional?
|
2016-11-12 08:08:58 -05:00
|
|
|
const oldRoots = getDOM().querySelectorAll(this._doc, '[id^=root]');
|
2016-04-28 20:50:03 -04:00
|
|
|
for (let i = 0; i < oldRoots.length; i++) {
|
|
|
|
getDOM().remove(oldRoots[i]);
|
|
|
|
}
|
|
|
|
getDOM().appendChild(this._doc.body, rootEl);
|
|
|
|
}
|
|
|
|
}
|