Skip to content

Enable TestBed in nativescript #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ tags
npm-debug.log
nativescript-angular*.tgz

tests/app/**/*.js
tests/test-output.txt
tests/platforms
tests/lib
tests/node_modules
tests/tns/app/**/*.js
tests/tns/test-output.txt
tests/tns/platforms
tests/tns/lib
tests/tns/node_modules

ng-sample/app/**/*.js
ng-sample/app/global.d.ts
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ install:
- cd nativescript-angular
- npm install
- npm run tslint
- cd ../tests
- cd ../tests/tns
- npm install
- tns platform add android
before_script:
- echo no | android create avd --force -n test -t android-19 -b armeabi-v7a
- emulator -memory 1024 -avd test -no-audio -no-window &
script:
-
-
- tns build android
- android-wait-for-emulator
- npm run run-appium-android
- npm run test
before_deploy:
- cd ../nativescript-angular
- npm install -g nativescript --ignore-scripts
Expand Down
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.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,122 +1,122 @@
// make sure you import mocha-config before @angular/core
import { assert } from "./test-config";
import { Component, ElementRef } from "@angular/core";
import { dumpView, createDevice } from "./test-utils";
import { TestApp } from "./test-app";
import { DEVICE } from "nativescript-angular/platform-providers";
import { platformNames } from "platform";
@Component({
template: `
<StackLayout>
<ios><Label text="IOS"></Label></ios>
</StackLayout>`
})
export class IosSpecificComponent {
constructor(public elementRef: ElementRef) { }
}
@Component({
template: `
<StackLayout>
<android><Label text="ANDROID"></Label></android>
</StackLayout>`
})
export class AndroidSpecificComponent {
constructor(public elementRef: ElementRef) { }
}
@Component({
template: `
<StackLayout>
<Label android:text="ANDROID" ios:text="IOS"></Label>
</StackLayout>`
})
export class PlatformSpecificAttributeComponent {
constructor(public elementRef: ElementRef) { }
}
describe("Platform filter directives", () => {
describe("on IOS device", () => {
let testApp: TestApp = null;
before(() => {
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.ios) }], [
PlatformSpecificAttributeComponent,
AndroidSpecificComponent,
IosSpecificComponent
]).then((app) => {
testApp = app;
});
});
after(() => {
testApp.dispose();
});
it("does render ios specific content", () => {
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=IOS])") >= 0);
});
});
it("does not render android specific content", () => {
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
});
});
it("applies iOS specific attribute", () => {
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.equal(
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
dumpView(componentRoot, true));
});
});
});
describe("on Android device", () => {
let testApp: TestApp = null;
before(() => {
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.android) }], [
AndroidSpecificComponent,
IosSpecificComponent,
PlatformSpecificAttributeComponent
]).then((app) => {
testApp = app;
});
});
after(() => {
testApp.dispose();
});
it("does render android specific content", () => {
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=ANDROID])") >= 0);
});
});
it("does not render ios specific content", () => {
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
});
});
it("applies Android specific attribute", () => {
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.equal(
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
dumpView(componentRoot, true));
});
});
});
});
// make sure you import mocha-config before @angular/core
import { assert } from "./test-config";
import { Component, ElementRef } from "@angular/core";
import { dumpView, createDevice } from "./test-utils";
import { TestApp } from "./test-app";
import { DEVICE } from "nativescript-angular/platform-providers";
import { platformNames } from "platform";

@Component({
template: `
<StackLayout>
<ios><Label text="IOS"></Label></ios>
</StackLayout>`
})
export class IosSpecificComponent {
constructor(public elementRef: ElementRef) { }
}

@Component({
template: `
<StackLayout>
<android><Label text="ANDROID"></Label></android>
</StackLayout>`
})
export class AndroidSpecificComponent {
constructor(public elementRef: ElementRef) { }
}

