2016-06-08 19:38:52 -04:00
|
|
|
import {TestComponentRenderer} from '@angular/compiler/testing';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {Inject, Injectable} from '@angular/core';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2016-05-19 17:31:21 -04:00
|
|
|
import {getDOM} from '../src/dom/dom_adapter';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {DOCUMENT} from '../src/dom/dom_tokens';
|
|
|
|
|
2016-05-19 17:31:21 -04:00
|
|
|
import {el} from './browser_util';
|
2016-04-28 20:50:03 -04:00
|
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|