mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
test: additional coverage for backgroundColor and borderColor
This commit is contained in:
@ -904,6 +904,12 @@ function _createLabelWithBorder(): View {
|
|||||||
return lbl;
|
return lbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _createBackgroundColorView(): View {
|
||||||
|
const lbl = new Label();
|
||||||
|
lbl.backgroundColor = new Color('#FFFF00');
|
||||||
|
return lbl;
|
||||||
|
}
|
||||||
|
|
||||||
export function testIsVisible() {
|
export function testIsVisible() {
|
||||||
const lbl = new Label();
|
const lbl = new Label();
|
||||||
|
|
||||||
@ -939,6 +945,23 @@ export function testBackgroundColor() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function testBackgroundBorderColor() {
|
||||||
|
helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array<View>) {
|
||||||
|
const lbl = views[0];
|
||||||
|
helper.waitUntilLayoutReady(lbl);
|
||||||
|
TKUnit.assertEqual(definition.checkNativeBackgroundColor(lbl), true, 'BackgroundColor not applied correctly!');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function testSetAndRemoveBackgroundColor() {
|
||||||
|
helper.buildUIAndRunTest(_createBackgroundColorView(), function (views: Array<View>) {
|
||||||
|
const lbl = views[0];
|
||||||
|
helper.waitUntilLayoutReady(lbl);
|
||||||
|
TKUnit.assertEqual(definition.checkNativeBackgroundColor(lbl), true, 'BackgroundColor not applied correctly!');
|
||||||
|
lbl.backgroundColor = null;
|
||||||
|
TKUnit.assertEqual(definition.checkNativeBackgroundColor(lbl), true, 'BackgroundColor not applied correctly!');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function testBackgroundImage() {
|
export function testBackgroundImage() {
|
||||||
const lbl = _createLabelWithBorder();
|
const lbl = _createLabelWithBorder();
|
||||||
lbl.className = 'myClass';
|
lbl.className = 'myClass';
|
||||||
|
@ -288,9 +288,14 @@ export function getUniformNativeCornerRadius(v: View): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function checkNativeBackgroundColor(v: View): boolean {
|
export function checkNativeBackgroundColor(v: View): boolean {
|
||||||
const bkg = <org.nativescript.widgets.BorderDrawable>(<android.view.View>v.android).getBackground();
|
const drawable = (<android.view.View>v.android).getBackground();
|
||||||
|
if (drawable instanceof org.nativescript.widgets.BorderDrawable) {
|
||||||
return v.backgroundColor && bkg && bkg.getBackgroundColor() === (<Color>v.backgroundColor).android;
|
return v.backgroundColor && drawable && drawable.getBackgroundColor() === (<Color>v.backgroundColor).android;
|
||||||
|
} else if (drawable instanceof android.graphics.drawable.ColorDrawable) {
|
||||||
|
// "no color when has a drawable is transparent => -1"
|
||||||
|
return drawable.getColor() === ((<Color>v.backgroundColor)?.android || -1);
|
||||||
|
}
|
||||||
|
return !v.backgroundColor && !drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkNativeBackgroundImage(v: View): boolean {
|
export function checkNativeBackgroundImage(v: View): boolean {
|
||||||
|
@ -36,12 +36,19 @@ export function getUniformNativeCornerRadius(v: View): number {
|
|||||||
export function checkNativeBackgroundColor(v: View): boolean {
|
export function checkNativeBackgroundColor(v: View): boolean {
|
||||||
if (v.ios instanceof UILabel) {
|
if (v.ios instanceof UILabel) {
|
||||||
var cgColor1 = (<UILabel>v.ios).layer.backgroundColor;
|
var cgColor1 = (<UILabel>v.ios).layer.backgroundColor;
|
||||||
var cgColor2 = (<UIColor>(<Color>v.backgroundColor).ios).CGColor;
|
var cgColor2 = (<UIColor>(<Color>v.backgroundColor)?.ios)?.CGColor;
|
||||||
|
|
||||||
return v.backgroundColor && !!CGColorEqualToColor(cgColor1, cgColor2);
|
if (v.backgroundColor) {
|
||||||
|
return v.backgroundColor && !!CGColorEqualToColor(cgColor1, cgColor2);
|
||||||
|
} else {
|
||||||
|
return !cgColor1 && !cgColor2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (v.backgroundColor) {
|
||||||
|
return (<UIView>v.ios)?.backgroundColor.isEqual((<Color>v.backgroundColor)?.ios);
|
||||||
|
} else {
|
||||||
|
return !(<UIView>v.ios).backgroundColor && !v.backgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return v.backgroundColor && (<UIView>v.ios).backgroundColor.isEqual((<Color>v.backgroundColor).ios);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkNativeBackgroundImage(v: View): boolean {
|
export function checkNativeBackgroundImage(v: View): boolean {
|
||||||
|
Reference in New Issue
Block a user