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,98 +108,103 @@ 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]}));
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(tc.domElement).toHaveText("Location;");
expect(DOM.nextSibling(tc.domElement))
.toHaveText('DynamicallyLoaded;');
tb.createView(MyComp).then((view) => {
var location = view.rawView.locals.get("loc");
loader.loadNextToLocation(DynamicallyLoaded, location.elementRef)
.then(ref => {
expect(view.rootNodes).toHaveText("Location;DynamicallyLoaded;");
async.done();
});
});
}));
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)
.then(ref => {
loader.loadNextToLocation(DynamicallyLoaded2, location.elementRef)
.then(ref2 => {
expect(view.rootNodes)
.toHaveText("Location;DynamicallyLoaded;DynamicallyLoaded2;")
createAsync(MyComp)
.then((tc) => {
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef)
.then(ref => {
loader.loadNextToLocation(DynamicallyLoaded2, tc.elementRef)
.then(ref2 => {
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();
ref2.dispose();
expect(view.rootNodes)
.toHaveText("Location;DynamicallyLoaded;")
firstSibling = DOM.nextSibling(tc.domElement);
secondSibling = DOM.nextSibling(firstSibling);
expect(secondSibling).toBeNull();
async.done();
});
});
});
}));
async.done();
});
});
});
}));
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)
.then(ref => {
ref.instance.id = "new value";
loader.loadNextToLocation(DynamicallyLoadedWithHostProps, tc.elementRef)
.then(ref => {
ref.instance.id = "new value";
view.detectChanges();
tc.detectChanges();
var newlyInsertedElement = DOM.childNodesAsList(view.rootNodes[0])[1];
expect(newlyInsertedElement.id)
.toEqual("new value")
var newlyInsertedElement = DOM.nextSibling(tc.domElement);
expect(newlyInsertedElement.id)
.toEqual("new value")
async.done();
});
});
}));
async.done();
});
});
}));
});
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');