mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Fixed tests for ListPicker.
This commit is contained in:
@ -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");
|
||||
|
@ -36,7 +36,7 @@ export var testWhenlistPickerIsCreatedItemsAreUndefined = function () {
|
||||
export var testWhenlistPickerIsCreatedSelectedIndexIsUndefined = function () {
|
||||
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<viewModule.View>) {
|
||||
var listPicker = <listPickerModule.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<viewModule.View>) {
|
||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
||||
listPicker.items = _createItems(10);
|
||||
// export var testSettingNegativeSelectedIndexShouldThrow = function () {
|
||||
// var listPicker = _createListPicker();
|
||||
// helper.buildUIAndRunTest(listPicker, function (views: Array<viewModule.View>) {
|
||||
// var listPicker = <listPickerModule.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<viewModule.View>) {
|
||||
var listPicker = <listPickerModule.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<viewModule.View>) {
|
||||
// var listPicker = <listPickerModule.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();
|
||||
|
@ -204,7 +204,7 @@ export class CoercibleProperty<T extends ViewBase, U> 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 {
|
||||
|
@ -27,6 +27,9 @@ export const selectedIndexProperty = new CoercibleProperty<ListPickerBase, numbe
|
||||
let items = target.items;
|
||||
if (items) {
|
||||
let max = items.length - 1;
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
}
|
||||
if (value > max) {
|
||||
value = max;
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
Reference in New Issue
Block a user