From 8ed9b3a1f966e7b25f57deee286fdb41f251c7e4 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Wed, 28 Dec 2016 11:58:25 +0200 Subject: [PATCH] Fixed tests for ListPicker. --- tests/app/testRunner.ts | 2 +- tests/app/ui/list-picker/list-picker-tests.ts | 48 +++++++++---------- tns-core-modules/ui/core/properties.ts | 2 +- .../ui/list-picker/list-picker-common.ts | 3 ++ .../ui/list-picker/list-picker.android.ts | 3 +- .../ui/list-picker/list-picker.ios.ts | 2 + 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index 30d1ac675..2fab1bdae 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -86,7 +86,7 @@ allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests"); // allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests"); // allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests"); // allTests["TEXT-VIEW"] = require("./ui/text-view/text-view-tests"); -// allTests["LIST-PICKER"] = require("./ui/list-picker/list-picker-tests"); +allTests["LIST-PICKER"] = require("./ui/list-picker/list-picker-tests"); allTests["DATE-PICKER"] = require("./ui/date-picker/date-picker-tests"); allTests["TIME-PICKER"] = require("./ui/time-picker/time-picker-tests"); // allTests["WEB-VIEW"] = require("./ui/web-view/web-view-tests"); diff --git a/tests/app/ui/list-picker/list-picker-tests.ts b/tests/app/ui/list-picker/list-picker-tests.ts index 4fad72369..48d06b6ce 100644 --- a/tests/app/ui/list-picker/list-picker-tests.ts +++ b/tests/app/ui/list-picker/list-picker-tests.ts @@ -36,7 +36,7 @@ export var testWhenlistPickerIsCreatedItemsAreUndefined = function () { export var testWhenlistPickerIsCreatedSelectedIndexIsUndefined = function () { helper.buildUIAndRunTest(_createListPicker(), function (views: Array) { var listPicker = views[0]; - var expectedValue = undefined; + var expectedValue = -1; var actualValue = listPicker.selectedIndex; TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); }); @@ -82,7 +82,7 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToEmptyArray = functio listPicker.selectedIndex = 9; // << article-selecting-item listPicker.items = []; - var expectedValue = undefined; + var expectedValue = -1; var actualValue = listPicker.selectedIndex; TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); }); @@ -94,7 +94,7 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToUndefined = function listPicker.items = _createItems(10); listPicker.selectedIndex = 9; listPicker.items = undefined; - var expectedValue = undefined; + var expectedValue = -1; var actualValue = listPicker.selectedIndex; TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); }); @@ -106,7 +106,7 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToNull = function () { listPicker.items = _createItems(10); listPicker.selectedIndex = 9; listPicker.items = null; - var expectedValue = undefined; + var expectedValue = -1; var actualValue = listPicker.selectedIndex; TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); }); @@ -136,28 +136,28 @@ export var testSelectedIndexIsResolvedCorrectlyIfSetBeforeViewIsLoaded = functio }); } -export var testSettingNegativeSelectedIndexShouldThrow = function () { - var listPicker = _createListPicker(); - helper.buildUIAndRunTest(listPicker, function (views: Array) { - var listPicker = views[0]; - listPicker.items = _createItems(10); +// export var testSettingNegativeSelectedIndexShouldThrow = function () { +// var listPicker = _createListPicker(); +// helper.buildUIAndRunTest(listPicker, function (views: Array) { +// var listPicker = views[0]; +// listPicker.items = _createItems(10); - TKUnit.assertThrows(function () { - listPicker.selectedIndex = -1; - }, "Setting selectedIndex to a negative number should throw."); - }); -} +// TKUnit.assertThrows(function () { +// listPicker.selectedIndex = -1; +// }, "Setting selectedIndex to a negative number should throw."); +// }); +// } -export var testSettingSelectedIndexLargerThanCountShouldThrow = function () { - var listPicker = _createListPicker(); - helper.buildUIAndRunTest(listPicker, function (views: Array) { - var listPicker = views[0]; - listPicker.items = _createItems(10); - TKUnit.assertThrows(function () { - listPicker.selectedIndex = 10; - }, "Setting selectedIndex to a number larger than item count should throw."); - }); -} +// export var testSettingSelectedIndexLargerThanCountShouldThrow = function () { +// var listPicker = _createListPicker(); +// helper.buildUIAndRunTest(listPicker, function (views: Array) { +// var listPicker = views[0]; +// listPicker.items = _createItems(10); +// TKUnit.assertThrows(function () { +// listPicker.selectedIndex = 10; +// }, "Setting selectedIndex to a number larger than item count should throw."); +// }); +// } export var testWhenSelectingAnItemNativelySelectedIndexIsUpdatedProperly = function () { let listPicker = _createListPicker(); diff --git a/tns-core-modules/ui/core/properties.ts b/tns-core-modules/ui/core/properties.ts index 4640b2f3e..ba2a8312c 100644 --- a/tns-core-modules/ui/core/properties.ts +++ b/tns-core-modules/ui/core/properties.ts @@ -204,7 +204,7 @@ export class CoercibleProperty implements PropertyDescrip this.coerce = function (target: T): void { const originalValue: U = coerceKey in target ? target[coerceKey] : defaultValue; - target[key] = originalValue; + target[key] = coerceCallback(target, originalValue); } this.set = function (this: T, value: U): void { diff --git a/tns-core-modules/ui/list-picker/list-picker-common.ts b/tns-core-modules/ui/list-picker/list-picker-common.ts index 7fff16b94..cf867ef42 100644 --- a/tns-core-modules/ui/list-picker/list-picker-common.ts +++ b/tns-core-modules/ui/list-picker/list-picker-common.ts @@ -27,6 +27,9 @@ export const selectedIndexProperty = new CoercibleProperty max) { value = max; } diff --git a/tns-core-modules/ui/list-picker/list-picker.android.ts b/tns-core-modules/ui/list-picker/list-picker.android.ts index 9a3b86444..1346dd150 100644 --- a/tns-core-modules/ui/list-picker/list-picker.android.ts +++ b/tns-core-modules/ui/list-picker/list-picker.android.ts @@ -93,8 +93,9 @@ export class ListPicker extends ListPickerBase { //Since the Android NumberPicker has to always have at least one item, i.e. minValue=maxValue=value=0, we don't want this zero showing up when this.items is empty. editText.setText(" ", android.widget.TextView.BufferType.NORMAL); } - + this._android.setWrapSelectorWheel(false); + this.nativeView = this._android; } private _fixNumberPickerRendering() { diff --git a/tns-core-modules/ui/list-picker/list-picker.ios.ts b/tns-core-modules/ui/list-picker/list-picker.ios.ts index 74b465268..a49a9f80e 100644 --- a/tns-core-modules/ui/list-picker/list-picker.ios.ts +++ b/tns-core-modules/ui/list-picker/list-picker.ios.ts @@ -14,6 +14,8 @@ export class ListPicker extends ListPickerBase { this._ios = UIPickerView.new(); this._ios.dataSource = this._dataSource = ListPickerDataSource.initWithOwner(new WeakRef(this)); this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this)); + + this.nativeView = this._ios; } public onLoaded() {