@ -28,6 +28,8 @@ export class TestComponentRenderer {
|
||||
insertRootElement(rootElementId: string) {}
|
||||
}
|
||||
|
||||
import {AnimationEntryMetadata} from '@angular/core';
|
||||
|
||||
export var ComponentFixtureAutoDetect = new OpaqueToken("ComponentFixtureAutoDetect");
|
||||
export var ComponentFixtureNoNgZone = new OpaqueToken("ComponentFixtureNoNgZone");
|
||||
|
||||
@ -219,6 +221,8 @@ export class TestComponentBuilder {
|
||||
/** @internal */
|
||||
_templateOverrides = new Map<Type, string>();
|
||||
/** @internal */
|
||||
_animationOverrides = new Map<Type, AnimationEntryMetadata[]>();
|
||||
/** @internal */
|
||||
_viewBindingsOverrides = new Map<Type, any[]>();
|
||||
/** @internal */
|
||||
_viewOverrides = new Map<Type, ViewMetadata>();
|
||||
@ -247,6 +251,12 @@ export class TestComponentBuilder {
|
||||
return clone;
|
||||
}
|
||||
|
||||
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): TestComponentBuilder {
|
||||
var clone = this._clone();
|
||||
clone._animationOverrides.set(componentType, animations);
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides a component's {@link ViewMetadata}.
|
||||
*/
|
||||
@ -339,6 +349,8 @@ export class TestComponentBuilder {
|
||||
this._viewOverrides.forEach((view, type) => mockViewResolver.setView(type, view));
|
||||
this._templateOverrides.forEach((template, type) =>
|
||||
mockViewResolver.setInlineTemplate(type, template));
|
||||
this._animationOverrides.forEach((animationsEntry, type) =>
|
||||
mockViewResolver.setAnimations(type, animationsEntry));
|
||||
this._directiveOverrides.forEach((overrides, component) => {
|
||||
overrides.forEach(
|
||||
(to, from) => { mockViewResolver.overrideViewDirective(component, from, to); });
|
||||
|
@ -2,7 +2,7 @@ import {Injectable, ViewMetadata, Type, BaseException} from '@angular/core';
|
||||
import {ViewResolver} from '../index';
|
||||
import {Map} from '../src/facade/collection';
|
||||
import {isPresent, stringify, isBlank, isArray} from '../src/facade/lang';
|
||||
import {resolveForwardRef} from '@angular/core';
|
||||
import {AnimationEntryMetadata, resolveForwardRef} from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class MockViewResolver extends ViewResolver {
|
||||
@ -11,6 +11,8 @@ export class MockViewResolver extends ViewResolver {
|
||||
/** @internal */
|
||||
_inlineTemplates = new Map<Type, string>();
|
||||
/** @internal */
|
||||
_animations = new Map<Type, AnimationEntryMetadata[]>();
|
||||
/** @internal */
|
||||
_viewCache = new Map<Type, ViewMetadata>();
|
||||
/** @internal */
|
||||
_directiveOverrides = new Map<Type, Map<Type, Type>>();
|
||||
@ -24,7 +26,6 @@ export class MockViewResolver extends ViewResolver {
|
||||
this._checkOverrideable(component);
|
||||
this._views.set(component, view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the inline template for a component - other configuration remains unchanged.
|
||||
*/
|
||||
@ -33,6 +34,11 @@ export class MockViewResolver extends ViewResolver {
|
||||
this._inlineTemplates.set(component, template);
|
||||
}
|
||||
|
||||
setAnimations(component: Type, animations: AnimationEntryMetadata[]): void {
|
||||
this._checkOverrideable(component);
|
||||
this._animations.set(component, animations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides a directive from the component {@link ViewMetadata}.
|
||||
*/
|
||||
@ -67,10 +73,26 @@ export class MockViewResolver extends ViewResolver {
|
||||
}
|
||||
|
||||
var directives = [];
|
||||
if (isPresent(view.directives)) {
|
||||
flattenArray(view.directives, directives);
|
||||
}
|
||||
var animations = view.animations;
|
||||
var templateUrl = view.templateUrl;
|
||||
var overrides = this._directiveOverrides.get(component);
|
||||
|
||||
var inlineAnimations = this._animations.get(component);
|
||||
if (isPresent(inlineAnimations)) {
|
||||
animations = inlineAnimations;
|
||||
}
|
||||
|
||||
var inlineTemplate = this._inlineTemplates.get(component);
|
||||
if (isPresent(inlineTemplate)) {
|
||||
templateUrl = null;
|
||||
} else {
|
||||
inlineTemplate = view.template;
|
||||
}
|
||||
|
||||
if (isPresent(overrides) && isPresent(view.directives)) {
|
||||
flattenArray(view.directives, directives);
|
||||
overrides.forEach((to, from) => {
|
||||
var srcIndex = directives.indexOf(from);
|
||||
if (srcIndex == -1) {
|
||||
@ -79,15 +101,18 @@ export class MockViewResolver extends ViewResolver {
|
||||
}
|
||||
directives[srcIndex] = to;
|
||||
});
|
||||
view = new ViewMetadata(
|
||||
{template: view.template, templateUrl: view.templateUrl, directives: directives});
|
||||
}
|
||||
|
||||
var inlineTemplate = this._inlineTemplates.get(component);
|
||||
if (isPresent(inlineTemplate)) {
|
||||
view = new ViewMetadata(
|
||||
{template: inlineTemplate, templateUrl: null, directives: view.directives});
|
||||
}
|
||||
view = new ViewMetadata({
|
||||
template: inlineTemplate,
|
||||
templateUrl: templateUrl,
|
||||
directives: directives.length > 0 ? directives : null,
|
||||
animations: animations,
|
||||
styles: view.styles,
|
||||
styleUrls: view.styleUrls,
|
||||
pipes: view.pipes,
|
||||
encapsulation: view.encapsulation
|
||||
});
|
||||
|
||||
this._viewCache.set(component, view);
|
||||
return view;
|
||||
@ -112,6 +137,7 @@ export class MockViewResolver extends ViewResolver {
|
||||
}
|
||||
|
||||
function flattenArray(tree: any[], out: Array<Type | any[]>): void {
|
||||
if (!isPresent(tree)) return;
|
||||
for (var i = 0; i < tree.length; i++) {
|
||||
var item = resolveForwardRef(tree[i]);
|
||||
if (isArray(item)) {
|
||||
|
Reference in New Issue
Block a user