Skip to content

Commit 47d231a

Browse files
committed
Port router tests to appium.
1 parent 558c712 commit 47d231a

10 files changed

+278
-14
lines changed

tests/app/app.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import {Component} from "@angular/core";
2+
import {SinglePageMain} from "./single-page-main.component";
3+
import {MultiPageMain} from "./multi-page-main.component";
24

35
@Component({
46
selector: "my-app",
7+
directives: [SinglePageMain, MultiPageMain],
58
template: `
6-
<StackLayout orientation="vertical">
7-
<Label [text]="message" class="title" (tap)="message = 'OHAI'"></Label>
8-
</StackLayout>
9+
<multi-page-main></multi-page-main>
10+
<!--
11+
<single-page-main *ngIf="true"></single-page-main>
12+
-->
913
`,
1014
})
1115
export class AppComponent {

tests/app/base.component.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {ROUTER_DIRECTIVES, Router, OnActivate, OnDeactivate, CanReuse, OnReuse,
2+
RouteParams, ComponentInstruction, RouteConfig } from '@angular/router-deprecated';
3+
import {Component} from "@angular/core";
4+
5+
6+
export const hooksLog = [];
7+
8+
export class BaseComponent implements OnActivate, OnDeactivate {
9+
protected name: string = "";
10+
11+
routerOnActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
12+
this.log("activate", nextInstruction, prevInstruction);
13+
}
14+
15+
routerOnDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
16+
this.log("deactivate", nextInstruction, prevInstruction);
17+
}
18+
19+
private log(method: string, nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction) {
20+
hooksLog.push(this.name + "." + method + " " + nextInstruction.urlPath + " " + (prevInstruction ? prevInstruction.urlPath : null));
21+
}
22+
}

tests/app/first.component.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {ROUTER_DIRECTIVES, Router, OnActivate, OnDeactivate, CanReuse, OnReuse,
2+
RouteParams, RouteData, ComponentInstruction, RouteConfig } from '@angular/router-deprecated';
3+
import {Component} from "@angular/core";
4+
import {BaseComponent} from "./base.component";
5+
6+
@Component({
7+
selector: "first-comp",
8+
template: `
9+
<StackLayout>
10+
<Label [automationText]="'first-' + id" [text]="'First: ' + id"></Label>
11+
<Button [automationText]="'first-navigate-' + id" text="Go to second" (tap)="gotoSecond()"></Button>
12+
</StackLayout>
13+
`
14+
})
15+
export class FirstComponent extends BaseComponent {
16+
constructor(private router: Router, private routeData: RouteData) {
17+
super();
18+
}
19+
20+
ngOnInit() {
21+
this.id = this.routeData.get('id');
22+
}
23+
24+
public id: string = ""
25+
26+
gotoSecond() {
27+
this.router.navigateByUrl("/second");
28+
}
29+
}

tests/app/main.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
// this import should be first in order to load some required settings (like globals and reflect-metadata)
2-
import {nativeScriptBootstrap} from "nativescript-angular/application";
2+
import {nativeScriptBootstrap, bootstrap} from "nativescript-angular/application";
33
import {AppComponent} from "./app.component";
44
import {GestureComponent} from "./snippets/gestures.component";
55
import {LayoutsComponent} from "./snippets/layouts.component";
66
import {IconFontComponent} from "./snippets/icon-font.component";
7+
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router/ns-router";
8+
import {APP_ROOT_VIEW} from "nativescript-angular/platform-providers";
9+
import {Page} from "ui/page";
10+
import {Label} from "ui/label";
11+
import {StackLayout} from "ui/layouts/stack-layout";
12+
import * as application from "application";
13+
//nativeScriptBootstrap(AppComponent, [NS_ROUTER_PROVIDERS]);
14+
import {MultiPageMain} from "./multi-page-main.component";
15+
import {SinglePageMain} from "./single-page-main.component";
16+
import {provide} from "@angular/core";
717

