Skip to content

Commit 680a296

Browse files
author
vakrilov
committed
Detached loader tests
1 parent 814a8b4 commit 680a296

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//make sure you import mocha-config before @angular/core
2+
import {assert} from "./test-config";
3+
import {Component, ElementRef, Renderer, AfterViewInit, OnInit, ViewChild, ChangeDetectionStrategy} from "@angular/core";
4+
import {ProxyViewContainer} from "ui/proxy-view-container";
5+
import {Red} from "color/known-colors";
6+
import {dumpView} from "./test-utils";
7+
import {TestApp} from "./test-app";
8+
import {LayoutBase} from "ui/layouts/layout-base";
9+
import {StackLayout} from "ui/layouts/stack-layout";
10+
import {DetachedLoader} from "nativescript-angular/common/detached-loader";
11+
12+
@Component({
13+
template: `<StackLayout><Label text="COMPONENT"></Label></StackLayout>`
14+
})
15+
class TestComponent { }
16+
17+
18+
class LoaderComponentBase {
19+
@ViewChild(DetachedLoader) public loader: DetachedLoader;
20+
21+
public ready: Promise<LoaderComponent>;
22+
private resolve;
23+
constructor() {
24+
this.ready = new Promise((reslove, reject) => {
25+
this.resolve = reslove;
26+
})
27+
}
28+
ngAfterViewInit() {
29+
this.resolve(this);
30+
}
31+
}
32+
33+
@Component({
34+
selector: 'loader-component-on-push',
35+
directives: [DetachedLoader],
36+
template: `
37+
<StackLayout>
38+
<DetachedContainer #loader></DetachedContainer>
39+
</StackLayout>
40+
`
41+
})
42+
export class LoaderComponent extends LoaderComponentBase { }
43+
44+
@Component({
45+
selector: 'loader-component-on-push',
46+
directives: [DetachedLoader],
47+
changeDetection: ChangeDetectionStrategy.OnPush,
48+
template: `
49+
<StackLayout>
50+
<DetachedContainer #loader></DetachedContainer>
51+
</StackLayout>
52+
`
53+
})
54+
export class LoaderComponentOnPush extends LoaderComponentBase { }
55+
56+
describe ('DetachedLoader', () => {
57+
let testApp: TestApp = null;
58+
59+
before(() => {
60+
return TestApp.create().then((app) => {
61+
testApp = app;
62+
})
63+
});
64+
65+
after(() => {
66+
testApp.dispose();
67+
});
68+
69+
afterEach(() => {
70+
testApp.disposeComponents();
71+
});
72+
73+
it("creates component", (done) => {
74+
testApp.loadComponent(LoaderComponent)
75+
.then((componentRef) => {
76+
// wait for the ngAfterViewInit
77+
return (<LoaderComponent>componentRef.instance).ready;
78+
})
79+
.then((comp) => {
80+
// load test component with loader
81+
return comp.loader.loadComponent(TestComponent);
82+
})
83+
.then((compRef) => {
84+
done();
85+
})
86+
.catch(done);
87+
});
88+
89+
90+
it("creates component when ChangeDetectionStrategy is OnPush", (done) => {
91+
testApp.loadComponent(LoaderComponentOnPush)
92+
.then((componentRef) => {
93+
// wait for the ngAfterViewInit
94+
return (<LoaderComponentOnPush>componentRef.instance).ready;
95+
})
96+
.then((comp) => {
97+
// load test component with loader
98+
return comp.loader.loadComponent(TestComponent);
99+
})
100+
.then((compRef) => {
101+
done();
102+
})
103+
.catch(done);
104+
});
105+
})

0 commit comments

Comments
 (0)