mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
tests added
This commit is contained in:
@ -3,6 +3,8 @@ import helper = require("../helper");
|
|||||||
import viewModule = require("ui/core/view");
|
import viewModule = require("ui/core/view");
|
||||||
import bindable = require("ui/core/bindable");
|
import bindable = require("ui/core/bindable");
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
|
import color = require("color");
|
||||||
|
import platform = require("platform");
|
||||||
// <snippet module="ui/switch" title="switch">
|
// <snippet module="ui/switch" title="switch">
|
||||||
// # Switch
|
// # Switch
|
||||||
// Using a switch requires the Switch module.
|
// Using a switch requires the Switch module.
|
||||||
@ -51,6 +53,31 @@ export function test_default_native_values() {
|
|||||||
helper.buildUIAndRunTest(mySwitch, testAction);
|
helper.buildUIAndRunTest(mySwitch, testAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uncomment this when find way to check android Drawable color set by setColorFilter() method.
|
||||||
|
if (platform.device.os === platform.platformNames.ios) {
|
||||||
|
exports.test_set_color = function () {
|
||||||
|
var mySwitch = new switchModule.Switch();
|
||||||
|
mySwitch.color = new color.Color("red");
|
||||||
|
|
||||||
|
function testAction(views: Array<viewModule.View>) {
|
||||||
|
TKUnit.assert(mySwitch.color.ios.isEqual(mySwitch.ios.thumbTintColor), "mySwitch.color");
|
||||||
|
};
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(mySwitch, testAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.test_set_backgroundColor = function () {
|
||||||
|
var mySwitch = new switchModule.Switch();
|
||||||
|
mySwitch.backgroundColor = new color.Color("red");
|
||||||
|
|
||||||
|
function testAction(views: Array<viewModule.View>) {
|
||||||
|
TKUnit.assert(CGColorEqualToColor(mySwitch.backgroundColor.ios.CGColor, mySwitch.ios.onTintColor.CGColor), "mySwitch.color");
|
||||||
|
};
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(mySwitch, testAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function test_set_TNS_checked_updates_native_checked() {
|
export function test_set_TNS_checked_updates_native_checked() {
|
||||||
var mySwitch = new switchModule.Switch();
|
var mySwitch = new switchModule.Switch();
|
||||||
function testAction(views: Array<viewModule.View>) {
|
function testAction(views: Array<viewModule.View>) {
|
||||||
|
@ -442,12 +442,12 @@ export class ProgressStyler implements definition.stylers.Styler {
|
|||||||
export class SwitchStyler implements definition.stylers.Styler {
|
export class SwitchStyler implements definition.stylers.Styler {
|
||||||
private static setColorProperty(view: view.View, newValue: any) {
|
private static setColorProperty(view: view.View, newValue: any) {
|
||||||
var sw = <UISwitch>view.ios;
|
var sw = <UISwitch>view.ios;
|
||||||
sw.thumbTintColor = UIColor.alloc().initWithCGColor((<UIColor>newValue).CGColor);
|
sw.thumbTintColor = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static resetColorProperty(view: view.View, nativeValue: any) {
|
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||||
var sw = <UISwitch>view.ios;
|
var sw = <UISwitch>view.ios;
|
||||||
sw.thumbTintColor = UIColor.alloc().initWithCGColor((<UIColor>nativeValue).CGColor);
|
sw.thumbTintColor = nativeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getNativeColorValue(view: view.View): any {
|
private static getNativeColorValue(view: view.View): any {
|
||||||
@ -457,17 +457,17 @@ export class SwitchStyler implements definition.stylers.Styler {
|
|||||||
|
|
||||||
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
||||||
var sw = <UISwitch>view.ios;
|
var sw = <UISwitch>view.ios;
|
||||||
sw.tintColor = UIColor.alloc().initWithCGColor((<UIColor>newValue).CGColor);
|
sw.onTintColor = view.backgroundColor.ios;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
|
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
|
||||||
var sw = <UISwitch>view.ios;
|
var sw = <UISwitch>view.ios;
|
||||||
sw.tintColor = UIColor.alloc().initWithCGColor((<UIColor>nativeValue).CGColor);
|
sw.onTintColor = nativeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getBackgroundColorProperty(view: view.View): any {
|
private static getBackgroundColorProperty(view: view.View): any {
|
||||||
var sw = <UISwitch>view.ios;
|
var sw = <UISwitch>view.ios;
|
||||||
return sw.tintColor;
|
return sw.onTintColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static registerHandlers() {
|
public static registerHandlers() {
|
||||||
|
Reference in New Issue
Block a user