mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #2654 from NativeScript/raikov/tintColorTest
Added unit test that tests tintColor in Image class
This commit is contained in:
70
tests/.vscode/launch.json
vendored
Normal file
70
tests/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Sync on iOS",
|
||||||
|
"type": "nativescript",
|
||||||
|
"platform": "ios",
|
||||||
|
"request": "launch",
|
||||||
|
"appRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"diagnosticLogging": false,
|
||||||
|
"emulator": false,
|
||||||
|
"rebuild": false,
|
||||||
|
"syncAllFiles": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Launch on iOS",
|
||||||
|
"type": "nativescript",
|
||||||
|
"platform": "ios",
|
||||||
|
"request": "launch",
|
||||||
|
"appRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"diagnosticLogging": false,
|
||||||
|
"emulator": false,
|
||||||
|
"rebuild": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Attach on iOS",
|
||||||
|
"type": "nativescript",
|
||||||
|
"platform": "ios",
|
||||||
|
"request": "attach",
|
||||||
|
"appRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"diagnosticLogging": false,
|
||||||
|
"emulator": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sync on Android",
|
||||||
|
"type": "nativescript",
|
||||||
|
"platform": "android",
|
||||||
|
"request": "launch",
|
||||||
|
"appRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"diagnosticLogging": false,
|
||||||
|
"emulator": false,
|
||||||
|
"rebuild": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Launch on Android",
|
||||||
|
"type": "nativescript",
|
||||||
|
"platform": "android",
|
||||||
|
"request": "launch",
|
||||||
|
"appRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"diagnosticLogging": false,
|
||||||
|
"emulator": false,
|
||||||
|
"rebuild": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Attach on Android",
|
||||||
|
"type": "nativescript",
|
||||||
|
"platform": "android",
|
||||||
|
"request": "attach",
|
||||||
|
"appRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"diagnosticLogging": false,
|
||||||
|
"emulator": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -20,6 +20,7 @@ import helper = require("../helper");
|
|||||||
import ObservableModule = require("data/observable");
|
import ObservableModule = require("data/observable");
|
||||||
import enumsModule = require("ui/enums");
|
import enumsModule = require("ui/enums");
|
||||||
import fs = require("file-system");
|
import fs = require("file-system");
|
||||||
|
import color = require("color");
|
||||||
|
|
||||||
var imagePath = fs.path.join(__dirname, "../../logo.png");
|
var imagePath = fs.path.join(__dirname, "../../logo.png");
|
||||||
|
|
||||||
@ -357,3 +358,35 @@ export var test_DimensionsAreRoundedAfterScale = function() {
|
|||||||
TKUnit.assertEqual(image.getMeasuredWidth(), hostWidth, "Actual width is different from expected width.");
|
TKUnit.assertEqual(image.getMeasuredWidth(), hostWidth, "Actual width is different from expected width.");
|
||||||
TKUnit.assertEqual(image.getMeasuredHeight(), expectedHeight, "Actual height is different from expected height.");
|
TKUnit.assertEqual(image.getMeasuredHeight(), expectedHeight, "Actual height is different from expected height.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export var test_tintColor = function () {
|
||||||
|
var colorRed = new color.Color("red");
|
||||||
|
var image = new ImageModule.Image();
|
||||||
|
image.imageSource = ImageSourceModule.fromFile(imagePath);
|
||||||
|
|
||||||
|
var testFunc = function (views: Array<ViewModule.View>) {
|
||||||
|
var testImage = <ImageModule.Image> views[0];
|
||||||
|
|
||||||
|
if (image.android) {
|
||||||
|
var tintColor = testImage.android.getColorFilter();
|
||||||
|
TKUnit.assert(tintColor === null, "tintColor expected to be set to null");
|
||||||
|
}
|
||||||
|
else if (image.ios) {
|
||||||
|
var tintColor = testImage.ios.tintColor;
|
||||||
|
var imageColor = utils.ios.getColor(testImage.ios.tintColor);
|
||||||
|
TKUnit.assert(!imageColor.equals(colorRed), "imageColor expected to be different than tintColor");
|
||||||
|
}
|
||||||
|
|
||||||
|
image.color = colorRed;
|
||||||
|
|
||||||
|
if (image.android) {
|
||||||
|
TKUnit.assert(testImage.android.getColorFilter() !== null, "tintColor expected to be set to a nonnull value");
|
||||||
|
}
|
||||||
|
else if (image.ios) {
|
||||||
|
var imageColor = utils.ios.getColor(testImage.ios.tintColor);
|
||||||
|
TKUnit.assert(imageColor.equals(colorRed), "tintColor expected to be set to: " + colorRed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(image, testFunc);
|
||||||
|
}
|
Reference in New Issue
Block a user