NativeView recycled for android

This commit is contained in:
Hristo Hristov
2017-03-28 12:48:19 +03:00
parent 5e555bcfd4
commit f2898f84d5
114 changed files with 1480 additions and 1391 deletions

View File

@@ -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));

View File

@@ -344,6 +344,7 @@ function printRunTestStats() {
page.style.backgroundColor = unsetValue;
page.content = stack;
messageContainer.focus();
page.style.fontSize = 11;
if (page.android) {
setTimeout(() => messageContainer.dismissSoftInput());
}

View File

@@ -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");
@@ -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;
@@ -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");
}
}

View File

@@ -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");

View File

@@ -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"));

View File

@@ -1,6 +1,6 @@
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";
@@ -8,12 +8,9 @@ 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);
}
@@ -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);
}
@@ -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);
}
@@ -75,19 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
}
export class MyButton extends Button implements def.MyButton {
private _layout: android.view.View;
get android(): android.view.View {
return this._layout;
}
get _nativeView(): android.view.View {
return this._layout;
}
nativeView: NativeButton;
public _createNativeView() {
this._layout = new NativeButton(this._context, this);
return this._layout;
return new NativeButton(this._context, this);
}
public _initNativeView(): void {
this.nativeView.owner = this;
}
public _disposeNativeView() {
this.nativeView.owner = undefined;
}
public measureCount: number = 0;
@@ -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;
get android(): android.view.View {
return this._layout;
}
get _nativeView(): android.view.View {
return this._layout;
}
nativeView: NativeStackLayout;
public _createNativeView() {
this._layout = new NativeStackLayout(this._context, this);
return this._layout;
return new NativeStackLayout(this._context, this);
}
public _initNativeView(): void {
this.nativeView.owner = this;
}
public _disposeNativeView() {
this.nativeView.owner = undefined;
}
public measureCount: number = 0;
@@ -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;
get android(): android.view.View {
return this._layout;
}
get _nativeView(): android.view.View {
return this._layout;
}
nativeView: NativeGridLayout;
public _createNativeView() {
this._layout = new NativeGridLayout(this._context, this);
return this._layout;
return new NativeGridLayout(this._context, this);
}
public _initNativeView(): void {
this.nativeView.owner = this;
}
public _disposeNativeView() {
this.nativeView.owner = undefined;
}
public measureCount: number = 0;
@@ -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();
}
}
@@ -258,4 +246,4 @@ export function dp(value: number): number {
export function dip(value: number): number {
return utils.layout.toDevicePixels(value);
}
}

View File

@@ -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;
@@ -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);
}

View File

@@ -170,7 +170,7 @@ export var testWhenSelectingAnItemNativelySelectedIndexIsUpdatedProperly = funct
TKUnit.waitUntilReady(() => listPicker.selectedIndex === 1);
let actualValue = listPicker.selectedIndex;
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
TKUnit.assertEqual(actualValue, expectedValue);
}
export var test_Android_MaxValueIsOneLessThanItemsCount = function () {
@@ -182,8 +182,8 @@ export var test_Android_MaxValueIsOneLessThanItemsCount = function () {
var listPicker = <listPickerModule.ListPicker>views[0];
listPicker.items = ["One", "Two", "Three"];
var expectedValue = listPicker.items.length - 1;
var actualValue = (<any>listPicker).android.getMaxValue();
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
var actualValue = listPicker.nativeView.getMaxValue();
TKUnit.assertEqual(actualValue, expectedValue);
});
}
@@ -195,8 +195,8 @@ export var test_Android_WhenItemsAreEmptyNativeControlDoesNotShowZero = function
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<viewModule.View>) {
var listPicker = <listPickerModule.ListPicker>views[0];
var expectedValue = " ";
var actualValue = (<any>listPicker)._editText.getText().toString();
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
var actualValue = listPicker.nativeView.editText.getText().toString();
TKUnit.assertEqual(actualValue, expectedValue);
});
}
@@ -209,8 +209,8 @@ export var test_Android_WhenBoundToSingleElementArrayEditTextIsUpdatedProperly =
var listPicker = <listPickerModule.ListPicker>views[0];
listPicker.items = ["One"];
var expectedValue = "One";
var actualValue = (<any>listPicker)._editText.getText().toString();
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
var actualValue = listPicker.nativeView.editText.getText().toString();
TKUnit.assertEqual(actualValue, expectedValue);
});
}
@@ -224,7 +224,7 @@ export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = func
listPicker.items = ["One", "Two"];
listPicker.selectedIndex = 1;
var expectedValue = "Two";
var actualValue = (<any>listPicker)._editText.getText().toString();
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
var actualValue = listPicker.nativeView.editText.getText().toString();
TKUnit.assertEqual(actualValue, expectedValue);
});
}
}