@Component({
template: `
<StackLayout>
<Label android:text="ANDROID" ios:text="IOS"></Label>
</StackLayout>`
})
export class PlatformSpecificAttributeComponent {
constructor(public elementRef: ElementRef) { }
}

describe("Platform filter directives", () => {
describe("on IOS device", () => {
let testApp: TestApp = null;

before(() => {
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.ios) }], [
PlatformSpecificAttributeComponent,
AndroidSpecificComponent,
IosSpecificComponent
]).then((app) => {
testApp = app;
});
});

after(() => {
testApp.dispose();
});

it("does render ios specific content", () => {
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=IOS])") >= 0);
});
});

it("does not render android specific content", () => {
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
});
});


it("applies iOS specific attribute", () => {
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.equal(
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
dumpView(componentRoot, true));
});
});
});

describe("on Android device", () => {
let testApp: TestApp = null;

before(() => {
return TestApp.create([{ provide: DEVICE, useValue: createDevice(platformNames.android) }], [
AndroidSpecificComponent,
IosSpecificComponent,
PlatformSpecificAttributeComponent
]).then((app) => {
testApp = app;
});
});

after(() => {
testApp.dispose();
});

it("does render android specific content", () => {
return testApp.loadComponent(AndroidSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=ANDROID])") >= 0);
});
});

it("does not render ios specific content", () => {
return testApp.loadComponent(IosSpecificComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.isTrue(dumpView(componentRoot, true).indexOf("Label") < 0);
});
});

it("applies Android specific attribute", () => {
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.equal(
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
dumpView(componentRoot, true));
});
});
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 45 additions & 45 deletions tests/app/tests/test-utils.ts → tests/tns/app/tests/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import { View } from "ui/core/view";
import { TextBase } from "ui/text-base";
import { Device } from "platform";
function getChildren(view: View): Array<View> {
let children: Array<View> = [];
(<any>view).eachChildView((child) => {
children.push(child);
return true;
});
return children;
}
export function dumpView(view: View, verbose: boolean = false): string {
let nodeName = (<any>view).nodeName || view;
let output = ["(", nodeName];
if (verbose) {
if (view instanceof TextBase) {
output.push("[text=", view.text, "]");
}
}
let children = getChildren(view).map((c) => dumpView(c, verbose)).join(", ");
if (children) {
output.push(" ", children);
}
output.push(")");
return output.join("");
}
export function createDevice(os: string): Device {
return {
os: os,
osVersion: "0",
deviceType: "Phone",
language: "en",
uuid: "0000",
sdkVersion: "0",
region: "US",
manufacturer: "tester",
model: "test device"
};
}
import { View } from "ui/core/view";
import { TextBase } from "ui/text-base";
import { Device } from "platform";

function getChildren(view: View): Array<View> {
let children: Array<View> = [];
(<any>view).eachChildView((child) => {
children.push(child);
return true;
});
return children;
}

export function dumpView(view: View, verbose: boolean = false): string {
let nodeName = (<any>view).nodeName || view;
let output = ["(", nodeName];
if (verbose) {
if (view instanceof TextBase) {
output.push("[text=", view.text, "]");
}
}

let children = getChildren(view).map((c) => dumpView(c, verbose)).join(", ");
if (children) {
output.push(" ", children);
}

output.push(")");
return output.join("");
}

export function createDevice(os: string): Device {
return {
os: os,
osVersion: "0",
deviceType: "Phone",
language: "en",
uuid: "0000",
sdkVersion: "0",
region: "US",
manufacturer: "tester",
model: "test device"
};
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/package.json → tests/tns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
"wd": "0.4.0"
},
"scripts": {
"test": "npm run test-android",
"test-android": "tns test android --emulator --justlaunch",
"test-ios": "tns test ios --emulator --justlaunch",
"updateTests": "grunt updateTests",
"appium-android": "tns build android && npm run run-appium-android",
"run-appium-android": "nativescript-dev-appium android",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading