Remove TCB (#10900)

* refactor(webworker): change tests not to use TestComponentBuilder

* refactor(core): change tests not to use TestComponentBuilder
This commit is contained in:
Victor Savkin 2016-08-17 15:05:22 -07:00 committed by Kara
parent 3009be8d6e
commit 4be863c223
2 changed files with 135 additions and 184 deletions

View File

@ -7,76 +7,66 @@
*/
import {Component, Directive, ElementRef, Input, QueryList, ViewChild, ViewChildren} from '@angular/core';
import {ViewMetadata} from '@angular/core/src/metadata/view';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {TestBed} from '@angular/core/testing';
export function main() {
describe('ViewChild', () => {
it('should support type selector',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
ViewChildTypeSelectorComponent, new ViewMetadata({
template: `<simple [marker]="'1'"></simple><simple [marker]="'2'"></simple>`,
directives: [Simple]
}))
.createAsync(ViewChildTypeSelectorComponent)
.then((view) => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ViewChildTypeSelectorComponent, ViewChildStringSelectorComponent, Simple]
});
});
it('should support type selector', () => {
TestBed.overrideComponent(
ViewChildTypeSelectorComponent,
{set: {template: `<simple [marker]="'1'"></simple><simple [marker]="'2'"></simple>`}});
const view = TestBed.createComponent(ViewChildTypeSelectorComponent);
view.detectChanges();
expect(view.componentInstance.child).toBeDefined();
expect(view.componentInstance.child.marker).toBe('1');
async.done();
});
}));
it('should support string selector',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
ViewChildStringSelectorComponent,
new ViewMetadata({template: `<simple #child></simple>`, directives: [Simple]}))
.createAsync(ViewChildStringSelectorComponent)
.then((view) => {
it('should support string selector', () => {
TestBed.overrideComponent(
ViewChildStringSelectorComponent, {set: {template: `<simple #child></simple>`}});
const view = TestBed.createComponent(ViewChildStringSelectorComponent);
view.detectChanges();
expect(view.componentInstance.child).toBeDefined();
async.done();
});
}));
});
describe('ViewChildren', () => {
it('should support type selector',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
beforeEach(() => {
TestBed.configureTestingModule({
declarations:
[ViewChildrenTypeSelectorComponent, ViewChildrenStringSelectorComponent, Simple]
});
});
it('should support type selector', () => {
TestBed.overrideComponent(
ViewChildrenTypeSelectorComponent,
new ViewMetadata(
{template: `<simple></simple><simple></simple>`, directives: [Simple]}))
.createAsync(ViewChildrenTypeSelectorComponent)
.then((view) => {
{set: {template: `<simple></simple><simple></simple>`}});
const view = TestBed.createComponent(ViewChildrenTypeSelectorComponent);
view.detectChanges();
expect(view.componentInstance.children).toBeDefined();
expect(view.componentInstance.children.length).toBe(2);
async.done();
});
}));
it('should support string selector',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(ViewChildrenStringSelectorComponent, new ViewMetadata({
template: `<simple #child1></simple><simple #child2></simple>`,
directives: [Simple]
}))
.createAsync(ViewChildrenStringSelectorComponent)
.then((view) => {
it('should support string selector', () => {
TestBed.overrideComponent(
ViewChildrenStringSelectorComponent,
{set: {template: `<simple #child1></simple><simple #child2></simple>`}});
const view = TestBed.createComponent(ViewChildrenStringSelectorComponent);
view.detectChanges();
expect(view.componentInstance.children).toBeDefined();
expect(view.componentInstance.children.length).toBe(2);
async.done();
});
}));
});
}
@ -86,22 +76,22 @@ class Simple {
@Input() marker: string;
}
@Component({selector: 'view-child-type-selector'})
@Component({selector: 'view-child-type-selector', template: ''})
class ViewChildTypeSelectorComponent {
@ViewChild(Simple) child: Simple;
}
@Component({selector: 'view-child-string-selector'})
@Component({selector: 'view-child-string-selector', template: ''})
class ViewChildStringSelectorComponent {
@ViewChild('child') child: ElementRef;
}
@Component({selector: 'view-children-type-selector'})
@Component({selector: 'view-children-type-selector', template: ''})
class ViewChildrenTypeSelectorComponent {
@ViewChildren(Simple) children: QueryList<Simple>;
}
@Component({selector: 'view-child-string-selector'})
@Component({selector: 'view-child-string-selector', template: ''})
class ViewChildrenStringSelectorComponent {
// Allow comma separated selector (with spaces).
@ViewChildren('child1 , child2') children: QueryList<ElementRef>;

View File

@ -12,7 +12,6 @@ import {DebugDomRootRenderer} from '@angular/core/src/debug/debug_renderer';
import {ViewMetadata} from '@angular/core/src/metadata/view';
import {RootRenderer} from '@angular/core/src/render/api';
import {TestBed} from '@angular/core/testing';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal';
import {platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DomRootRenderer, DomRootRenderer_} from '@angular/platform-browser/src/dom/dom_renderer';
@ -81,6 +80,7 @@ export function main() {
workerRenderStore = new RenderStore();
TestBed.configureTestingModule({
declarations: [MyComp2],
providers: [
Serializer, {provide: RenderStore, useValue: workerRenderStore}, {
provide: RootRenderer,
@ -104,33 +104,24 @@ export function main() {
return (<any>componentRef.hostView).internalView.renderer;
}
it('should update text nodes',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({template: '<div>{{ctxProp}}</div>'}))
.createAsync(MyComp2)
.then((fixture) => {
it('should update text nodes', () => {
TestBed.overrideComponent(MyComp2, {set: {template: '<div>{{ctxProp}}</div>'}});
const fixture = TestBed.createComponent(MyComp2);
var renderEl = getRenderElement(fixture.debugElement.nativeElement);
expect(renderEl).toHaveText('');
fixture.debugElement.componentInstance.ctxProp = 'Hello World!';
fixture.detectChanges();
expect(renderEl).toHaveText('Hello World!');
async.done();
});
}));
it('should update any element property/attributes/class/style(s) independent of the compilation on the root element and other elements',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp2,
new ViewMetadata({template: '<input [title]="y" style="position:absolute">'}))
.createAsync(MyComp2)
.then((fixture) => {
() => {
TestBed.overrideComponent(
MyComp2, {set: {template: '<input [title]="y" style="position:absolute">'}});
const fixture = TestBed.createComponent(MyComp2);
var checkSetters =
(componentRef: any /** TODO #9100 */, workerEl: any /** TODO #9100 */) => {
var renderer = getRenderer(componentRef);
@ -155,40 +146,25 @@ export function main() {
// root element
checkSetters(fixture.componentRef, fixture.debugElement.nativeElement);
// nested elements
checkSetters(
fixture.componentRef, fixture.debugElement.children[0].nativeElement);
async.done();
checkSetters(fixture.componentRef, fixture.debugElement.children[0].nativeElement);
});
}));
it('should update any template comment property/attributes',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
var tpl = '<template [ngIf]="ctxBoolProp"></template>';
tcb.overrideView(MyComp2, new ViewMetadata({template: tpl, directives: [NgIf]}))
it('should update any template comment property/attributes', () => {
TestBed.overrideComponent(
MyComp2, {set: {template: '<template [ngIf]="ctxBoolProp"></template>'}});
const fixture = TestBed.createComponent(MyComp2);
.createAsync(MyComp2)
.then((fixture) => {
(<MyComp2>fixture.debugElement.componentInstance).ctxBoolProp = true;
fixture.detectChanges();
var el = getRenderElement(fixture.debugElement.nativeElement);
expect(getDOM().getInnerHTML(el)).toContain('"ng-reflect-ng-if": "true"');
async.done();
});
}));
it('should add and remove fragments',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({
template: '<template [ngIf]="ctxBoolProp">hello</template>',
directives: [NgIf]
}))
.createAsync(MyComp2)
.then((fixture) => {
it('should add and remove fragments', () => {
TestBed.overrideComponent(
MyComp2, {set: {template: '<template [ngIf]="ctxBoolProp">hello</template>'}});
const fixture = TestBed.createComponent(MyComp2);
var rootEl = getRenderElement(fixture.debugElement.nativeElement);
expect(rootEl).toHaveText('');
@ -200,46 +176,31 @@ export function main() {
fixture.debugElement.componentInstance.ctxBoolProp = false;
fixture.detectChanges();
expect(rootEl).toHaveText('');
async.done();
});
}));
if (getDOM().supportsDOMEvents()) {
it('should call actions on the element',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({template: '<input [title]="y">'}))
.createAsync(MyComp2)
.then((fixture) => {
it('should call actions on the element', () => {
TestBed.overrideComponent(MyComp2, {set: {template: '<input [title]="y">'}});
const fixture = TestBed.createComponent(MyComp2);
var el = fixture.debugElement.children[0];
getRenderer(fixture.componentRef)
.invokeElementMethod(el.nativeElement, 'setAttribute', ['a', 'b']);
getRenderer(fixture.componentRef).invokeElementMethod(el.nativeElement, 'setAttribute', [
'a', 'b'
]);
expect(getDOM().getAttribute(getRenderElement(el.nativeElement), 'a')).toEqual('b');
expect(getDOM().getAttribute(getRenderElement(el.nativeElement), 'a'))
.toEqual('b');
async.done();
});
}));
it('should listen to events',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp2, new ViewMetadata({template: '<input (change)="ctxNumProp = 1">'}))
.createAsync(MyComp2)
.then((fixture) => {
it('should listen to events', () => {
TestBed.overrideComponent(MyComp2, {set: {template: '<input (change)="ctxNumProp = 1">'}});
const fixture = TestBed.createComponent(MyComp2);
var el = fixture.debugElement.children[0];
dispatchEvent(getRenderElement(el.nativeElement), 'change');
expect(fixture.componentInstance.ctxNumProp).toBe(1);
fixture.destroy();
async.done();
});
}));
}
});
}