chore(testbed): migrate dynamic component loader spec to testcomponentbuilder
Part of #2354
This commit is contained in:
parent
ba9fecd068
commit
5c9e53a25e
|
@ -13,10 +13,11 @@ import {
|
||||||
it,
|
it,
|
||||||
xit,
|
xit,
|
||||||
viewRootNodes,
|
viewRootNodes,
|
||||||
TestComponentBuilder
|
TestComponentBuilder,
|
||||||
|
RootTestComponent,
|
||||||
|
inspectElement
|
||||||
} from 'angular2/test_lib';
|
} from 'angular2/test_lib';
|
||||||
|
|
||||||
import {TestBed, ViewProxy} from 'angular2/src/test_lib/test_bed';
|
|
||||||
import {Injector} from 'angular2/di';
|
import {Injector} from 'angular2/di';
|
||||||
import {Component, View, onDestroy} from 'angular2/annotations';
|
import {Component, View, onDestroy} from 'angular2/annotations';
|
||||||
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
|
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
|
||||||
|
@ -107,98 +108,103 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("loading next to a location", () => {
|
describe("loading next to a location", () => {
|
||||||
it('should work',
|
it('should work', inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||||
inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (loader, tb: TestBed,
|
(loader, tcb: TestComponentBuilder, async) => {
|
||||||
async) => {
|
tcb.overrideView(MyComp, new viewAnn.View({
|
||||||
tb.overrideView(
|
template: '<div><location #loc></location></div>',
|
||||||
MyComp,
|
directives: [Location]
|
||||||
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) => {
|
async.done();
|
||||||
var location = view.rawView.locals.get("loc");
|
});
|
||||||
|
});
|
||||||
loader.loadNextToLocation(DynamicallyLoaded, location.elementRef)
|
}));
|
||||||
.then(ref => {
|
|
||||||
expect(view.rootNodes).toHaveText("Location;DynamicallyLoaded;");
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return a disposable component ref',
|
it('should return a disposable component ref',
|
||||||
inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (loader, tb: TestBed,
|
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||||
async) => {
|
(loader, tcb: TestComponentBuilder, async) => {
|
||||||
tb.overrideView(
|
tcb.overrideView(MyComp, new viewAnn.View({
|
||||||
MyComp,
|
template: '<div><location #loc></location></div>',
|
||||||
new viewAnn.View(
|
directives: [Location]
|
||||||
{template: '<div><location #loc></location></div>', directives: [Location]}));
|
}))
|
||||||
|
.
|
||||||
|
|
||||||
tb.createView(MyComp).then((view) => {
|
createAsync(MyComp)
|
||||||
var location = view.rawView.locals.get("loc");
|
.then((tc) => {
|
||||||
loader.loadNextToLocation(DynamicallyLoaded, location.elementRef)
|
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef)
|
||||||
.then(ref => {
|
.then(ref => {
|
||||||
loader.loadNextToLocation(DynamicallyLoaded2, location.elementRef)
|
loader.loadNextToLocation(DynamicallyLoaded2, tc.elementRef)
|
||||||
.then(ref2 => {
|
.then(ref2 => {
|
||||||
expect(view.rootNodes)
|
var firstSibling = DOM.nextSibling(tc.domElement);
|
||||||
.toHaveText("Location;DynamicallyLoaded;DynamicallyLoaded2;")
|
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)
|
firstSibling = DOM.nextSibling(tc.domElement);
|
||||||
.toHaveText("Location;DynamicallyLoaded;")
|
secondSibling = DOM.nextSibling(firstSibling);
|
||||||
|
expect(secondSibling).toBeNull();
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should update host properties',
|
it('should update host properties',
|
||||||
inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (loader, tb: TestBed,
|
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||||
async) => {
|
(loader, tcb: TestComponentBuilder, async) => {
|
||||||
tb.overrideView(
|
tcb.overrideView(MyComp, new viewAnn.View({
|
||||||
MyComp,
|
template: '<div><location #loc></location></div>',
|
||||||
new viewAnn.View(
|
directives: [Location]
|
||||||
{template: '<div><location #loc></location></div>', directives: [Location]}));
|
}))
|
||||||
|
|
||||||
tb.createView(MyComp).then((view) => {
|
.createAsync(MyComp)
|
||||||
var location = view.rawView.locals.get("loc");
|
.then((tc) => {
|
||||||
|
|
||||||
loader.loadNextToLocation(DynamicallyLoadedWithHostProps, location.elementRef)
|
loader.loadNextToLocation(DynamicallyLoadedWithHostProps, tc.elementRef)
|
||||||
.then(ref => {
|
.then(ref => {
|
||||||
ref.instance.id = "new value";
|
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)
|
expect(newlyInsertedElement.id)
|
||||||
.toEqual("new value")
|
.toEqual("new value")
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('loadAsRoot', () => {
|
describe('loadAsRoot', () => {
|
||||||
it('should allow to create, update and destroy components',
|
it('should allow to create, update and destroy components',
|
||||||
inject([TestBed, AsyncTestCompleter, DynamicComponentLoader, DOCUMENT_TOKEN, Injector],
|
inject([AsyncTestCompleter, DynamicComponentLoader, DOCUMENT_TOKEN, Injector],
|
||||||
(tb: TestBed, async, dcl, doc, injector) => {
|
(async, loader, doc, injector) => {
|
||||||
var rootEl = el('<child-cmp></child-cmp>');
|
var rootEl = el('<child-cmp></child-cmp>');
|
||||||
DOM.appendChild(doc.body, rootEl);
|
DOM.appendChild(doc.body, rootEl);
|
||||||
dcl.loadAsRoot(ChildComp, null, injector)
|
loader.loadAsRoot(ChildComp, null, injector)
|
||||||
.then((componentRef) => {
|
.then((componentRef) => {
|
||||||
var view = new ViewProxy(componentRef);
|
var el = new RootTestComponent(componentRef);
|
||||||
expect(rootEl.parentNode).toBe(doc.body);
|
expect(rootEl.parentNode).toBe(doc.body);
|
||||||
|
|
||||||
view.detectChanges();
|
el.detectChanges();
|
||||||
|
|
||||||
expect(rootEl).toHaveText('hello');
|
expect(rootEl).toHaveText('hello');
|
||||||
|
|
||||||
componentRef.instance.ctxProp = 'new';
|
componentRef.instance.ctxProp = 'new';
|
||||||
|
|
||||||
view.detectChanges();
|
el.detectChanges();
|
||||||
|
|
||||||
expect(rootEl).toHaveText('new');
|
expect(rootEl).toHaveText('new');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue