Skip to content

Commit d02935e

Browse files
author
vakrilov
committed
Tests added
1 parent 5f9c59a commit d02935e

File tree

6 files changed

+79
-38
lines changed

6 files changed

+79
-38
lines changed

Diff for: ng-sample/app/app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ const customPageFactoryProvider = {
112112
}
113113
};
114114

115-
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest));
115+
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest));
116116
// platformNativeScriptDynamic(undefined, [customPageFactoryProvider]).bootstrapModule(makeExampleModule(RendererTest));
117117
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(TabViewTest));
118118
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(Benchmark));
119119
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTest));
120-
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTemplateSelectorTest));
120+
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTemplateSelectorTest));
121121
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTestAsync));
122122
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ImageTest));
123123
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));

Diff for: tests/app/snippets/navigation/page-outlet.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class PageNavigationApp {
2424

2525
this.done = new Promise<void>((resolve, reject) => {
2626
this.router.events.subscribe((e) => {
27-
console.log("------>>>>>> PageRouter event: " + e.toString());
2827
if (e instanceof NavigationStart) {
2928
this.startEvent = e;
3029
}

Diff for: tests/app/snippets/navigation/router-outlet.ts

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class NavigationApp {
3434

3535
this.done = new Promise<void>((resolve, reject) => {
3636
this.router.events.subscribe((e) => {
37-
console.log("------>>>>>> Router event: " + e.toString());
3837
if (e instanceof NavigationStart) {
3938
this.startEvent = e;
4039
}

Diff for: tests/app/tests/list-view-tests.ts

+74-30
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,89 @@
1-
import {assert} from "./test-config";
2-
import {
3-
ElementRef,
4-
Component
5-
} from '@angular/core';
6-
import {TestApp} from "./test-app";
7-
import {device, platformNames} from "platform";
8-
const IS_IOS = (device.os === platformNames.ios);
1+
import { assert } from "./test-config";
2+
import { Component, Input, AfterViewInit } from '@angular/core';
3+
import { TestApp } from "./test-app";
4+
5+
// import trace = require("trace");
6+
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
7+
// trace.enable();
98

109
class DataItem {
1110
constructor(public id: number, public name: string) { }
1211
}
1312

13+
const ITEMS = [
14+
new DataItem(0, "data item 0"),
15+
new DataItem(1, "data item 1"),
16+
new DataItem(2, "data item 2"),
17+
];
18+
19+
20+
let testTemplates: { first: number, second: number };
21+
1422
@Component({
1523
selector: 'list-view-setupItemView',
1624
template: `
17-
<StackLayout>
18-
<ListView height="200" [items]="myItems" (setupItemView)="onSetupItemView($event)">
19-
<template let-item="item" let-i="index" let-odd="odd" let-even="even">
20-
<StackLayout [class.odd]="odd" [class.even]="even">
21-
<Label [text]='"index: " + i'></Label>
22-
<Label [text]='"[" + item.id +"] " + item.name'></Label>
23-
</StackLayout>
25+
<GridLayout>
26+
<ListView [items]="myItems" (setupItemView)="onSetupItemView($event)">
27+
<template let-item="item">
28+
<Label [text]='"[" + item.id +"] " + item.name'></Label>
2429
</template>
2530
</ListView>
26-
</StackLayout>
31+
</GridLayout>
2732
`
2833
})
2934
export class TestListViewComponent {
30-
public myItems: Array<DataItem>;
31-
public counter: number;
35+
public myItems: Array<DataItem> = ITEMS;
36+
public counter: number = 0;
37+
onSetupItemView(args) { this.counter++; }
38+
}
3239

33-
constructor(public elementRef: ElementRef) {
34-
this.counter = 0;
35-
this.myItems = [];
36-
for (var i = 0; i < 2; i++) {
37-
this.myItems.push(new DataItem(i, "data item " + i));
40+
@Component({
41+
selector: 'item-component',
42+
template: `<Label text="template"></Label>`
43+
})
44+
export class ItemTemplateComponent {
45+
@Input() set templateName(value: any) {
46+
if (value === "first") {
47+
testTemplates.first = testTemplates.first + 1;
48+
} else if (value === "second") {
49+
testTemplates.second = testTemplates.second + 1;
50+
} else {
51+
throw new Error("Unexpected templateName: " + value);
3852
}
3953
}
54+
}
4055

41-
onSetupItemView(args) {
42-
this.counter++;
56+
@Component({
57+
selector: 'list-with-template-selector',
58+
template: `
59+
<GridLayout>
60+
<ListView [items]="myItems" [itemTemplateSelector]="templateSelector">
61+
<template nsTemplateKey="first">
62+
<item-component templateName="first"></item-component>
63+
</template>
64+
65+
<template nsTemplateKey="second" let-item="item">
66+
<item-component templateName="second"></item-component>
67+
</template>
68+
</ListView>
69+
</GridLayout>
70+
`
71+
})
72+
export class TestListViewSelectorComponent {
73+
public myItems: Array<DataItem> = ITEMS;
74+
public templateSelector = (item: DataItem, index: number, items: any) => {
75+
return (item.id % 2 === 0) ? "first" : "second";
4376
}
77+
constructor() { testTemplates = { first: 0, second: 0 }; }
4478
}
4579

4680
describe('ListView-tests', () => {
4781
let testApp: TestApp = null;
4882

4983
before(() => {
50-
return TestApp.create([], [TestListViewComponent]).then((app) => {
84+
return TestApp.create([], [TestListViewComponent, TestListViewSelectorComponent, ItemTemplateComponent]).then((app) => {
5185
testApp = app;
52-
})
86+
});
5387
});
5488

5589
after(() => {
@@ -64,11 +98,21 @@ describe('ListView-tests', () => {
6498
return testApp.loadComponent(TestListViewComponent).then((componentRef) => {
6599
const component = componentRef.instance;
66100
setTimeout(() => {
67-
console.log("component: " + component);
68-
assert.equal(component.counter, 2);
101+
assert.equal(component.counter, 3);
102+
done();
103+
}, 1000);
104+
})
105+
.catch(done);
106+
});
107+
108+
109+
it('itemTemplateSelector selects templates', (done) => {
110+
return testApp.loadComponent(TestListViewSelectorComponent).then((componentRef) => {
111+
setTimeout(() => {
112+
assert.deepEqual(testTemplates, { first: 2, second: 1 });
69113
done();
70114
}, 1000);
71115
})
72-
.catch(done);
116+
.catch(done);
73117
});
74118
});

Diff for: tests/app/tests/test-app.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Type, Component, ComponentRef,
55
ComponentFactoryResolver, ApplicationRef, Renderer,
66
ViewContainerRef, NgZone, NgModule,
7-
NgModuleRef,
87
} from "@angular/core";
98

109
import {GridLayout} from "ui/layouts/grid-layout";
@@ -42,7 +41,7 @@ export class TestApp {
4241

4342
public disposeComponents() {
4443
while (this._pendingDispose.length > 0) {
45-
const componentRef = this._pendingDispose.pop()
44+
const componentRef = this._pendingDispose.pop();
4645
componentRef.destroy();
4746
}
4847
}
@@ -132,7 +131,7 @@ export function destroyTestApp(app: any) {
132131
throw new Error("Unable to cleanup app: " + app);
133132
}
134133

135-
var entry = runningApps.get(app);
134+
const entry = runningApps.get(app);
136135
entry.container.removeChild(entry.appRoot);
137136
//TODO: App disposal not doing anything useful anymore. Get rid of it?
138137
//entry.appRef.dispose();

Diff for: tests/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"homepage": "http://nativescript.org",
2828
"dependencies": {
29-
"nativescript-unit-test-runner": "^0.3.3",
29+
"nativescript-unit-test-runner": "^0.3.4",
3030
"tns-core-modules": "2.4.0",
3131
"nativescript-angular": "file:../nativescript-angular",
3232
"@angular/core": "~2.2.1",

0 commit comments

Comments
 (0)