chore(testbed): migrate dynamic component loader spec to testcomponentbuilder

Part of #2354
This commit is contained in:
Julie Ralph 2015-06-23 10:41:13 -07:00
parent ba9fecd068
commit 5c9e53a25e
1 changed files with 72 additions and 66 deletions

View File

@ -13,10 +13,11 @@ import {
it,
xit,
viewRootNodes,
TestComponentBuilder
TestComponentBuilder,
RootTestComponent,
inspectElement
} from 'angular2/test_lib';
import {TestBed, ViewProxy} from 'angular2/src/test_lib/test_bed';
import {Injector} from 'angular2/di';
import {Component, View, onDestroy} from 'angular2/annotations';
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
@ -107,46 +108,51 @@ export function main() {
});
describe("loading next to a location", () => {
it('should work',
inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (loader, tb: TestBed,
async) => {
tb.overrideView(
MyComp,
new viewAnn.View(
{template: '<div><location #loc></location></div>', directives: [Location]}));
tb.createView(MyComp).then((view) => {
var location = view.rawView.locals.get("loc");
loader.loadNextToLocation(DynamicallyLoaded, location.elementRef)
it('should work', inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new viewAnn.View({
template: '<div><location #loc></location></div>',
directives: [Location]
}))
.createAsync(MyComp)
.then((tc) => {
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef)
.then(ref => {
expect(view.rootNodes).toHaveText("Location;DynamicallyLoaded;");
expect(tc.domElement).toHaveText("Location;");
expect(DOM.nextSibling(tc.domElement))
.toHaveText('DynamicallyLoaded;');
async.done();
});
});
}));
it('should return a disposable component ref',
inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (loader, tb: TestBed,
async) => {
tb.overrideView(
MyComp,
new viewAnn.View(
{template: '<div><location #loc></location></div>', directives: [Location]}));
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new viewAnn.View({
template: '<div><location #loc></location></div>',
directives: [Location]
}))
.
tb.createView(MyComp).then((view) => {
var location = view.rawView.locals.get("loc");
loader.loadNextToLocation(DynamicallyLoaded, location.elementRef)
createAsync(MyComp)
.then((tc) => {
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef)
.then(ref => {
loader.loadNextToLocation(DynamicallyLoaded2, location.elementRef)
loader.loadNextToLocation(DynamicallyLoaded2, tc.elementRef)
.then(ref2 => {
expect(view.rootNodes)
.toHaveText("Location;DynamicallyLoaded;DynamicallyLoaded2;")
var firstSibling = DOM.nextSibling(tc.domElement);
var secondSibling = DOM.nextSibling(firstSibling);
expect(tc.domElement).toHaveText("Location;");
expect(firstSibling).toHaveText("DynamicallyLoaded;");
expect(secondSibling).toHaveText("DynamicallyLoaded2;");
ref2.dispose();
expect(view.rootNodes)
.toHaveText("Location;DynamicallyLoaded;")
firstSibling = DOM.nextSibling(tc.domElement);
secondSibling = DOM.nextSibling(firstSibling);
expect(secondSibling).toBeNull();
async.done();
});
@ -155,23 +161,23 @@ export function main() {
}));
it('should update host properties',
inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (loader, tb: TestBed,
async) => {
tb.overrideView(
MyComp,
new viewAnn.View(
{template: '<div><location #loc></location></div>', directives: [Location]}));
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new viewAnn.View({
template: '<div><location #loc></location></div>',
directives: [Location]
}))
tb.createView(MyComp).then((view) => {
var location = view.rawView.locals.get("loc");
.createAsync(MyComp)
.then((tc) => {
loader.loadNextToLocation(DynamicallyLoadedWithHostProps, location.elementRef)
loader.loadNextToLocation(DynamicallyLoadedWithHostProps, tc.elementRef)
.then(ref => {
ref.instance.id = "new value";
view.detectChanges();
tc.detectChanges();
var newlyInsertedElement = DOM.childNodesAsList(view.rootNodes[0])[1];
var newlyInsertedElement = DOM.nextSibling(tc.domElement);
expect(newlyInsertedElement.id)
.toEqual("new value")
@ -183,22 +189,22 @@ export function main() {
describe('loadAsRoot', () => {
it('should allow to create, update and destroy components',
inject([TestBed, AsyncTestCompleter, DynamicComponentLoader, DOCUMENT_TOKEN, Injector],
(tb: TestBed, async, dcl, doc, injector) => {
inject([AsyncTestCompleter, DynamicComponentLoader, DOCUMENT_TOKEN, Injector],
(async, loader, doc, injector) => {
var rootEl = el('<child-cmp></child-cmp>');
DOM.appendChild(doc.body, rootEl);
dcl.loadAsRoot(ChildComp, null, injector)
loader.loadAsRoot(ChildComp, null, injector)
.then((componentRef) => {
var view = new ViewProxy(componentRef);
var el = new RootTestComponent(componentRef);
expect(rootEl.parentNode).toBe(doc.body);
view.detectChanges();
el.detectChanges();
expect(rootEl).toHaveText('hello');
componentRef.instance.ctxProp = 'new';
view.detectChanges();
el.detectChanges();
expect(rootEl).toHaveText('new');