mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Fixed Progress tests.
This commit is contained in:
@ -79,7 +79,7 @@ allTests["TAB-VIEW"] = require("./ui/tab-view/tab-view-tests");
|
|||||||
// allTests["IMAGE"] = require("./ui/image/image-tests");
|
// allTests["IMAGE"] = require("./ui/image/image-tests");
|
||||||
// allTests["SLIDER"] = require("./ui/slider/slider-tests");
|
// allTests["SLIDER"] = require("./ui/slider/slider-tests");
|
||||||
allTests["SWITCH"] = require("./ui/switch/switch-tests");
|
allTests["SWITCH"] = require("./ui/switch/switch-tests");
|
||||||
// allTests["PROGRESS"] = require("./ui/progress/progress-tests");
|
allTests["PROGRESS"] = require("./ui/progress/progress-tests");
|
||||||
// allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests");
|
// allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests");
|
||||||
// allTests["PAGE"] = require("./ui/page/page-tests");
|
// allTests["PAGE"] = require("./ui/page/page-tests");
|
||||||
// allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
|
// allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
|
||||||
|
@ -103,18 +103,24 @@ export function test_property_changed_event_when_setting_maxValue_with_adjust()
|
|||||||
function testAction(views: Array<viewModule.View>) {
|
function testAction(views: Array<viewModule.View>) {
|
||||||
var changedProperties = {};
|
var changedProperties = {};
|
||||||
var allChanges = 0;
|
var allChanges = 0;
|
||||||
progress.on(observable.Observable.propertyChangeEvent, function (data: observable.EventData) {
|
progress.on("valueChange", function (data: observable.EventData) {
|
||||||
|
allChanges++;
|
||||||
|
changedProperties[(<observable.PropertyChangeData>data).propertyName] = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
progress.on("maxValueChange", function (data: observable.EventData) {
|
||||||
allChanges++;
|
allChanges++;
|
||||||
changedProperties[(<observable.PropertyChangeData>data).propertyName] = true;
|
changedProperties[(<observable.PropertyChangeData>data).propertyName] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
progress.maxValue = 40;
|
progress.maxValue = 40;
|
||||||
progress.off(observable.Observable.propertyChangeEvent);
|
progress.off("valueChange");
|
||||||
|
progress.off("maxValueChange");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
TKUnit.assert(changedProperties["value"], "Property changed for 'value' not called.");
|
|
||||||
TKUnit.assert(changedProperties["maxValue"], "Property changed for 'maxValue' not called.");
|
TKUnit.assert(changedProperties["maxValue"], "Property changed for 'maxValue' not called.");
|
||||||
|
TKUnit.assert(changedProperties["value"], "Property changed for 'value' not called.");
|
||||||
TKUnit.assertEqual(allChanges, 2, "Property changed callbacks.");
|
TKUnit.assertEqual(allChanges, 2, "Property changed callbacks.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -204,7 +204,8 @@ 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] = coerceCallback(target, originalValue);
|
// need that to make coercing but also fire change events
|
||||||
|
this.set.call(target, originalValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set = function (this: T, value: U): void {
|
this.set = function (this: T, value: U): void {
|
||||||
@ -238,13 +239,13 @@ export class CoercibleProperty<T extends ViewBase, U> implements PropertyDescrip
|
|||||||
delete this[defaultValueKey];
|
delete this[defaultValueKey];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this[key] = value;
|
this[key] = unboxedValue;
|
||||||
if (setNativeValue) {
|
if (setNativeValue) {
|
||||||
if (!(defaultValueKey in this)) {
|
if (!(defaultValueKey in this)) {
|
||||||
this[defaultValueKey] = this[native];
|
this[defaultValueKey] = this[native];
|
||||||
}
|
}
|
||||||
|
|
||||||
this[native] = value;
|
this[native] = unboxedValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,11 +30,25 @@ export class ProgressBase extends View implements ProgressDefinition {
|
|||||||
/**
|
/**
|
||||||
* Represents the observable property backing the value property of each Progress instance.
|
* Represents the observable property backing the value property of each Progress instance.
|
||||||
*/
|
*/
|
||||||
export const valueProperty = new CoercibleProperty<ProgressBase, number>({ name: "value", defaultValue: 0, coerceValue: (t, v) => v < 0 ? 0 : Math.min(v, t.maxValue) });
|
export const valueProperty = new CoercibleProperty<ProgressBase, number>({
|
||||||
|
name: "value",
|
||||||
|
defaultValue: 0,
|
||||||
|
coerceValue: (t, v) => {
|
||||||
|
return v < 0 ? 0 : Math.min(v, t.maxValue)
|
||||||
|
},
|
||||||
|
valueConverter: (v) => parseInt(v)
|
||||||
|
});
|
||||||
valueProperty.register(ProgressBase);
|
valueProperty.register(ProgressBase);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the observable property backing the maxValue property of each Progress instance.
|
* Represents the observable property backing the maxValue property of each Progress instance.
|
||||||
*/
|
*/
|
||||||
export const maxValueProperty = new Property<ProgressBase, number>({ name: "maxValue", defaultValue: 100, valueChanged: (target, oldValue, newValue) => valueProperty.coerce(target) });
|
export const maxValueProperty = new Property<ProgressBase, number>({
|
||||||
|
name: "maxValue",
|
||||||
|
defaultValue: 100,
|
||||||
|
valueChanged: (target, oldValue, newValue) => {
|
||||||
|
valueProperty.coerce(target);
|
||||||
|
},
|
||||||
|
valueConverter: (v) => parseInt(v)
|
||||||
|
});
|
||||||
maxValueProperty.register(ProgressBase);
|
maxValueProperty.register(ProgressBase);
|
@ -18,6 +18,10 @@ export class Progress extends ProgressBase {
|
|||||||
return this._android;
|
return this._android;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get nativeView(): android.widget.ProgressBar {
|
||||||
|
return this._android;
|
||||||
|
}
|
||||||
|
|
||||||
get [valueProperty.native](): number {
|
get [valueProperty.native](): number {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,14 @@ export class Progress extends ProgressBase {
|
|||||||
return this._ios;
|
return this._ios;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get nativeView(): UIProgressView {
|
||||||
|
return this._ios;
|
||||||
|
}
|
||||||
|
|
||||||
|
get _nativeView(): UIProgressView {
|
||||||
|
return this._ios;
|
||||||
|
}
|
||||||
|
|
||||||
get [valueProperty.native](): number {
|
get [valueProperty.native](): number {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user