8-
nativeScriptBootstrap(AppComponent);
18+
import { rendererTraceCategory, routerTraceCategory } from "nativescript-angular/trace";
19+
20+
import trace = require("trace");
21+
//trace.setCategories(rendererTraceCategory + "," + routerTraceCategory);
22+
trace.enable();
23+
24+
//nativeScriptBootstrap(MultiPageMain, [NS_ROUTER_PROVIDERS]);
925
// nativeScriptBootstrap(GestureComponent);
1026
// nativeScriptBootstrap(LayoutsComponent);
1127
// nativeScriptBootstrap(IconFontComponent);
28+
application.start({
29+
create: (): Page => {
30+
const page = new Page();
31+
const root = new StackLayout();
32+
page.content = root;
33+
34+
let onLoadedHandler = function(args) {
35+
page.off('loaded', onLoadedHandler);
36+
//profiling.stop('application-start');
37+
console.log('Page loaded');
38+
39+
//profiling.start('ng-bootstrap');
40+
console.log('BOOTSTRAPPING TEST APPS...');
41+
//bootstrap(MultiPageMain, [NS_ROUTER_PROVIDERS]);
42+
const rootViewProvider = provide(APP_ROOT_VIEW, { useValue: root });
43+
bootstrap(SinglePageMain, [rootViewProvider, NS_ROUTER_PROVIDERS]);
44+
bootstrap(MultiPageMain, [rootViewProvider, NS_ROUTER_PROVIDERS]);
45+
}
46+
47+
page.on('loaded', onLoadedHandler);
48+
49+
return page;
50+
}
51+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {ROUTER_DIRECTIVES, Router, OnActivate, OnDeactivate, CanReuse, OnReuse,
2+
RouteParams, ComponentInstruction, RouteConfig } from '@angular/router-deprecated';
3+
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router/ns-router";
4+
import {Component, ElementRef} from "@angular/core";
5+
import {Location, LocationStrategy} from '@angular/common';
6+
import {FirstComponent} from "./first.component";
7+
import {SecondComponent} from "./second.component";
8+
9+
@Component({
10+
selector: "multi-page-main",
11+
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
12+
template: `
13+
<Label text="Multi-page router"></Label>
14+
<page-router-outlet></page-router-outlet>
15+
`
16+
17+
})
18+
@RouteConfig([
19+
{ path: '/first', name: 'First', component: FirstComponent, useAsDefault: true , data: {id: "multi-page"}},
20+
{ path: '/second', name: 'Second', component: SecondComponent, data: {id: "multi-page"} }
21+
])
22+
export class MultiPageMain {
23+
constructor(
24+
public elementRef: ElementRef,
25+
public router: Router,
26+
public location: LocationStrategy) {
27+
}
28+
}

tests/app/second.component.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {ROUTER_DIRECTIVES, Router, OnActivate, OnDeactivate, CanReuse, OnReuse,
2+
RouteParams, RouteData, ComponentInstruction, RouteConfig } from '@angular/router-deprecated';
3+
import {Component} from "@angular/core";
4+
import {BaseComponent} from "./base.component";
5+
6+
@Component({
7+
selector: "second-comp",
8+
template: `
9+
<StackLayout>
10+
<Label [automationText]="'second-' + id" [text]="'Second: ' + id"></Label>
11+
<Button [automationText]="'second-navigate-' + id" text="Go to first" (tap)="gotoFirst()"></Button>
12+
</StackLayout>
13+
`
14+
})
15+
export class SecondComponent extends BaseComponent {
16+
constructor(private router: Router, private routeData: RouteData) {
17+
super();
18+
}
19+
20+
ngOnInit() {
21+
this.id = this.routeData.get('id');
22+
}
23+
24+
public id: string = ""
25+
26+
gotoFirst() {
27+
this.router.navigateByUrl("/first");
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {ROUTER_DIRECTIVES, Router, OnActivate, OnDeactivate, CanReuse, OnReuse,
2+
RouteParams, ComponentInstruction, RouteConfig } from '@angular/router-deprecated';
3+
import {Component, ElementRef} from "@angular/core";
4+
import {Location, LocationStrategy} from '@angular/common';
5+
import {FirstComponent} from "./first.component";
6+
import {SecondComponent} from "./second.component";
7+
8+
@Component({
9+
selector: "single-page-main",
10+
directives: [ROUTER_DIRECTIVES],
11+
template: `
12+
<Label text="Single-page router"></Label>
13+
<router-outlet></router-outlet>
14+
`
15+
16+
})
17+
@RouteConfig([
18+
{ path: '/first', name: 'First', component: FirstComponent, useAsDefault: true , data: {id: "single-page"}},
19+
{ path: '/second', name: 'Second', component: SecondComponent, data: {id: "single-page"} }
20+
])
21+
export class SinglePageMain {
22+
constructor(
23+
public elementRef: ElementRef,
24+
public router: Router,
25+
public location: LocationStrategy) {
26+
}
27+
}

tests/e2e-tests/multi-page-routing.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
var nsAppium = require("nativescript-dev-appium");
3+
4+
describe("multi page routing", function () {
5+
this.timeout(40000);
6+
var driver;
7+
8+
before(function () {
9+
driver = nsAppium.createDriver();
10+
});
11+
12+
after(function () {
13+
return driver
14+
.quit()
15+
.finally(function () {
16+
console.log("Driver quit successfully");
17+
});
18+
});
19+
20+
it("loads default path", function () {
21+
return driver
22+
.elementByAccessibilityId("first-multi-page")
23+
.should.eventually.exist
24+
.text().should.eventually.equal("First: multi-page")
25+
});
26+
27+
it("navigates and returns", function () {
28+
return driver
29+
.elementByAccessibilityId("first-navigate-multi-page")
30+
.should.eventually.exist
31+
.tap()
32+
.elementByAccessibilityId("second-multi-page")
33+
.should.eventually.exist
34+
.text().should.eventually.equal("Second: multi-page")
35+
.elementByAccessibilityId("second-navigate-multi-page")
36+
.should.eventually.exist
37+
.tap()
38+
.elementByAccessibilityId("first-multi-page")
39+
.should.eventually.exist
40+
.text().should.eventually.equal("First: multi-page")
41+
});
42+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
var nsAppium = require("nativescript-dev-appium");
3+
4+
describe("single page routing", function () {
5+
this.timeout(40000);
6+
var driver;
7+
8+
before(function () {
9+
driver = nsAppium.createDriver();
10+
});
11+
12+
after(function () {
13+
return driver
14+
.quit()
15+
.finally(function () {
16+
console.log("Driver quit successfully");
17+
});
18+
});
19+
20+
it("loads default path", function () {
21+
return driver
22+
.elementByAccessibilityId("first-single-page")
23+
.should.eventually.exist
24+
.text().should.eventually.equal("First: single-page")
25+
});
26+
27+
it("navigates and returns", function () {
28+
return driver
29+
.elementByAccessibilityId("first-navigate-single-page")
30+
.should.eventually.exist
31+
.tap()
32+
.elementByAccessibilityId("second-single-page")
33+
.should.eventually.exist
34+
.text().should.eventually.equal("Second: single-page")
35+
.elementByAccessibilityId("second-navigate-single-page")
36+
.should.eventually.exist
37+
.tap()
38+
.elementByAccessibilityId("first-single-page")
39+
.should.eventually.exist
40+
.text().should.eventually.equal("First: single-page")
41+
});
42+
});

tests/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"nativescript": {
3-
"id": "org.nativescript.helloworldng",
3+
"id": "org.nativescript.ngtests",
44
"tns-android": {
55
"version": "2.0.0"
66
},
77
"tns-ios": {
88
"version": "2.0.0"
99
}
1010
},
11-
"name": "nativescript-hello-world-ng",
11+
"name": "ngtests",
1212
"main": "app.js",
1313
"version": "1.0.0",
1414
"author": "Telerik <[email protected]>",
15-
"description": "Nativescript Angular Hello World template",
15+
"description": "Angular tests",
1616
"license": "BSD",
1717
"keywords": [
1818
"telerik",
@@ -24,10 +24,6 @@
2424
"appbuilder",
2525
"template"
2626
],
27-
"repository": {
28-
"type": "git",
29-
"url": "git://github.com/NativeScript/template-hello-world-ng"
30-
},
3127
"homepage": "http://nativescript.org",
3228
"dependencies": {
3329
"nativescript-unit-test-runner": "^0.3.3",
@@ -54,6 +50,7 @@
5450
"babel-types": "6.8.1",
5551
"babylon": "6.8.0",
5652
"chai": "^3.5.0",
53+
"chai-as-promised": "^5.3.0",
5754
"filewalker": "0.1.2",
5855
"grunt-cli": "^1.2.0",
5956
"karma": "^0.13.19",
@@ -63,11 +60,15 @@
6360
"karma-nativescript-launcher": "^0.4.0",
6461
"lazy": "1.0.11",
6562
"mocha": "^2.4.5",
63+
"nativescript-dev-appium": "^0.0.10",
6664
"nativescript-dev-typescript": "^0.3.1",
6765
"shelljs": "^0.5.3",
68-
"typescript": "1.8.2"
66+
"typescript": "^1.8.10",
67+
"wd": "0.4.0"
6968
},
7069
"scripts": {
71-
"updateTests": "grunt updateTests"
70+
"updateTests": "grunt updateTests",
71+
"appium-android": "tns build android && nativescript-dev-appium android",
72+
"appium-ios-simulator": "tns build ios && nativescript-dev-appium ios-simulator"
7273
}
7374
}

0 commit comments

Comments
 (0)