From 5a86a60b61d35b2c95045bca64b29a46d8b38308 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Wed, 23 Nov 2022 21:24:14 -0800 Subject: [PATCH] test: additional coverage for backgroundColor and borderColor --- .../src/ui/view/view-tests-common.ts | 23 +++++++++++++++++++ .../src/ui/view/view-tests.android.ts | 11 ++++++--- apps/automated/src/ui/view/view-tests.ios.ts | 15 ++++++++---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/apps/automated/src/ui/view/view-tests-common.ts b/apps/automated/src/ui/view/view-tests-common.ts index 803cd3538..48fdebbde 100644 --- a/apps/automated/src/ui/view/view-tests-common.ts +++ b/apps/automated/src/ui/view/view-tests-common.ts @@ -904,6 +904,12 @@ function _createLabelWithBorder(): View { return lbl; } +function _createBackgroundColorView(): View { + const lbl = new Label(); + lbl.backgroundColor = new Color('#FFFF00'); + return lbl; +} + export function testIsVisible() { const lbl = new Label(); @@ -939,6 +945,23 @@ export function testBackgroundColor() { }); } +export function testBackgroundBorderColor() { + helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { + 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) { + 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() { const lbl = _createLabelWithBorder(); lbl.className = 'myClass'; diff --git a/apps/automated/src/ui/view/view-tests.android.ts b/apps/automated/src/ui/view/view-tests.android.ts index a4b10efc1..78385921d 100644 --- a/apps/automated/src/ui/view/view-tests.android.ts +++ b/apps/automated/src/ui/view/view-tests.android.ts @@ -288,9 +288,14 @@ export function getUniformNativeCornerRadius(v: View): number { } export function checkNativeBackgroundColor(v: View): boolean { - const bkg = (v.android).getBackground(); - - return v.backgroundColor && bkg && bkg.getBackgroundColor() === (v.backgroundColor).android; + const drawable = (v.android).getBackground(); + if (drawable instanceof org.nativescript.widgets.BorderDrawable) { + return v.backgroundColor && drawable && drawable.getBackgroundColor() === (v.backgroundColor).android; + } else if (drawable instanceof android.graphics.drawable.ColorDrawable) { + // "no color when has a drawable is transparent => -1" + return drawable.getColor() === ((v.backgroundColor)?.android || -1); + } + return !v.backgroundColor && !drawable; } export function checkNativeBackgroundImage(v: View): boolean { diff --git a/apps/automated/src/ui/view/view-tests.ios.ts b/apps/automated/src/ui/view/view-tests.ios.ts index 7e4463323..d8e025cd7 100644 --- a/apps/automated/src/ui/view/view-tests.ios.ts +++ b/apps/automated/src/ui/view/view-tests.ios.ts @@ -36,12 +36,19 @@ export function getUniformNativeCornerRadius(v: View): number { export function checkNativeBackgroundColor(v: View): boolean { if (v.ios instanceof UILabel) { var cgColor1 = (v.ios).layer.backgroundColor; - var cgColor2 = ((v.backgroundColor).ios).CGColor; + var cgColor2 = ((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 (v.ios)?.backgroundColor.isEqual((v.backgroundColor)?.ios); + } else { + return !(v.ios).backgroundColor && !v.backgroundColor; } - - return v.backgroundColor && (v.ios).backgroundColor.isEqual((v.backgroundColor).ios); } export function checkNativeBackgroundImage(v: View): boolean {