Skip to content

Commit a3d1faa

Browse files
committed
refactor(testing): Splitting tests into pure tns and testbed (prepare)
1 parent 428136b commit a3d1faa

File tree

101 files changed

+173
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+173
-544
lines changed

.gitignore

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ tags
2222
npm-debug.log
2323
nativescript-angular*.tgz
2424

25-
tests/app/**/*.js
26-
tests/test-output.txt
27-
tests/platforms
28-
tests/lib
29-
tests/node_modules
25+
tests/tns/app/**/*.js
26+
tests/tns/test-output.txt
27+
tests/tns/platforms
28+
tests/tns/lib
29+
tests/tns/node_modules
3030

3131
ng-sample/app/**/*.js
3232
ng-sample/app/global.d.ts

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ install:
2929
- cd nativescript-angular
3030
- npm install
3131
- npm run tslint
32-
- cd ../tests
32+
- cd ../tests/tns
3333
- npm install
3434
- tns platform add android
3535
before_script:
3636
- echo no | android create avd --force -n test -t android-19 -b armeabi-v7a
3737
- emulator -memory 1024 -avd test -no-audio -no-window &
3838
script:
39-
-
40-
-
4139
- tns build android
4240
- android-wait-for-emulator
4341
- npm run run-appium-android
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,122 @@
1-
// make sure you import mocha-config before @angular/core
2-
import { assert } from "./test-config";
3-
import { Component, ElementRef } from "@angular/core";
4-
import { dumpView, createDevice } from "./test-utils";
5-
import { TestApp } from "./test-app";
6-
import { DEVICE } from "nativescript-angular/platform-providers";
7-
import { platformNames } from "platform";
8-
9-
@Component({
10-
template: `
11-
<StackLayout>
12-
<ios><Label text="IOS"></Label></ios>
13-
</StackLayout>`
14-
})
15-
export class IosSpecificComponent {
16-
constructor(public elementRef: ElementRef) { }
17-
}
18-
19-
@Component({
20-
template: `
21-
<StackLayout>
22-
<android><Label text="ANDROID"></Label></android>
23-
</StackLayout>`
24-
})
25-
export class AndroidSpecificComponent {
26-
constructor(public elementRef: ElementRef) { }
27-
}
28-
29-
@Component({
30-
template: `
31-
<StackLayout>
32-
<Label android:text="ANDROID" ios:text="IOS"></Label>
33-
</StackLayout>`
34-
})
35-
export class PlatformSpecificAttributeComponent {
36-
constructor(public elementRef: ElementRef) { }
37-
}
38-
39-
describe("Platform filter directives", () => {
40-
describe("on IOS device", () => {
41-
let testApp: TestApp = null;
42-
43-
before(() => {
44-
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.ios) }], [
45-
PlatformSpecificAttributeComponent,
46-
AndroidSpecificComponent,
47-
IosSpecificComponent
48-
]).then((app) => {
49-
testApp = app;
50-
});
51-
});
52-
53-
after(() => {
54-
testApp.dispose();
55-
});
56-
57-
it("does render ios specific content", () => {
58-
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
59-
const componentRoot = componentRef.instance.elementRef.nativeElement;
60-
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=IOS])") >= 0);
61-
});
62-
});
63-
64-
it("does not render android specific content", () => {
65-
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
66-
const componentRoot = componentRef.instance.elementRef.nativeElement;
67-
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
68-
});
69-
});
70-
71-
72-
it("applies iOS specific attribute", () => {
73-
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
74-
const componentRoot = componentRef.instance.elementRef.nativeElement;
75-
assert.equal(
76-
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
77-
dumpView(componentRoot, true));
78-
});
79-
});
80-
});
81-
82-
describe("on Android device", () => {
83-
let testApp: TestApp = null;
84-
85-
before(() => {
86-
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.android) }], [
87-
AndroidSpecificComponent,
88-
IosSpecificComponent,
89-
PlatformSpecificAttributeComponent
90-
]).then((app) => {
91-
testApp = app;
92-
});
93-
});
94-
95-
after(() => {
96-
testApp.dispose();
97-
});
98-
99-
it("does render android specific content", () => {
100-
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
101-
const componentRoot = componentRef.instance.elementRef.nativeElement;
102-
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=ANDROID])") >= 0);
103-
});
104-
});
105-
106-
it("does not render ios specific content", () => {
107-
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
108-
const componentRoot = componentRef.instance.elementRef.nativeElement;
109-
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
110-
});
111-
});
112-
113-
it("applies Android specific attribute", () => {
114-
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
115-
const componentRoot = componentRef.instance.elementRef.nativeElement;
116-
assert.equal(
117-
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
118-
dumpView(componentRoot, true));
119-
});
120-
});
121-
});
122-
});
1+
// make sure you import mocha-config before @angular/core
2+
import { assert } from "./test-config";
3+
import { Component, ElementRef } from "@angular/core";
4+
import { dumpView, createDevice } from "./test-utils";
5+
import { TestApp } from "./test-app";
6+
import { DEVICE } from "nativescript-angular/platform-providers";
7+
import { platformNames } from "platform";
8+
9+
@Component({
10+
template: `
11+
<StackLayout>
12+
<ios><Label text="IOS"></Label></ios>
13+
</StackLayout>`
14+
})
15+
export class IosSpecificComponent {
16+
constructor(public elementRef: ElementRef) { }
17+
}
18+
19+
@Component({
20+
template: `
21+
<StackLayout>
22+
<android><Label text="ANDROID"></Label></android>
23+
</StackLayout>`
24+
})
25+
export class AndroidSpecificComponent {
26+
constructor(public elementRef: ElementRef) { }
27+
}
28+
29+
@Component({
30+
template: `
31+
<StackLayout>
32+
<Label android:text="ANDROID" ios:text="IOS"></Label>
33+
</StackLayout>`
34+
})
35+
export class PlatformSpecificAttributeComponent {
36+
constructor(public elementRef: ElementRef) { }
37+
}
38+
39+
describe("Platform filter directives", () => {
40+
describe("on IOS device", () => {
41+
let testApp: TestApp = null;
42+
43+
before(() => {
44+
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.ios) }], [
45+
PlatformSpecificAttributeComponent,
46+
AndroidSpecificComponent,
47+
IosSpecificComponent
48+
]).then((app) => {
49+
testApp = app;
50+
});
51+
});
52+
53+
after(() => {
54+
testApp.dispose();
55+
});
56+
57+
it("does render ios specific content", () => {
58+
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
59+
const componentRoot = componentRef.instance.elementRef.nativeElement;
60+
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=IOS])") >= 0);
61+
});
62+
});
63+
64+
it("does not render android specific content", () => {
65+
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
66+
const componentRoot = componentRef.instance.elementRef.nativeElement;
67+
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
68+
});
69+
});
70+
71+
72+
it("applies iOS specific attribute", () => {
73+
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
74+
const componentRoot = componentRef.instance.elementRef.nativeElement;
75+
assert.equal(
76+
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
77+
dumpView(componentRoot, true));
78+
});
79+
});
80+
});
81+
82+
describe("on Android device", () => {
83+
let testApp: TestApp = null;
84+
85+
before(() => {
86+
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.android) }], [
87+
AndroidSpecificComponent,
88+
IosSpecificComponent,
89+
PlatformSpecificAttributeComponent
90+
]).then((app) => {
91+
testApp = app;
92+
});
93+
});
94+
95+
after(() => {
96+
testApp.dispose();
97+
});
98+
99+
it("does render android specific content", () => {
100+
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
101+
const componentRoot = componentRef.instance.elementRef.nativeElement;
102+
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=ANDROID])") >= 0);
103+
});
104+
});
105+
106+
it("does not render ios specific content", () => {
107+
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
108+
const componentRoot = componentRef.instance.elementRef.nativeElement;
109+
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
110+
});
111+
});
112+
113+
it("applies Android specific attribute", () => {
114+
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
115+
const componentRoot = componentRef.instance.elementRef.nativeElement;
116+
assert.equal(
117+
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
118+
dumpView(componentRoot, true));
119+
});
120+
});
121+
});
122+
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
import { View } from "ui/core/view";
2-
import { TextBase } from "ui/text-base";
3-
import { Device } from "platform";
4-
5-
function getChildren(view: View): Array<View> {
6-
let children: Array<View> = [];
7-
(<any>view).eachChildView((child) => {
8-
children.push(child);
9-
return true;
10-
});
11-
return children;
12-
}
13-
14-
export function dumpView(view: View, verbose: boolean = false): string {
15-
let nodeName = (<any>view).nodeName || view;
16-
let output = ["(", nodeName];
17-
if (verbose) {
18-
if (view instanceof TextBase) {
19-
output.push("[text=", view.text, "]");
20-
}
21-
}
22-
23-
let children = getChildren(view).map((c) => dumpView(c, verbose)).join(", ");
24-
if (children) {
25-
output.push(" ", children);
26-
}
27-
28-
output.push(")");
29-
return output.join("");
30-
}
31-
32-
export function createDevice(os: string): Device {
33-
return {
34-
os: os,
35-
osVersion: "0",
36-
deviceType: "Phone",
37-
language: "en",
38-
uuid: "0000",
39-
sdkVersion: "0",
40-
region: "US",
41-
manufacturer: "tester",
42-
model: "test device"
43-
};
44-
}
45-
1+
import { View } from "ui/core/view";
2+
import { TextBase } from "ui/text-base";
3+
import { Device } from "platform";
4+
5+
function getChildren(view: View): Array<View> {
6+
let children: Array<View> = [];
7+
(<any>view).eachChildView((child) => {
8+
children.push(child);
9+
return true;
10+
});
11+
return children;
12+
}
13+
14+
export function dumpView(view: View, verbose: boolean = false): string {
15+
let nodeName = (<any>view).nodeName || view;
16+
let output = ["(", nodeName];
17+
if (verbose) {
18+
if (view instanceof TextBase) {
19+
output.push("[text=", view.text, "]");
20+
}
21+
}
22+
23+
let children = getChildren(view).map((c) => dumpView(c, verbose)).join(", ");
24+
if (children) {
25+
output.push(" ", children);
26+
}
27+
28+
output.push(")");
29+
return output.join("");
30+
}
31+
32+
export function createDevice(os: string): Device {
33+
return {
34+
os: os,
35+
osVersion: "0",
36+
deviceType: "Phone",
37+
language: "en",
38+
uuid: "0000",
39+
sdkVersion: "0",
40+
region: "US",
41+
manufacturer: "tester",
42+
model: "test device"
43+
};
44+
}
45+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)