test(ViewMetadata): use ViewMetadata consistently in tests

Closes #3746
This commit is contained in:
Pawel Kozlowski 2015-08-20 13:51:48 +02:00
parent 215c4aa8fb
commit c4044102d6
6 changed files with 50 additions and 47 deletions

View File

@ -48,7 +48,7 @@ main() {
tb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template:
'<type-literal-component></type-literal-component>',
directives: [TypeLiteralComponent]))
@ -69,7 +69,7 @@ main() {
tb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template: '<throwing-component></throwing-component>',
directives: [ThrowingComponent]))
.createAsync(Dummy)
@ -86,7 +86,7 @@ main() {
tb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template: '<throwing-component2></throwing-component2>',
directives: [ThrowingComponent2]))
.createAsync(Dummy)
@ -105,7 +105,7 @@ main() {
tb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template: '<property-access></property-access>',
directives: [PropertyAccess]))
.createAsync(Dummy)
@ -123,7 +123,7 @@ main() {
tb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template: '<no-property-access></no-property-access>',
directives: [NoPropertyAccess]))
.createAsync(Dummy)
@ -142,7 +142,7 @@ main() {
tb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template: '''<on-change [prop]="'hello'"></on-change>''',
directives: [OnChangeComponent]))
.createAsync(Dummy)
@ -164,7 +164,7 @@ main() {
tcb
.overrideView(
Dummy,
new View(
new ViewMetadata(
template:
'''<component-with-observable-list [list]="value"></component-with-observable-list>''',
directives: [ComponentWithObservableList]))

View File

@ -24,9 +24,6 @@ import {
import {DOM} from 'angular2/src/dom/dom_adapter';
import {
Component,
Directive,
View,
forwardRef,
ViewContainerRef,
ElementRef,
@ -34,6 +31,7 @@ import {
bind,
ViewEncapsulation
} from 'angular2/angular2';
import {Component, Directive, View, ViewMetadata} from 'angular2/metadata';
import {MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE} from 'angular2/src/render/render';
@ -41,7 +39,7 @@ export function main() {
describe('projection', () => {
it('should support simple components',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<simple>' +
'<div>A</div>' +
'</simple>',
@ -56,7 +54,7 @@ export function main() {
it('should support simple components with text interpolation as direct children',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '{{\'START(\'}}<simple>' +
'{{text}}' +
'</simple>{{\')END\'}}',
@ -76,10 +74,11 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
Simple,
new View(
new ViewMetadata(
{template: 'SIMPLE(<div><ng-content></ng-content></div>)', directives: []}))
.overrideView(MainComp,
new View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
.overrideView(
MainComp,
new ViewMetadata({template: '<simple>{{text}}</simple>', directives: [Simple]}))
.createAsync(MainComp)
.then((main) => {
@ -94,13 +93,14 @@ export function main() {
it('should support projecting text interpolation to a non bound element with other bound elements after it',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
Simple, new View({
Simple, new ViewMetadata({
template:
'SIMPLE(<div><ng-content></ng-content></div><div [tab-index]="0">EL</div>)',
directives: []
}))
.overrideView(MainComp,
new View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
.overrideView(
MainComp,
new ViewMetadata({template: '<simple>{{text}}</simple>', directives: [Simple]}))
.createAsync(MainComp)
.then((main) => {
@ -113,7 +113,8 @@ export function main() {
it('should not show the light dom even if there is no content tag',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({template: '<empty>A</empty>', directives: [Empty]}))
tcb.overrideView(MainComp,
new ViewMetadata({template: '<empty>A</empty>', directives: [Empty]}))
.createAsync(MainComp)
.then((main) => {
@ -124,7 +125,7 @@ export function main() {
it('should support multiple content tags',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<multiple-content-tags>' +
'<div>B</div>' +
'<div>C</div>' +
@ -142,7 +143,7 @@ export function main() {
it('should redistribute only direct children',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<multiple-content-tags>' +
'<div>B<div class="left">A</div></div>' +
'<div>C</div>' +
@ -159,7 +160,7 @@ export function main() {
it("should redistribute direct child viewcontainers when the light dom changes",
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<multiple-content-tags>' +
'<template manual class="left"><div>A1</div></template>' +
'<div>B</div>' +
@ -185,7 +186,7 @@ export function main() {
it("should support nested components",
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<outer-with-indirect-nested>' +
'<div>A</div>' +
'<div>B</div>' +
@ -202,7 +203,7 @@ export function main() {
it("should support nesting with content being direct child of a nested component",
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<outer>' +
'<template manual class="left"><div>A</div></template>' +
'<div>B</div>' +
@ -226,7 +227,7 @@ export function main() {
it('should redistribute when the shadow dom changes',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<conditional-content>' +
'<div class="left">A</div>' +
'<div>B</div>' +
@ -260,7 +261,8 @@ export function main() {
tcb.overrideView(
MainComp,
new View({template: '<simple string-prop="text"></simple>', directives: [Simple]}))
new ViewMetadata(
{template: '<simple string-prop="text"></simple>', directives: [Simple]}))
.overrideTemplate(Simple, '<ng-content></ng-content><p>P,</p>{{stringProp}}')
.createAsync(MainComp)
.then((main) => {
@ -280,7 +282,8 @@ export function main() {
tcb.overrideView(
MainComp,
new View({template: '<simple string-prop="text"></simple>', directives: [Simple]}))
new ViewMetadata(
{template: '<simple string-prop="text"></simple>', directives: [Simple]}))
.overrideTemplate(Simple, '<style></style><p>P,</p>{{stringProp}}')
.createAsync(MainComp)
.then((main) => {
@ -293,7 +296,7 @@ export function main() {
it('should support moving non projected light dom around',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<empty>' +
' <template manual><div>A</div></template>' +
'</empty>' +
@ -318,7 +321,7 @@ export function main() {
it('should support moving projected light dom around',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<simple><template manual><div>A</div></template></simple>' +
'START(<div project></div>)END',
directives: [Simple, ProjectDirective, ManualViewportDirective],
@ -342,7 +345,7 @@ export function main() {
it('should support moving ng-content around',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
MainComp, new View({
MainComp, new ViewMetadata({
template: '<conditional-content>' +
'<div class="left">A</div>' +
'<div>B</div>' +
@ -378,7 +381,8 @@ export function main() {
// the presence of ng-content elements!
it('should still allow to implement a recursive trees',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({template: '<tree></tree>', directives: [Tree]}))
tcb.overrideView(MainComp,
new ViewMetadata({template: '<tree></tree>', directives: [Tree]}))
.createAsync(MainComp)
.then((main) => {
@ -397,7 +401,7 @@ export function main() {
if (DOM.supportsNativeShadowDOM()) {
it('should support native content projection',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: '<simple-native>' +
'<div>A</div>' +
'</simple-native>',
@ -417,7 +421,7 @@ export function main() {
it('should support nested conditionals that contain ng-contents',
inject(
[TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new View({
tcb.overrideView(MainComp, new ViewMetadata({
template: `<conditional-text>a</conditional-text>`,
directives: [ConditionalTextComponent]
}))

View File

@ -12,7 +12,7 @@ import {
TestComponentBuilder
} from 'angular2/test_lib';
import {Directive, Component, View, LifecycleEvent} from 'angular2/angular2';
import {Directive, Component, View, ViewMetadata, LifecycleEvent} from 'angular2/metadata';
export function main() {
describe('directive lifecycle integration spec', () => {
@ -21,7 +21,7 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
MyComp,
new View(
new ViewMetadata(
{template: '<div [field]="123" lifecycle></div>', directives: [LifecycleDir]}))
.createAsync(MyComp)
.then((tc) => {

View File

@ -12,7 +12,7 @@ import {stringify} from 'angular2/src/facade/lang';
import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock';
import {Component, View} from 'angular2/angular2';
import {Component, View, ViewMetadata} from 'angular2/metadata';
import {isBlank} from 'angular2/src/facade/lang';
@ -30,7 +30,7 @@ export function main() {
});
it('should allow overriding the @View', () => {
viewResolver.setView(SomeComponent, new View({template: 'overridden template'}));
viewResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'}));
var view = viewResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template');
expect(isBlank(view.directives)).toBe(true);
@ -40,7 +40,7 @@ export function main() {
it('should not allow overriding a view after it has been resolved', () => {
viewResolver.resolve(SomeComponent);
expect(() => {
viewResolver.setView(SomeComponent, new View({template: 'overridden template'}));
viewResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'}));
})
.toThrowError(
`The component ${stringify(SomeComponent)} has already been compiled, its configuration can not be changed`);
@ -56,7 +56,7 @@ export function main() {
});
it('should allow overriding an overriden @View', () => {
viewResolver.setView(SomeComponent, new View({template: 'overridden template'}));
viewResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'}));
viewResolver.setInlineTemplate(SomeComponent, 'overridden template x 2');
var view = viewResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template x 2');
@ -80,7 +80,7 @@ export function main() {
});
it('should allow overriding a directive from an overriden @View', () => {
viewResolver.setView(SomeComponent, new View({directives: [SomeOtherDirective]}));
viewResolver.setView(SomeComponent, new ViewMetadata({directives: [SomeOtherDirective]}));
viewResolver.overrideViewDirective(SomeComponent, SomeOtherDirective, SomeComponent);
var view = viewResolver.resolve(SomeComponent);
expect(view.directives.length).toEqual(1);

View File

@ -16,7 +16,7 @@ import {
} from 'angular2/test_lib';
import {Injector, Inject, bind} from 'angular2/di';
import {Component, View} from 'angular2/metadata';
import {Component, View, ViewMetadata} from 'angular2/metadata';
import {CONST, NumberWrapper, isPresent, Json} from 'angular2/src/facade/lang';
import {
Promise,
@ -85,7 +85,7 @@ export function main() {
}));
function compile(template: string = "<router-outlet></router-outlet>") {
return tcb.overrideView(MyComp, new View({
return tcb.overrideView(MyComp, new ViewMetadata({
template: ('<div>' + template + '</div>'),
directives: [RouterOutlet, RouterLink]
}))

View File

@ -13,7 +13,7 @@ import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
import {PipeResolver} from 'angular2/src/core/compiler/pipe_resolver';
import {Component, Directive, View} from 'angular2/angular2';
import {Component, Directive, View, ViewMetadata} from 'angular2/metadata';
import {ViewResolver} from 'angular2/src/core/compiler/view_resolver';
import {UrlResolver} from 'angular2/src/services/url_resolver';
import {AppRootUrl} from 'angular2/src/services/app_root_url';
@ -121,11 +121,10 @@ class MultipleViewResolver extends ViewResolver {
this._cache.set(component, ListWrapper.join(multiplier, ''));
}
resolve(component: Type): View {
resolve(component: Type): ViewMetadata {
var view = super.resolve(component);
var myView =
new View({template:<string>this._cache.get(component), directives: view.directives});
return myView;
return new ViewMetadata(
{template:<string>this._cache.get(component), directives: view.directives});
}
}