View File

@@ -259,6 +259,8 @@ export function test_NavigateTo_WithBindingContext() {
}
export function test_FrameBackStack_WhenNavigatingForwardAndBack() {
helper.navigate(() => new Page());
let testPage: Page;
let pageFactory = function () {
testPage = new Page();

View File

@@ -43,19 +43,19 @@ export function test_NavigateToNewPage_WithAndroidCache() {
androidFrame.cachePagesOnNavigate = cachingBefore;
}
TKUnit.assert(testPage.parent === undefined, "Page.parent should become undefined after navigating back");
TKUnit.assert(testPage.isLoaded === false, "Page.isLoaded should become false after navigating back");
TKUnit.assert(testPage.frame === undefined, "Page.frame should become undefined after navigating back");
TKUnit.assert(testPage._isAddedToNativeVisualTree === false, "Page._isAddedToNativeVisualTree should become false after navigating back");
TKUnit.assertNull(testPage.parent, "Page.parent should become undefined after navigating back");
TKUnit.assertFalse(testPage.isLoaded, "Page.isLoaded should become false after navigating back");
TKUnit.assertNull(testPage.frame, "Page.frame should become undefined after navigating back");
TKUnit.assertFalse(testPage._isAddedToNativeVisualTree, "Page._isAddedToNativeVisualTree should become false after navigating back");
TKUnit.assert(label._context === null, "InnerControl._context should not be set after navigate back.");
TKUnit.assert(label.android === undefined, "InnerControl.android should not be set after navigate back.");
TKUnit.assert(label._nativeView === undefined, "InnerControl._nativeView hould not be set after navigate back.");
TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back");
TKUnit.assert(label._isAddedToNativeVisualTree === false, "InnerControl._isAddedToNativeVisualTree should not be true after navigating back");
TKUnit.assertNull(label._context, "InnerControl._context should not be set after navigate back.");
TKUnit.assertNull(label.android, "InnerControl.android should not be set after navigate back.");
TKUnit.assertNull(label.nativeView, "InnerControl.nativeView hould not be set after navigate back.");
TKUnit.assertFalse(label.isLoaded, "InnerControl.isLoaded should become false after navigating back");
TKUnit.assertFalse(label._isAddedToNativeVisualTree, "InnerControl._isAddedToNativeVisualTree should not be true after navigating back");
}
export var test_NavigateToNewPage_InnerControl = function () {
export function test_NavigateToNewPage_InnerControl() {
var testPage: PageModule.Page;
var pageFactory = function () {
testPage = new PageModule.Page();
@@ -69,11 +69,11 @@ export var test_NavigateToNewPage_InnerControl = function () {
var label = <LabelModule.Label>testPage.content;
TKUnit.assert(label._context === null, "InnerControl._context should be undefined after navigate back.");
TKUnit.assert(label.android === undefined, "InnerControl.android should be undefined after navigate back.");
TKUnit.assert(label._nativeView === undefined, "InnerControl._nativeView should be undefined after navigate back.");
TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back");
TKUnit.assert(label._isAddedToNativeVisualTree === false, "InnerControl._isAddedToNativeVisualTree should become false after navigating back");
TKUnit.assertNull(label._context, "InnerControl._context should be undefined after navigate back.");
TKUnit.assertNull(label.android, "InnerControl.android should be undefined after navigate back.");
TKUnit.assertNull(label.nativeView, "InnerControl.nativeView should be undefined after navigate back.");
TKUnit.assertFalse(label.isLoaded, "InnerControl.isLoaded should become false after navigating back");
TKUnit.assertFalse(label._isAddedToNativeVisualTree, "InnerControl._isAddedToNativeVisualTree should become false after navigating back");
}
export var test_ChangePageCaching_AfterNavigated_Throws = function () {

View File

@@ -23,8 +23,8 @@ export function test_NavigateToNewPage_InnerControl() {
helper.goBack();
TKUnit.assertEqual(label._context, null, "label._context should be undefined after navigate back.");
TKUnit.assertEqual(label.android, undefined, "label.android should be undefined after navigate back.");
TKUnit.assertNull(label._context, "label._context should be undefined after navigate back.");
TKUnit.assertNull(label.android, "label.android should be undefined after navigate back.");
TKUnit.assertFalse(label.isLoaded, "label.isLoaded should become false after navigating back");
}

View File

@@ -1,19 +1,19 @@
import * as segmentedBarModule from "tns-core-modules/ui/segmented-bar";
export function getNativeItemsCount(bar: segmentedBarModule.SegmentedBar): number {
return (<UISegmentedControl>bar.ios).numberOfSegments;
return (<UISegmentedControl>bar.nativeView).numberOfSegments;
}
export function checkNativeItemsTextColor(bar: segmentedBarModule.SegmentedBar): boolean {
var isValid = true;
var attrs = (<UISegmentedControl>bar.ios).titleTextAttributesForState(UIControlState.Normal);
var attrs = (<UISegmentedControl>bar.nativeView).titleTextAttributesForState(UIControlState.Normal);
isValid = bar.color && attrs && attrs.valueForKey(NSForegroundColorAttributeName) === bar.color.ios;
return isValid;
}
export function setNativeSelectedIndex(bar: segmentedBarModule.SegmentedBar, index: number): void {
bar.ios.selectedSegmentIndex = index;
(<UISegmentedControl>bar.ios).sendActionsForControlEvents(UIControlEvents.ValueChanged);
(<UISegmentedControl>bar.nativeView).selectedSegmentIndex = index;
(<UISegmentedControl>bar.nativeView).sendActionsForControlEvents(UIControlEvents.ValueChanged);
}

View File

@@ -13,10 +13,10 @@ import * as switchModule from "tns-core-modules/ui/switch";
// >> article-binding-switch-property
function pageLoaded(args) {
var page = args.object;
var obj = new observable.Observable();
obj.set("someProperty", false);
page.bindingContext = obj;
var page = args.object;
var obj = new observable.Observable();
obj.set("someProperty", false);
page.bindingContext = obj;
}
exports.pageLoaded = pageLoaded;
// << article-binding-switch-property
@@ -137,17 +137,18 @@ export function test_binding_value_to_model() {
}
function getNativeValue(mySwitch: switchModule.Switch): boolean {
if (mySwitch.android) {
return mySwitch.android.isChecked();
}
else if (mySwitch.ios) {
if (platform.isAndroid) {
const nativeView: android.widget.Switch = mySwitch.nativeView;
return nativeView.isChecked();
} else if (mySwitch.ios) {
return mySwitch.ios.on;
}
}
function setNativeValue(mySwitch: switchModule.Switch, value: boolean) {
if (mySwitch.android) {
mySwitch.android.setChecked(value);
if (platform.isAndroid) {
const nativeView: android.widget.Switch = mySwitch.nativeView;
nativeView.setChecked(value);
}
else if (mySwitch.ios) {
mySwitch.ios.on = value;

View File

@@ -185,7 +185,7 @@ export class TabViewTest extends testModule.UITest<tabViewModule.TabView> {
var tabView = this.testView;
this.waitUntilTestElementIsLoaded();
TKUnit.assertThrows(function () {
TKUnit.assertThrows(() => {
let item = new tabViewModule.TabViewItem();
item.title = "Tab 0";
item.view = undefined;
@@ -198,7 +198,7 @@ export class TabViewTest extends testModule.UITest<tabViewModule.TabView> {
var tabView = this.testView;
this.waitUntilTestElementIsLoaded();
TKUnit.assertThrows(function () {
TKUnit.assertThrows(() => {
let item = new tabViewModule.TabViewItem();
item.title = "Tab 0";
item.view = null;

View File

@@ -46,7 +46,7 @@ var _createTextViewFunc = function (): textViewModule.TextView {
export var testSetText = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
// >> set-text-value
textView.text = "Hello, world!";
// << set-text-value
@@ -60,7 +60,7 @@ export var testSetText = function () {
export var testSetTextNull = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
textView.text = null;
var expectedValue = "";
@@ -304,14 +304,14 @@ export var testBindEditableDirectlyToModel = function () {
textView.bind(options, model);
// textView.editable is now false
// >> (hide)
TKUnit.assert(textView.editable === false, "Actual: " + textView.text + "; Expected: " + false);
TKUnit.assert(textViewTestsNative.getNativeEditable(textView) === false, "Actual: " + textViewTestsNative.getNativeEditable(textView) + "; Expected: " + false);
TKUnit.assertFalse(textView.editable, ".ediable property should be false");
TKUnit.assertFalse(textViewTestsNative.getNativeEditable(textView), "native Editable should be false");
// << (hide)
model.set("editable", true);
// textView.editable is now true
// >> (hide)
TKUnit.assert(textView.editable === true, "Actual: " + textView.text + "; Expected: " + true);
TKUnit.assert(textViewTestsNative.getNativeEditable(textView) === true, "Actual: " + textViewTestsNative.getNativeEditable(textView) + "; Expected: " + true);
TKUnit.assertTrue(textView.editable, ".ediable property should be true");
TKUnit.assertTrue(textViewTestsNative.getNativeEditable(textView), "native Editable should be true");
// << (hide)
// << binding-editable-property
});
@@ -332,12 +332,12 @@ export var testBindEditableToBindingConext = function () {
}
textView.bind(options);
TKUnit.assert(textView.editable === false, "Actual: " + textView.text + "; Expected: " + false);
TKUnit.assert(textViewTestsNative.getNativeEditable(textView) === false, "Actual: " + textViewTestsNative.getNativeEditable(textView) + "; Expected: " + false);
TKUnit.assertFalse(textView.editable, ".ediable property should be false");
TKUnit.assertFalse(textViewTestsNative.getNativeEditable(textView), "native Editable should be false");
model.set("editable", true);
TKUnit.assert(textView.editable === true, "Actual: " + textView.text + "; Expected: " + true);
TKUnit.assert(textViewTestsNative.getNativeEditable(textView) === true, "Actual: " + textViewTestsNative.getNativeEditable(textView) + "; Expected: " + true);
TKUnit.assertTrue(textView.editable, ".ediable property should be true");
TKUnit.assertTrue(textViewTestsNative.getNativeEditable(textView), "native Editable should be true");
});
}
@@ -499,7 +499,7 @@ export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormatt
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
view.text = "NormalText";
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform");
TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration");
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
@@ -512,7 +512,7 @@ export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedT
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
view.formattedText = formattedString;
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform");
TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration");
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");

View File

@@ -92,19 +92,19 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
}
public testMinuteIntervalThrowExceptionWhenLessThan1() {
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minuteInterval = 0;
}, "Setting minuteInterval property to a value less than 1 should throw.");
}
public testMinuteIntervalThrowExceptionWhenGreaterThan30() {
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minuteInterval = 31;
}, "Setting minuteInterval property to a value greater than 30 should throw.");
}
public testMinuteIntervalThrowExceptionWhenNotFold60() {
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minuteInterval = 7;
}, "Setting minuteInterval property to a value not fold 60 should throw.");
}
@@ -112,14 +112,14 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
public testHourThrowExceptionWhenLessThanMinHour() {
this.testView.hour = 14;
this.testView.minHour = this.testView.hour - 1;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.hour = this.testView.minHour - 1;
}, "Setting hour property to a value less than minHour property value should throw.");
}
public testMinHourThrowExceptionWhenHourLessThanMinHour() {
this.testView.hour = 14;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minHour = this.testView.hour + 1;
}, "Setting minHour property to a greater than hour property value should throw.");
}
@@ -127,14 +127,14 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
public testHourThrowExceptionWhenGreaterThanMaxHour() {
this.testView.hour = 14;
this.testView.maxHour = this.testView.hour + 1;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.hour = this.testView.maxHour + 1;
}, "Setting hour property to a value greater than maxHour property value should throw.");
}
public testMaxHourThrowExceptionWhenHourGreaterThanMaxHour() {
this.testView.hour = 14;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.maxHour = this.testView.hour - 1;
}, "Setting maxHour property to a value less than hour property value should throw.");
}
@@ -145,7 +145,7 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
this.testView.minHour = this.testView.hour;
this.testView.minMinute = this.testView.minute;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minute = this.testView.minMinute - 1;
}, "Setting minute property to a value less than minMinute property value should throw.");
}
@@ -155,7 +155,7 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
this.testView.minute = 13;
this.testView.minHour = this.testView.hour;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minMinute = this.testView.minute + 1;
}, "Setting minMinute property to a value greater than minute property value should throw.");
}
@@ -166,7 +166,7 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
this.testView.maxHour = this.testView.hour;
this.testView.maxMinute = this.testView.minute;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.minute = this.testView.maxMinute + 1;
}, "Setting minute property to a value greater than maxMinute property value should throw.");
}
@@ -176,7 +176,7 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
this.testView.minute = 13;
this.testView.maxHour = this.testView.hour;
TKUnit.assertThrows(function() {
TKUnit.assertThrows(() => {
this.testView.maxMinute = this.testView.minute - 1;
}, "Setting maxMinute property to a value less than minute property value should throw.");
}

View File

@@ -14,6 +14,7 @@ import * as helper from "../../ui/helper";
import * as observable from "tns-core-modules/data/observable";
import * as bindable from "tns-core-modules/ui/core/bindable";
import * as definition from "./view-tests";
import { isIOS } from "tns-core-modules/platform";
export function test_eachDescendant() {
const test = function (views: Array<View>) {
@@ -273,8 +274,20 @@ class TestView extends Layout {
this.style["customCssProperty"] = value;
}
private _nativeView;
constructor(public name: string) {
super();
this._nativeView = this.nativeView;
this.nativeView = undefined;
}
public _createNativeView() {
if (isIOS) {
this.nativeView = this._nativeView;
return this._nativeView;
}
return super._createNativeView();
}
public toString() {
@@ -404,28 +417,55 @@ export function test_NativeSetter_called_when_add_and_remove() {
secondView.custom = "testViewValue";
helper.buildUIAndRunTest(firstView, () => {
TKUnit.assertEqual(secondView.cssPropCounter, 0);
TKUnit.assertEqual(secondView.viewPropCounter, 0);
TKUnit.assertEqual(secondView.cssPropCounter, 0, "1");
TKUnit.assertEqual(secondView.viewPropCounter, 0, "2");
// Add to visual tree
firstView.addChild(secondView);
TKUnit.assertEqual(secondView.cssPropCounter, 1);
TKUnit.assertEqual(secondView.viewPropCounter, 1);
secondView.cssPropCounter = 0;
secondView.viewPropCounter = 0;
TKUnit.assertEqual(secondView.cssPropCounter, 1, "3");
TKUnit.assertEqual(secondView.viewPropCounter, 1, "4");
// Set new value
secondView.customCssProperty = "test2";
secondView.custom = "test2";
TKUnit.assertEqual(secondView.cssPropCounter, 1);
TKUnit.assertEqual(secondView.viewPropCounter, 1);
secondView.cssPropCounter = 0;
secondView.viewPropCounter = 0;
TKUnit.assertEqual(secondView.cssPropCounter, 2, "5");
TKUnit.assertEqual(secondView.viewPropCounter, 2, "6");
// Remove from visual tree
firstView.removeChild(secondView);
TKUnit.assertEqual(secondView.cssPropCounter, 0);
TKUnit.assertEqual(secondView.viewPropCounter, 0);
TKUnit.assertEqual(secondView.cssPropCounter, 2, "7");
TKUnit.assertEqual(secondView.viewPropCounter, 2, "8");
});
};
export function test_NativeSetter_called_when_add_and_remove_and_recycled() {
const firstView = new TestView("firstView");
const secondView = new TestView("secondView");
secondView.recycleNativeView = !isIOS;
secondView.customCssProperty = "testCssValue";
secondView.custom = "testViewValue";
helper.buildUIAndRunTest(firstView, () => {
TKUnit.assertEqual(secondView.cssPropCounter, 0, "1");
TKUnit.assertEqual(secondView.viewPropCounter, 0, "2");
// Add to visual tree
firstView.addChild(secondView);
TKUnit.assertEqual(secondView.cssPropCounter, 1, "3");
TKUnit.assertEqual(secondView.viewPropCounter, 1, "4");
// Set new value
secondView.customCssProperty = "test2";
secondView.custom = "test2";
TKUnit.assertEqual(secondView.cssPropCounter, 2, "5");
TKUnit.assertEqual(secondView.viewPropCounter, 2, "6");
// Remove from visual tree
firstView.removeChild(secondView);
// we don't recycle nativeViews on iOS yet so reset is not called.
TKUnit.assertEqual(secondView.cssPropCounter, isIOS ? 2 : 3, "7");
TKUnit.assertEqual(secondView.viewPropCounter, isIOS ? 2 : 3, "8");
});
};