Skip to content

Add appium E2E tests for the router #279

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

Merged
merged 7 commits into from
Jun 13, 2016
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ before_script:
script:
- tns platform add android
- tns test android --emulator --justlaunch
- npm run appium-android
11 changes: 6 additions & 5 deletions nativescript-angular/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "zone.js/dist/zone-node"

import 'reflect-metadata';
import './polyfills/array';
import {rendererLog, rendererError} from "./trace";
import {SanitizationService} from '@angular/core/src/security';
import {isPresent, Type, print} from '@angular/core/src/facade/lang';
import {ReflectiveInjector, reflector, coreLoadAndBootstrap, createPlatform,
Expand Down Expand Up @@ -107,18 +108,18 @@ export function nativeScriptBootstrap(appComponentType: any, customProviders?: P
let onLoadedHandler = function(args) {
page.off('loaded', onLoadedHandler);
//profiling.stop('application-start');
console.log('Page loaded');
rendererLog('Page loaded');

//profiling.start('ng-bootstrap');
console.log('BOOTSTRAPPING...');
rendererLog('BOOTSTRAPPING...');
bootstrap(appComponentType, customProviders).then((appRef) => {
//profiling.stop('ng-bootstrap');
console.log('ANGULAR BOOTSTRAP DONE.');
rendererLog('ANGULAR BOOTSTRAP DONE.');
resolve(appRef);
}, (err) => {
console.log('ERROR BOOTSTRAPPING ANGULAR');
rendererError('ERROR BOOTSTRAPPING ANGULAR');
let errorMessage = err.message + "\n\n" + err.stack;
console.log(errorMessage);
rendererError(errorMessage);

let view = new TextView();
view.text = errorMessage;
Expand Down
5 changes: 3 additions & 2 deletions nativescript-angular/directives/list-view-comp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {View} from 'ui/core/view';
import {NgView} from '../view-util';
import {ObservableArray} from 'data/observable-array';
import {LayoutBase} from 'ui/layouts/layout-base';
import {rendererLog, rendererError} from "../trace";
const NG_VIEW = "_ngViewRef";

export class ListItemContext {
Expand Down Expand Up @@ -98,15 +99,15 @@ export class ListViewComponent {
let viewRef: EmbeddedViewRef<ListItemContext>;

if (args.view) {
console.log("ListView.onItemLoading: " + index + " - Reusing existing view");
rendererLog("ListView.onItemLoading: " + index + " - Reusing existing view");
viewRef = args.view[NG_VIEW];
// getting angular view from original element (in cases when ProxyViewContainer is used NativeScript internally wraps it in a StackLayout)
if (!viewRef) {
viewRef = (args.view._subViews && args.view._subViews.length > 0) ? args.view._subViews[0][NG_VIEW] : undefined;
}
}
else {
console.log("ListView.onItemLoading: " + index + " - Creating view from template");
rendererLog("ListView.onItemLoading: " + index + " - Creating view from template");
viewRef = this.loader.createEmbeddedView(this.itemTemplate, new ListItemContext(), 0);
args.view = getSingleViewFromViewRef(viewRef);
args.view[NG_VIEW] = viewRef;
Expand Down
3 changes: 2 additions & 1 deletion nativescript-angular/directives/tab-view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ElementRef, Directive, Input, TemplateRef, ViewContainerRef} from "@angular/core";
import {TabView, TabViewItem} from "ui/tab-view";
import * as utils from '../common/utils';
import {rendererLog, rendererError} from "../trace";
import {isBlank} from '@angular/core/src/facade/lang';

@Directive({
Expand Down Expand Up @@ -31,7 +32,7 @@ export class TabViewDirective {
ngAfterViewInit() {
this.viewInitialized = true;
debugger;
console.log("this._selectedIndex: " + this._selectedIndex);
rendererLog("this._selectedIndex: " + this._selectedIndex);
if (!isBlank(this._selectedIndex)) {
this.tabView.selectedIndex = this._selectedIndex;
}
Expand Down
3 changes: 2 additions & 1 deletion nativescript-angular/dom_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {SanitizationService} from '@angular/core/src/security';
import {Parse5DomAdapter} from '@angular/platform-server';
import {setRootDomAdapter} from '@angular/platform-browser/src/dom/dom_adapter';
import {Type} from '@angular/core/src/facade/lang';
import {rendererLog, rendererError} from "./trace";

export enum SecurityContext {
NONE,
Expand Down Expand Up @@ -35,7 +36,7 @@ export class NativeScriptSanitizationService extends SanitizationService {

export class NativeScriptDomAdapter extends Parse5DomAdapter {
static makeCurrent() {
console.log("Setting DOM");
rendererLog("Setting DOM");
setRootDomAdapter(new NativeScriptDomAdapter());
}

Expand Down
5 changes: 2 additions & 3 deletions nativescript-angular/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import {View} from "ui/core/view";
import * as application from "application";
import {topmost} from 'ui/frame';
import {Page} from 'ui/page';
import {traceLog, ViewUtil, NgView} from "./view-util";
import {ViewUtil, NgView} from "./view-util";
import {rendererLog as traceLog} from "./trace";
import {escapeRegexSymbols} from "utils/utils";
import { Device } from "platform";

export { rendererTraceCategory } from "./view-util";

@Injectable()
export class NativeScriptRootRenderer implements RootRenderer {
private _rootView: View = null;
Expand Down
7 changes: 0 additions & 7 deletions nativescript-angular/router/common.ts

This file was deleted.

28 changes: 14 additions & 14 deletions nativescript-angular/router/ns-location-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import application = require("application");
import { LocationStrategy } from '@angular/common';
import { NgZone, ApplicationRef, Inject, forwardRef } from '@angular/core';
import { log } from "./common";
import { routerLog } from "../trace";
import { topmost } from "ui/frame";

interface LocationState {
Expand All @@ -20,18 +20,18 @@ export class NSLocationStrategy extends LocationStrategy {
private _isPageNavigatingForward: boolean = false;

path(): string {
log("NSLocationStrategy.path()");
routerLog("NSLocationStrategy.path()");
let state = this.peekState();
return state ? state.url : "/";
}

prepareExternalUrl(internal: string): string {
log("NSLocationStrategy.prepareExternalUrl() internal: " + internal);
routerLog("NSLocationStrategy.prepareExternalUrl() internal: " + internal);
return internal;
}

pushState(state: any, title: string, url: string, queryParams: string): void {
log(`NSLocationStrategy.pushState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);
routerLog(`NSLocationStrategy.pushState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);

let isNewPage = this._isPageNavigatingForward;
this._isPageNavigatingForward = false;
Expand All @@ -46,12 +46,12 @@ export class NSLocationStrategy extends LocationStrategy {
}

replaceState(state: any, title: string, url: string, queryParams: string): void {
log(`NSLocationStrategy.replaceState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);
routerLog(`NSLocationStrategy.replaceState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);
throw new Error("Not implemented");
}

forward(): void {
log("NSLocationStrategy.forward");
routerLog("NSLocationStrategy.forward");
throw new Error("Not implemented");
}

Expand All @@ -65,30 +65,30 @@ export class NSLocationStrategy extends LocationStrategy {
state = this.states.pop();
count++;
}
log("NSLocationStrategy.back() while navigating back. States popped: " + count)
routerLog("NSLocationStrategy.back() while navigating back. States popped: " + count)
this.callPopState(state, true);
} else {
let state = this.peekState();
if (state.isPageNavigation) {
// This was a page navigation - so navigate through frame.
log("NSLocationStrategy.back() while not navigating back but top state is page - will call frame.goback()")
routerLog("NSLocationStrategy.back() while not navigating back but top state is page - will call frame.goback()")
topmost().goBack();
} else {
// Nested navigation - just pop the state
log("NSLocationStrategy.back() while not navigating back but top state is not page - just pop")
routerLog("NSLocationStrategy.back() while not navigating back but top state is not page - just pop")
this.callPopState(this.states.pop(), true);
}
}

}

onPopState(fn: (_: any) => any): void {
log("NSLocationStrategy.onPopState");
routerLog("NSLocationStrategy.onPopState");
this.popStateCallbacks.push(fn);
}

getBaseHref(): string {
log("NSLocationStrategy.getBaseHref()");
routerLog("NSLocationStrategy.getBaseHref()");
return "";
}

Expand All @@ -108,15 +108,15 @@ export class NSLocationStrategy extends LocationStrategy {

// Methods for syncing with page navigation in PageRouterOutlet
public beginBackPageNavigation() {
log("NSLocationStrategy.startGoBack()");
routerLog("NSLocationStrategy.startGoBack()");
if (this._isPageNavigationgBack) {
throw new Error("Calling startGoBack while going back.")
}
this._isPageNavigationgBack = true;
}

public finishBackPageNavigation() {
log("NSLocationStrategy.finishBackPageNavigation()");
routerLog("NSLocationStrategy.finishBackPageNavigation()");
if (!this._isPageNavigationgBack) {
throw new Error("Calling endGoBack while not going back.")
}
Expand All @@ -128,7 +128,7 @@ export class NSLocationStrategy extends LocationStrategy {
}

public navigateToNewPage() {
log("NSLocationStrategy.navigateToNewPage()");
routerLog("NSLocationStrategy.navigateToNewPage()");
if (this._isPageNavigatingForward) {
throw new Error("Calling navigateToNewPage while already navigating to new page.")
}
Expand Down
4 changes: 2 additions & 2 deletions nativescript-angular/router/ns-router-link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Directive, Input} from '@angular/core';
import {isString} from '@angular/core/src/facade/lang';
import {Router, Instruction} from '@angular/router-deprecated';
import { log } from "./common";
import {routerLog} from "../trace";

/**
* The NSRouterLink directive lets you link to specific parts of your app.
Expand Down Expand Up @@ -55,7 +55,7 @@ export class NSRouterLink {
}

onTap(): void {
log("NSRouterLink onTap() instruction: " + JSON.stringify(this._navigationInstruction))
routerLog("NSRouterLink onTap() instruction: " + JSON.stringify(this._navigationInstruction))
this._router.navigateByInstruction(this._navigationInstruction);
}
}
4 changes: 1 addition & 3 deletions nativescript-angular/router/ns-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {NSLocationStrategy} from './ns-location-strategy';
import {ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {LocationStrategy} from '@angular/common';
import {provide} from '@angular/core';
import { CATEGORY } from "./common";
export {routerTraceCategory} from "../trace";

export const NS_ROUTER_PROVIDERS: any[] = [
ROUTER_PROVIDERS,
Expand All @@ -17,5 +17,3 @@ export const NS_ROUTER_DIRECTIVES: Type[] = [
NSRouterLink,
PageRouterOutlet
];

export const routerTraceCategory = CATEGORY;
14 changes: 7 additions & 7 deletions nativescript-angular/router/page-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {topmost} from "ui/frame";
import {Page, NavigatedData} from "ui/page";
import {DEVICE} from "../platform-providers";
import {Device} from "platform";
import {log} from "./common";
import {routerLog} from "../trace";
import {NSLocationStrategy} from "./ns-location-strategy";
import {DetachedLoader} from "../common/detached-loader";
import {ViewUtil} from "../view-util";
Expand Down Expand Up @@ -106,7 +106,7 @@ export class PageRouterOutlet extends RouterOutlet {
}

private activateOnGoBack(nextInstruction: ComponentInstruction, previousInstruction: ComponentInstruction): Promise<any> {
log("PageRouterOutlet.activate() - Back naviation, so load from cache: " + nextInstruction.componentType.name);
routerLog("PageRouterOutlet.activate() - Back naviation, so load from cache: " + nextInstruction.componentType.name);

this.location.finishBackPageNavigation();

Expand Down Expand Up @@ -134,14 +134,14 @@ export class PageRouterOutlet extends RouterOutlet {
];

if (this.isInitalPage) {
log("PageRouterOutlet.activate() inital page - just load component: " + componentType.name);
routerLog("PageRouterOutlet.activate() inital page - just load component: " + componentType.name);
this.isInitalPage = false;
resultPromise = this.compiler.resolveComponent(componentType).then((componentFactory) => {
const childInjector = ReflectiveInjector.resolveAndCreate(providersArray, this.containerRef.parentInjector);
return this.containerRef.createComponent(componentFactory, this.containerRef.length, childInjector, null);
});
} else {
log("PageRouterOutlet.activate() forward navigation - create detached loader in the loader container: " + componentType.name);
routerLog("PageRouterOutlet.activate() forward navigation - create detached loader in the loader container: " + componentType.name);

const page = new Page();
providersArray.push(provide(Page, { useValue: page }));
Expand Down Expand Up @@ -215,7 +215,7 @@ export class PageRouterOutlet extends RouterOutlet {
}

if (this.location.isPageNavigatingBack()) {
log("PageRouterOutlet.deactivate() while going back - should destroy: " + instruction.componentType.name)
routerLog("PageRouterOutlet.deactivate() while going back - should destroy: " + instruction.componentType.name)
return next.then((_) => {
const popedItem = this.refCache.pop();
const popedRef = popedItem.componentRef;
Expand Down Expand Up @@ -275,7 +275,7 @@ export class PageRouterOutlet extends RouterOutlet {
StringMapWrapper.equals(nextInstruction.params, this.currentInstruction.params));
}

log("PageRouterOutlet.routerCanReuse(): " + result);
routerLog("PageRouterOutlet.routerCanReuse(): " + result);
return PromiseWrapper.resolve(result);
}

Expand Down Expand Up @@ -311,6 +311,6 @@ export class PageRouterOutlet extends RouterOutlet {
}

private log(method: string, nextInstruction: ComponentInstruction) {
log("PageRouterOutlet." + method + " isBack: " + this.location.isPageNavigatingBack() + " nextUrl: " + nextInstruction.urlPath);
routerLog("PageRouterOutlet." + method + " isBack: " + this.location.isPageNavigatingBack() + " nextUrl: " + nextInstruction.urlPath);
}
}
20 changes: 20 additions & 0 deletions nativescript-angular/trace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {write, categories, messageType} from "trace";

export const rendererTraceCategory = "ns-renderer";
export const routerTraceCategory = "ns-router";

export function rendererLog(msg): void {
write(msg, rendererTraceCategory);
}

export function rendererError(message: string): void {
write(message, rendererTraceCategory, messageType.error);
}

export function routerLog(message: string): void {
write(message, routerTraceCategory);
}

export function styleError(message: string): void {
write(message, categories.Style, messageType.error);
}
9 changes: 2 additions & 7 deletions nativescript-angular/view-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@ import * as styleProperty from "ui/styling/style-property";
import {StyleProperty, getPropertyByName, withStyleProperty} from "ui/styling/style-property";
import {ValueSource} from "ui/core/dependency-observable";
import { ActionBar, ActionItem, NavigationButton } from "ui/action-bar";
import trace = require("trace");
import {device, platformNames, Device} from "platform";
import {rendererLog as traceLog, styleError} from "./trace";

const IOS_PREFX: string = "@ios:";
const ANDROID_PREFX: string = "@android:";
const whiteSpaceSplitter = /\s+/;

export const rendererTraceCategory = "ns-renderer";
export type ViewExtensions = ViewExtensions;
export type NgView = NgView;
export type NgLayoutBase = LayoutBase & ViewExtensions;
export type NgContentView = ContentView & ViewExtensions;
export type BeforeAttachAction = (view: View) => void;

export function traceLog(msg) {
trace.write(msg, rendererTraceCategory);
}

export function isView(view: any): view is NgView {
return view instanceof View;
}
Expand Down Expand Up @@ -298,7 +293,7 @@ export class ViewUtil {
try {
view.style._setValue(property, value, ValueSource.Local);
} catch (ex) {
trace.write("Error setting property: " + property.name + " view: " + view + " value: " + value + " " + ex, trace.categories.Style, trace.messageType.error);
styleError("Error setting property: " + property.name + " view: " + view + " value: " + value + " " + ex);
}
}

Expand Down
Loading