Skip to content
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
11 changes: 4 additions & 7 deletions apps/app/ui-tests-app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ application.on(application.lowMemoryEvent, function (args: application.Applicati
});

application.on(application.uncaughtErrorEvent, function (args: application.UnhandledErrorEventData) {
if (args.android) {
// For Android applications, args.android is NativeScriptError.
console.log("### NativeScriptError: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is NativeScriptError.
console.log("### NativeScriptError: " + args.ios);
}
console.log("### NativeScriptError: " + args.error);
console.log("### nativeException: " + (<any>args.error).nativeException);
console.log("### stackTace: " + (<any>args.error).stackTrace);
console.log("### stack: " + args.error.stack);
});

application.setCssFileName("ui-tests-app/app.css");
Expand Down
12 changes: 5 additions & 7 deletions apps/app/ui-tests-app/mainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ var oldExamples: Map<string, string> = new Map<string, string>();

export function pageLoaded(args: EventData) {
let page = <Page>args.object;
let view = require("ui/core/view");
let wrapLayout = <WrapLayout>view.getViewById(page, "wrapLayoutWithExamples");

let wrapLayout = page.getViewById<WrapLayout>("wrapLayoutWithExamples");
examples.set("action-bar", "action-bar/main-page");
examples.set("bindings", "bindings/main-page");
examples.set("css", "css/main-page");
Expand Down Expand Up @@ -46,8 +44,8 @@ export function pageLoaded(args: EventData) {
let viewModel = new MainPageViewModel(wrapLayout, examples);
page.bindingContext = viewModel;

var parent = page.getViewById('parentLayout');
var searchBar = page.getViewById('textView');
var parent = page.getViewById('parentLayout');
var searchBar = page.getViewById('textView');

if (parent.android) {
parent.android.setFocusableInTouchMode(true);
Expand All @@ -57,7 +55,7 @@ export function pageLoaded(args: EventData) {

refresh();
}

// should be removes
export function refresh() {
oldExamples.set("actStyle", "action-bar/all");
Expand Down Expand Up @@ -217,7 +215,7 @@ export class MainPageViewModel extends observable.Observable {
}

btn.style.color = new colorModule.Color(this.colors[count++ % 3]);
btn.on(buttonModule.Button.tapEvent, function(eventData) {
btn.on(buttonModule.Button.tapEvent, function (eventData) {
let text = btn.text;
this.loadExample(text);
}, this);
Expand Down
4 changes: 2 additions & 2 deletions tests/app/TKUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,13 @@ export var wait = function (seconds: number) {
}, seconds, false);
};

export var waitUntilReady = function (isReady: () => boolean, timeoutSec: number = 20, shouldThrow: boolean = true) {
export var waitUntilReady = function (isReady: () => boolean, timeoutSec: number = 3, shouldThrow: boolean = true) {
if (!isReady) {
return;
}

if (Application.ios) {
var waitTime = 20 / 1000;
const waitTime = 20 / 1000;
var totalWaitTime = 0;
while (true) {
utils.ios.getter(NSRunLoop, NSRunLoop.currentRunLoop).runUntilDate(<any>NSDate.dateWithTimeIntervalSinceNow(waitTime));
Expand Down
6 changes: 5 additions & 1 deletion tests/app/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ function printRunTestStats() {
page.style.backgroundColor = unsetValue;
page.content = stack;
messageContainer.focus();
page.style.fontSize = 11;
if (page.android) {
setTimeout(() => messageContainer.dismissSoftInput());
setTimeout(() => {
messageContainer.dismissSoftInput();
(<android.view.View>messageContainer.nativeView).scrollTo(0, 0);
});
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/app/ui/action-bar/action-bar-tests.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function test_actionItem_visibility() {
actionItem.text = "Test";
const page = actionTestsCommon.createPageAndNavigate();
page.actionBar.actionItems.addItem(actionItem);
const toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;
const menu = toolbar.getMenu();

TKUnit.assertTrue(menu.hasVisibleItems(), "Visibility does not work");
Expand All @@ -25,7 +25,7 @@ export function test_navigationButton_visibility() {
const page = actionTestsCommon.createPageAndNavigate();
page.actionBar.navigationButton = actionItem;

const toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;

TKUnit.assertNotNull(toolbar.getNavigationIcon(), "Visibility does not work");
actionItem.visibility = Visibility.collapse;
Expand Down Expand Up @@ -72,4 +72,4 @@ export function test_add_actionItem_with_actionView_propagates_context() {
TKUnit.assertNull(actionButton._context, "Action button context should be null before added");
actionItem.actionView = actionButton;
TKUnit.assertNotNull(actionButton._context, "Action button context should not be null after add");
}
}
4 changes: 2 additions & 2 deletions tests/app/ui/core/bindable/bindable-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export function test_BindingToDictionaryAtAppLevel() {
pageViewModel.set("testProperty", testPropertyName);
const dict = {};
dict[testPropertyName] = expectedValue;
appModule.resources["dict"] = dict;
appModule.getResources()["dict"] = dict;

const testFunc = function (views: Array<View>) {
const testLabel = <Label>(views[0]);
Expand All @@ -629,7 +629,7 @@ export function test_BindingConverterCalledEvenWithNullValue() {
const testPropertyValue = null;
const expectedValue = "collapsed";
pageViewModel.set("testProperty", testPropertyValue);
appModule.resources["converter"] = function (value) {
appModule.getResources()["converter"] = function (value) {
if (value) {
return "visible";
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/app/ui/layouts/common-layout-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function percent_support_nativeLayoutParams_are_correct(test: testModule.

test.waitUntilTestElementLayoutIsValid();

let lp = getNativeLayoutParams(btn._nativeView);
let lp = getNativeLayoutParams(btn.nativeView);
TKUnit.assertEqual(lp.width, 100, "width");
TKUnit.assertEqual(lp.widthPercent, -1, "widthPercent");
TKUnit.assertEqual(lp.height, 100, "height");
Expand Down
1 change: 1 addition & 0 deletions tests/app/ui/layouts/flexbox-layout-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export function testFlexboxPage() {
function view(id: string) {
return <View>page.getViewById(id);
}
TKUnit.waitUntilReady(() => page.isLayoutValid);
isLeftOf(view("six"), view("one"));
isAbove(view("one"), view("scrollview"));
isAbove(view("title"), view("firstlabel"));
Expand Down
94 changes: 41 additions & 53 deletions tests/app/ui/layouts/layout-helper.android.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {Button} from "tns-core-modules/ui/button";
import {StackLayout} from "tns-core-modules/ui/layouts/stack-layout";
import {GridLayout} from "tns-core-modules/ui/layouts/grid-layout";
import { Button } from "tns-core-modules/ui/button";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout";

import * as utils from "tns-core-modules/utils/utils";
import * as TKUnit from "../../TKUnit";
import * as def from "./layout-helper";

var DELTA = 0.1;

class NativeButton extends android.widget.Button {
private owner: def.MeasuredView;

constructor(context: android.content.Context, owner: def.MeasuredView) {
class NativeButton extends android.widget.Button {
constructor(context: android.content.Context, public owner: def.MeasuredView) {
super(context);
this.owner = owner;
return global.__native(this);
}

Expand All @@ -31,11 +28,8 @@ class NativeButton extends android.widget.Button {
}

class NativeStackLayout extends org.nativescript.widgets.StackLayout {
private owner: def.MeasuredView;

constructor(context: android.content.Context, owner: def.MeasuredView) {
constructor(context: android.content.Context, public owner: def.MeasuredView) {
super(context);
this.owner = owner;
return global.__native(this);
}

Expand All @@ -53,11 +47,8 @@ class NativeStackLayout extends org.nativescript.widgets.StackLayout {
}

class NativeGridLayout extends org.nativescript.widgets.GridLayout {
private owner: def.MeasuredView;

constructor(context: android.content.Context, owner: def.MeasuredView) {
constructor(context: android.content.Context, public owner: def.MeasuredView) {
super(context);
this.owner = owner;
return global.__native(this);
}

Expand All @@ -75,19 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
}

export class MyButton extends Button implements def.MyButton {
private _layout: android.view.View;
nativeView: NativeButton;

get android(): android.view.View {
return this._layout;
public createNativeView() {
return new NativeButton(this._context, this);
}

get _nativeView(): android.view.View {
return this._layout;
public initNativeView(): void {
this.nativeView.owner = this;
}

public _createNativeView() {
this._layout = new NativeButton(this._context, this);
return this._layout;
public disposeNativeView() {
this.nativeView.owner = undefined;
}

public measureCount: number = 0;
Expand All @@ -112,36 +102,35 @@ export class MyButton extends Button implements def.MyButton {
}

get layoutWidth(): number {
return this._layout.getWidth();
return this.nativeView.getWidth();
}

get layoutHeight(): number {
return this._layout.getHeight();
return this.nativeView.getHeight();
}

get layoutLeft(): number {
return this._layout.getLeft();
return this.nativeView.getLeft();
}

get layoutTop(): number {
return this._layout.getTop();
return this.nativeView.getTop();
}
}

export class MyStackLayout extends StackLayout implements def.MyStackLayout {
private _layout: android.view.View;
nativeView: NativeStackLayout;

get android(): android.view.View {
return this._layout;
public createNativeView() {
return new NativeStackLayout(this._context, this);
}

get _nativeView(): android.view.View {
return this._layout;
public initNativeView(): void {
this.nativeView.owner = this;
}

public _createNativeView() {
this._layout = new NativeStackLayout(this._context, this);
return this._layout;
public disposeNativeView() {
this.nativeView.owner = undefined;
}

public measureCount: number = 0;
Expand All @@ -166,36 +155,35 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
}

get layoutWidth(): number {
return this._layout.getWidth();
return this.nativeView.getWidth();
}

get layoutHeight(): number {
return this._layout.getHeight();
return this.nativeView.getHeight();
}

get layoutLeft(): number {
return this._layout.getLeft();
return this.nativeView.getLeft();
}

get layoutTop(): number {
return this._layout.getTop();
return this.nativeView.getTop();
}
}

export class MyGridLayout extends GridLayout implements def.MyGridLayout {
private _layout: android.view.View;
nativeView: NativeGridLayout;

get android(): android.view.View {
return this._layout;
public createNativeView() {
return new NativeGridLayout(this._context, this);
}

get _nativeView(): android.view.View {
return this._layout;
public initNativeView(): void {
this.nativeView.owner = this;
}

public _createNativeView() {
this._layout = new NativeGridLayout(this._context, this);
return this._layout;
public disposeNativeView() {
this.nativeView.owner = undefined;
}

public measureCount: number = 0;
Expand All @@ -220,19 +208,19 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout {
}

get layoutWidth(): number {
return this._layout.getWidth();
return this.nativeView.getWidth();
}

get layoutHeight(): number {
return this._layout.getHeight();
return this.nativeView.getHeight();
}

get layoutLeft(): number {
return this._layout.getLeft();
return this.nativeView.getLeft();
}

get layoutTop(): number {
return this._layout.getTop();
return this.nativeView.getTop();
}
}

Expand All @@ -258,4 +246,4 @@ export function dp(value: number): number {

export function dip(value: number): number {
return utils.layout.toDevicePixels(value);
}
}
8 changes: 4 additions & 4 deletions tests/app/ui/list-picker/list-picker-tests-native.android.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as listPickerModule from "tns-core-modules/ui/list-picker";

export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): number {
var maxValue = listPicker.android.getMaxValue();
var maxValue = listPicker.nativeView.getMaxValue();

if (listPicker.items.length === 0 && maxValue === 0) {
return 0;
Expand All @@ -12,6 +12,6 @@ export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): nu

export function selectNativeItem(listPicker: listPickerModule.ListPicker, index: number): void {
var oldIndex = listPicker.selectedIndex;
listPicker.android.setValue(index);
(<any>listPicker)._valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
}
listPicker.nativeView.setValue(index);
listPicker.nativeView.valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
}
Loading