mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +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["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests");
|
||||||
// allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests");
|
// allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests");
|
||||||
// allTests["TEXT-VIEW"] = require("./ui/text-view/text-view-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["DATE-PICKER"] = require("./ui/date-picker/date-picker-tests");
|
||||||
allTests["TIME-PICKER"] = require("./ui/time-picker/time-picker-tests");
|
allTests["TIME-PICKER"] = require("./ui/time-picker/time-picker-tests");
|
||||||
// allTests["WEB-VIEW"] = require("./ui/web-view/web-view-tests");
|
// allTests["WEB-VIEW"] = require("./ui/web-view/web-view-tests");
|
||||||
|
@ -36,7 +36,7 @@ export var testWhenlistPickerIsCreatedItemsAreUndefined = function () {
|
|||||||
export var testWhenlistPickerIsCreatedSelectedIndexIsUndefined = function () {
|
export var testWhenlistPickerIsCreatedSelectedIndexIsUndefined = function () {
|
||||||
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<viewModule.View>) {
|
||||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
var listPicker = <listPickerModule.ListPicker>views[0];
|
||||||
var expectedValue = undefined;
|
var expectedValue = -1;
|
||||||
var actualValue = listPicker.selectedIndex;
|
var actualValue = listPicker.selectedIndex;
|
||||||
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
});
|
});
|
||||||
@ -82,7 +82,7 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToEmptyArray = functio
|
|||||||
listPicker.selectedIndex = 9;
|
listPicker.selectedIndex = 9;
|
||||||
// << article-selecting-item
|
// << article-selecting-item
|
||||||
listPicker.items = [];
|
listPicker.items = [];
|
||||||
var expectedValue = undefined;
|
var expectedValue = -1;
|
||||||
var actualValue = listPicker.selectedIndex;
|
var actualValue = listPicker.selectedIndex;
|
||||||
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
});
|
});
|
||||||
@ -94,7 +94,7 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToUndefined = function
|
|||||||
listPicker.items = _createItems(10);
|
listPicker.items = _createItems(10);
|
||||||
listPicker.selectedIndex = 9;
|
listPicker.selectedIndex = 9;
|
||||||
listPicker.items = undefined;
|
listPicker.items = undefined;
|
||||||
var expectedValue = undefined;
|
var expectedValue = -1;
|
||||||
var actualValue = listPicker.selectedIndex;
|
var actualValue = listPicker.selectedIndex;
|
||||||
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
});
|
});
|
||||||
@ -106,7 +106,7 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToNull = function () {
|
|||||||
listPicker.items = _createItems(10);
|
listPicker.items = _createItems(10);
|
||||||
listPicker.selectedIndex = 9;
|
listPicker.selectedIndex = 9;
|
||||||
listPicker.items = null;
|
listPicker.items = null;
|
||||||
var expectedValue = undefined;
|
var expectedValue = -1;
|
||||||
var actualValue = listPicker.selectedIndex;
|
var actualValue = listPicker.selectedIndex;
|
||||||
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
});
|
});
|
||||||
@ -136,28 +136,28 @@ export var testSelectedIndexIsResolvedCorrectlyIfSetBeforeViewIsLoaded = functio
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export var testSettingNegativeSelectedIndexShouldThrow = function () {
|
// export var testSettingNegativeSelectedIndexShouldThrow = function () {
|
||||||
var listPicker = _createListPicker();
|
// var listPicker = _createListPicker();
|
||||||
helper.buildUIAndRunTest(listPicker, function (views: Array<viewModule.View>) {
|
// helper.buildUIAndRunTest(listPicker, function (views: Array<viewModule.View>) {
|
||||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
// var listPicker = <listPickerModule.ListPicker>views[0];
|
||||||
listPicker.items = _createItems(10);
|
// listPicker.items = _createItems(10);
|
||||||
|
|
||||||
TKUnit.assertThrows(function () {
|
// TKUnit.assertThrows(function () {
|
||||||
listPicker.selectedIndex = -1;
|
// listPicker.selectedIndex = -1;
|
||||||
}, "Setting selectedIndex to a negative number should throw.");
|
// }, "Setting selectedIndex to a negative number should throw.");
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
export var testSettingSelectedIndexLargerThanCountShouldThrow = function () {
|
// export var testSettingSelectedIndexLargerThanCountShouldThrow = function () {
|
||||||
var listPicker = _createListPicker();
|
// var listPicker = _createListPicker();
|
||||||
helper.buildUIAndRunTest(listPicker, function (views: Array<viewModule.View>) {
|
// helper.buildUIAndRunTest(listPicker, function (views: Array<viewModule.View>) {
|
||||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
// var listPicker = <listPickerModule.ListPicker>views[0];
|
||||||
listPicker.items = _createItems(10);
|
// listPicker.items = _createItems(10);
|
||||||
TKUnit.assertThrows(function () {
|
// TKUnit.assertThrows(function () {
|
||||||
listPicker.selectedIndex = 10;
|
// listPicker.selectedIndex = 10;
|
||||||
}, "Setting selectedIndex to a number larger than item count should throw.");
|
// }, "Setting selectedIndex to a number larger than item count should throw.");
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
export var testWhenSelectingAnItemNativelySelectedIndexIsUpdatedProperly = function () {
|
export var testWhenSelectingAnItemNativelySelectedIndexIsUpdatedProperly = function () {
|
||||||
let listPicker = _createListPicker();
|
let listPicker = _createListPicker();
|
||||||
|
@ -204,7 +204,7 @@ export class CoercibleProperty<T extends ViewBase, U> implements PropertyDescrip
|
|||||||
|
|
||||||
this.coerce = function (target: T): void {
|
this.coerce = function (target: T): void {
|
||||||
const originalValue: U = coerceKey in target ? target[coerceKey] : defaultValue;
|
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 {
|
this.set = function (this: T, value: U): void {
|
||||||
|
@ -27,6 +27,9 @@ export const selectedIndexProperty = new CoercibleProperty<ListPickerBase, numbe
|
|||||||
let items = target.items;
|
let items = target.items;
|
||||||
if (items) {
|
if (items) {
|
||||||
let max = items.length - 1;
|
let max = items.length - 1;
|
||||||
|
if (value < 0) {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
if (value > max) {
|
if (value > max) {
|
||||||
value = max;
|
value = max;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ export class ListPicker extends ListPickerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._android.setWrapSelectorWheel(false);
|
this._android.setWrapSelectorWheel(false);
|
||||||
|
this.nativeView = this._android;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _fixNumberPickerRendering() {
|
private _fixNumberPickerRendering() {
|
||||||
|
@ -14,6 +14,8 @@ export class ListPicker extends ListPickerBase {
|
|||||||
this._ios = UIPickerView.new();
|
this._ios = UIPickerView.new();
|
||||||
this._ios.dataSource = this._dataSource = ListPickerDataSource.initWithOwner(new WeakRef(this));
|
this._ios.dataSource = this._dataSource = ListPickerDataSource.initWithOwner(new WeakRef(this));
|
||||||
this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this));
|
this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this));
|
||||||
|
|
||||||
|
this.nativeView = this._ios;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onLoaded() {
|
public onLoaded() {
|
||||||
|
Reference in New Issue
Block a user