2017-01-20 16:10:57 -05: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
|
|
|
|
*/
|
|
|
|
|
2017-03-14 19:26:17 -04:00
|
|
|
import {Injector, NgModuleRef, RootRenderer, Sanitizer} from '@angular/core';
|
2017-05-15 16:12:10 -04:00
|
|
|
import {ArgumentType, NodeCheckFn, NodeDef, RootData, Services, ViewData, ViewDefinition, initServicesIfNeeded} from '@angular/core/src/view/index';
|
2017-01-20 16:10:57 -05:00
|
|
|
import {TestBed} from '@angular/core/testing';
|
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
|
|
|
|
export function isBrowser() {
|
|
|
|
return getDOM().supportsDOMEvents();
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
export const ARG_TYPE_VALUES = [ArgumentType.Inline, ArgumentType.Dynamic];
|
2017-01-20 12:21:09 -05:00
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
export function checkNodeInlineOrDynamic(
|
|
|
|
check: NodeCheckFn, view: ViewData, nodeIndex: number, argType: ArgumentType,
|
|
|
|
values: any[]): any {
|
|
|
|
switch (argType) {
|
|
|
|
case ArgumentType.Inline:
|
|
|
|
return (<any>check)(view, nodeIndex, argType, ...values);
|
|
|
|
case ArgumentType.Dynamic:
|
|
|
|
return check(view, nodeIndex, argType, values);
|
2017-01-20 12:21:09 -05:00
|
|
|
}
|
|
|
|
}
|
2017-02-01 14:32:27 -05:00
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
export function createRootView(
|
|
|
|
def: ViewDefinition, context?: any, projectableNodes?: any[][],
|
|
|
|
rootSelectorOrNode?: any): ViewData {
|
|
|
|
initServicesIfNeeded();
|
|
|
|
return Services.createRootView(
|
2017-03-14 19:26:17 -04:00
|
|
|
TestBed.get(Injector), projectableNodes || [], rootSelectorOrNode, def,
|
|
|
|
TestBed.get(NgModuleRef), context);
|
2017-02-01 14:32:27 -05:00
|
|
|
}
|
|
|
|
|
2017-05-15 16:12:10 -04:00
|
|
|
export function createEmbeddedView(parent: ViewData, anchorDef: NodeDef, context?: any): ViewData {
|
|
|
|
return Services.createEmbeddedView(parent, anchorDef, anchorDef.element !.template !, context);
|
|
|
|
}
|
|
|
|
|
2017-02-01 14:32:27 -05:00
|
|
|
export let removeNodes: Node[];
|
|
|
|
beforeEach(() => { removeNodes = []; });
|
|
|
|
afterEach(() => { removeNodes.forEach((node) => getDOM().remove(node)); });
|