From 3a0cc32ff240f10cf67261517ab466ae8705a6f9 Mon Sep 17 00:00:00 2001 From: hshristov Date: Fri, 28 Aug 2015 16:57:00 +0300 Subject: [PATCH] Fix for Button padding in android. Fix for types - isString and isNumber. Modified several tests to pass on VS Emulator for Android. Fix page background to be applied in onLoaded method. Enhancements for dependency-observable - it is now possible to add defaultValueGetter function to extract default value for a property. It can also be cached or not. Remove android_constants because they are per theme and we cannot use them safely. Fix for SearchBar reseColorProperty method. --- CrossPlatformModules.csproj | 11 +- apps/tests/pages/fonts-test.ts | 1 - .../tests/ui/scroll-view/scroll-view-tests.ts | 24 +- apps/tests/ui/search-bar/search-bar-tests.ts | 2 +- apps/tests/ui/view/view-tests-common.ts | 35 +- apps/ui-tests-app/pages/text/button.ts | 8 +- apps/ui-tests-app/pages/text/button.xml | 22 +- apps/ui-tests-app/pages/text/label.ts | 1 - apps/ui-tests-app/pages/text/text-field.ts | 1 - apps/ui-tests-app/pages/text/text-view.ts | 1 - ui/core/dependency-observable.d.ts | 15 + ui/core/dependency-observable.ts | 19 + ui/page/page-common.ts | 6 +- ui/styling/css-selector.ts | 22 +- ui/styling/style-property.d.ts | 9 + ui/styling/style-property.ts | 20 +- ui/styling/style.ts | 396 ++++++++++-------- ui/styling/stylers.android.ts | 67 +-- utils/android_constants.ts | 9 - utils/types.ts | 4 +- 20 files changed, 398 insertions(+), 275 deletions(-) delete mode 100644 utils/android_constants.ts diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index 1f8bb0a24..4f26631e7 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -369,7 +369,9 @@ - + + button.xml + webview.xml @@ -795,7 +797,6 @@ - utils.d.ts @@ -1379,7 +1380,9 @@ styling.d.ts - + + style-property.d.ts + @@ -1947,7 +1950,7 @@ False - + \ No newline at end of file diff --git a/apps/tests/pages/fonts-test.ts b/apps/tests/pages/fonts-test.ts index 7b5b18e8b..14d5ba0ba 100644 --- a/apps/tests/pages/fonts-test.ts +++ b/apps/tests/pages/fonts-test.ts @@ -10,7 +10,6 @@ export function buttonTap(args) { v.style._resetValue(style.fontSizeProperty); v.style._resetValue(style.fontStyleProperty); v.style._resetValue(style.fontWeightProperty); - v.style._resetValue(style.fontProperty); v.style._resetValue(style.colorProperty); v.style._resetValue(style.textAlignmentProperty); diff --git a/apps/tests/ui/scroll-view/scroll-view-tests.ts b/apps/tests/ui/scroll-view/scroll-view-tests.ts index 26ffbf786..fa84a5865 100644 --- a/apps/tests/ui/scroll-view/scroll-view-tests.ts +++ b/apps/tests/ui/scroll-view/scroll-view-tests.ts @@ -124,7 +124,7 @@ export function test_scrollabeHeight_vertical_orientation_when_content_is_big() scrollView.content = btn; waitForLayout(); - TKUnit.assertEqual(scrollView.scrollableHeight, 200, "scrollView.scrollableHeight"); + TKUnit.assertAreClose(scrollView.scrollableHeight, 200, 0.4, "scrollView.scrollableHeight"); TKUnit.assertEqual(scrollView.scrollableWidth, 0, "scrollView.scrollableWidth"); } @@ -157,7 +157,7 @@ export function test_scrollabeWidth_horizontal_orientation_when_content_is_big() waitForLayout(); TKUnit.assertEqual(scrollView.scrollableHeight, 0, "scrollView.scrollableHeight"); - TKUnit.assertEqual(scrollView.scrollableWidth, 300, "scrollView.scrollableWidth"); + TKUnit.assertAreClose(scrollView.scrollableWidth, 300, 0.4, "scrollView.scrollableWidth"); } export function test_scrollToVerticalOffset_no_animation() { @@ -174,7 +174,7 @@ export function test_scrollToVerticalOffset_no_animation() { TKUnit.assertEqual(scrollView.verticalOffset, 0, "scrollView.verticalOffset"); scrollView.scrollToVerticalOffset(100, false); - TKUnit.assertEqual(scrollView.verticalOffset, 100, "scrollView.verticalOffset"); + TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset"); } export function test_scrollToVerticalOffset_with_animation() { @@ -198,7 +198,7 @@ export function test_scrollToVerticalOffset_with_animation() { TKUnit.waitUntilReady(() => { return scrollView.verticalOffset === 100 }, ASYNC); // The scrolling animation should be finished by now - TKUnit.assertEqual(scrollView.verticalOffset, 100, "scrollView.verticalOffset"); + TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset"); } export function test_scrollToHorizontalOffset_no_animation() { @@ -215,7 +215,7 @@ export function test_scrollToHorizontalOffset_no_animation() { TKUnit.assertEqual(scrollView.horizontalOffset, 0, "scrollView.horizontalOffset"); scrollView.scrollToHorizontalOffset(100, false); - TKUnit.assertEqual(scrollView.horizontalOffset, 100, "scrollView.horizontalOffset"); + TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset"); } export function test_scrollToHorizontalOffset_with_animation() { @@ -239,7 +239,7 @@ export function test_scrollToHorizontalOffset_with_animation() { TKUnit.waitUntilReady(() => { return scrollView.horizontalOffset === 100 }, ASYNC); // The scrolling animation should be finished by now - TKUnit.assertEqual(scrollView.horizontalOffset, 100, "scrollView.horizontalOffset"); + TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset"); } export function test_scrollView_persistsState_vertical() { @@ -256,7 +256,7 @@ export function test_scrollView_persistsState_vertical() { scrollView.scrollToVerticalOffset(100, false); - TKUnit.assertEqual(scrollView.verticalOffset, 100, "scrollView.verticalOffset before navigation"); + TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset before navigation"); helper.do_PageTest_WithButton((t) => { // Just navigate forward and back. @@ -264,11 +264,11 @@ export function test_scrollView_persistsState_vertical() { // Wait for the page to reload. TKUnit.waitUntilReady(function () { - return scrollView.verticalOffset === 100; + return Math.abs(scrollView.verticalOffset - 100) < 0.1; }, ASYNC); // Check verticalOffset after navigation - TKUnit.assertEqual(scrollView.verticalOffset, 100, "scrollView.verticalOffset after navigation"); + TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset after navigation"); } export function test_scrollView_persistsState_horizontal() { @@ -285,7 +285,7 @@ export function test_scrollView_persistsState_horizontal() { scrollView.scrollToHorizontalOffset(100, false); - TKUnit.assertEqual(scrollView.horizontalOffset, 100, "scrollView.horizontalOffset before navigation"); + TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset before navigation"); helper.do_PageTest_WithButton((t) => { // Just navigate forward and back. @@ -293,9 +293,9 @@ export function test_scrollView_persistsState_horizontal() { // Wait for the page to reload. TKUnit.waitUntilReady(function () { - return scrollView.horizontalOffset === 100; + return Math.abs(scrollView.horizontalOffset - 100) < 0.1; }, ASYNC); // Check verticalOffset after navigation - TKUnit.assertEqual(scrollView.horizontalOffset, 100, "scrollView.horizontalOffset after navigation"); + TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset after navigation"); } diff --git a/apps/tests/ui/search-bar/search-bar-tests.ts b/apps/tests/ui/search-bar/search-bar-tests.ts index 7164134f5..b030c20a0 100644 --- a/apps/tests/ui/search-bar/search-bar-tests.ts +++ b/apps/tests/ui/search-bar/search-bar-tests.ts @@ -70,7 +70,7 @@ export var testSearchBarFontSize = function () { searchBar.style.fontSize = expectedValue; actualValue = searchBarTestsNative.getNativeFontSize(searchBar); - TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + TKUnit.assertAreClose(actualValue, expectedValue, 0.2); }); }; diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index 74134f0b0..c0fdb2e2c 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -407,11 +407,11 @@ function property_binding_test(propName: string, firstValue: any, secondValue: a view.bind(options, model); actualResult = view.get(propName); - TKUnit.assert(actualResult === firstValue, "Actual result: " + actualResult + "; Expected result: " + firstValue); + TKUnit.assertEqual(actualResult, firstValue); model.set(propName, secondValue); actualResult = view.get(propName); - TKUnit.assert(actualResult === secondValue, "Actual result: " + actualResult + "; Expected result: " + secondValue); + TKUnit.assertEqual(actualResult, secondValue); } function property_binding_style_test(propName: string, firstValue: any, secondValue: any, view?: viewModule.View) { @@ -431,11 +431,11 @@ function property_binding_style_test(propName: string, firstValue: any, secondVa view.bind(options, model); actualResult = view.style.get(propName); - TKUnit.assert(actualResult === firstValue, "Actual result: " + actualResult + "; Expected result: " + firstValue); + TKUnit.assertEqual(actualResult, firstValue); model.set(propName, secondValue); actualResult = view.style.get(propName); - TKUnit.assert(actualResult === secondValue, "Actual result: " + actualResult + "; Expected result: " + secondValue); + TKUnit.assertEqual(actualResult, secondValue); } export var test_binding_width = function () { @@ -531,7 +531,7 @@ export var test_binding_style_minHeight = function () { } export var test_binding_style_margin = function () { - property_binding_style_test("margin", "1,1,1,1", "2,2,2,2"); + property_binding_style_test("margin", "1 1 1 1", "2 2 2 2"); } export var test_binding_style_marginLeft = function () { @@ -551,7 +551,7 @@ export var test_binding_style_marginBottom = function () { } export var test_binding_style_padding = function () { - property_binding_style_test("padding", "1,1,1,1", "2,2,2,2"); + property_binding_style_test("padding", "1 1 1 1", "2 2 2 2"); } export var test_binding_style_paddingLeft = function () { @@ -600,16 +600,16 @@ export var testIsVisible = function () { var lbl = new label.Label(); helper.buildUIAndRunTest(lbl, function (views: Array) { - TKUnit.assert(lbl.visibility === enums.Visibility.visible, "Actual: " + lbl.visibility + "; Expected: " + enums.Visibility.visible); - TKUnit.assert(lbl._isVisible, "Actual: " + lbl._isVisible + "; Expected: true;"); + TKUnit.assertEqual(lbl.visibility, enums.Visibility.visible); + TKUnit.assertEqual(lbl._isVisible, true); lbl.visibility = enums.Visibility.collapse; - TKUnit.assert(lbl.visibility === enums.Visibility.collapse, "Actual: " + lbl.visibility + "; Expected: " + enums.Visibility.collapse); - TKUnit.assert(!lbl._isVisible, "Actual: " + lbl._isVisible + "; Expected: false;"); + TKUnit.assertEqual(lbl.visibility, enums.Visibility.collapse); + TKUnit.assertEqual(lbl._isVisible, false); lbl.visibility = enums.Visibility.collapsed; - TKUnit.assert(lbl.visibility === enums.Visibility.collapsed, "Actual: " + lbl.visibility + "; Expected: " + enums.Visibility.collapsed); - TKUnit.assert(!lbl._isVisible, "Actual: " + lbl._isVisible + "; Expected: false;"); + TKUnit.assertEqual(lbl.visibility, enums.Visibility.collapsed); + TKUnit.assertEqual(lbl._isVisible, false); }); } @@ -632,7 +632,7 @@ export var testBorderWidth = function () { var lbl = views[0]; var expectedValue = lbl.borderWidth; var actualValue = definition.getNativeBorderWidth(lbl); - TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + TKUnit.assertEqual(actualValue, expectedValue); }); } @@ -641,21 +641,21 @@ export var testCornerRadius = function () { var lbl = views[0]; var expectedValue = lbl.borderRadius; var actualValue = definition.getNativeCornerRadius(lbl); - TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + TKUnit.assertEqual(actualValue, expectedValue); }); } export var testBorderColor = function () { helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { var lbl = views[0]; - TKUnit.assert(definition.checkNativeBorderColor(lbl), "BorderColor not applied correctly!"); + TKUnit.assertEqual(definition.checkNativeBorderColor(lbl), true, "BorderColor not applied correctly!"); }); } export var testBackgroundColor = function () { helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { var lbl = views[0]; - TKUnit.assert(definition.checkNativeBackgroundColor(lbl), "BackgroundColor not applied correctly!"); + TKUnit.assertEqual(definition.checkNativeBackgroundColor(lbl), true, "BackgroundColor not applied correctly!"); }); } @@ -665,7 +665,6 @@ export var testBackgroundImage = function () { helper.buildUIAndRunTest(lbl, function (views: Array) { var page = views[1]; page.css = ".myClass { background-image: url('~/logo.png') }"; - - TKUnit.assert(definition.checkNativeBackgroundImage(lbl), "Style background-image not loaded correctly."); + TKUnit.assertEqual(definition.checkNativeBackgroundImage(lbl), true, "Style background-image not loaded correctly."); }); } \ No newline at end of file diff --git a/apps/ui-tests-app/pages/text/button.ts b/apps/ui-tests-app/pages/text/button.ts index 0c4b3bb79..c9c0d1c17 100644 --- a/apps/ui-tests-app/pages/text/button.ts +++ b/apps/ui-tests-app/pages/text/button.ts @@ -8,9 +8,15 @@ export function resetStyles(args) { v.style._resetValue(style.fontSizeProperty); v.style._resetValue(style.fontStyleProperty); v.style._resetValue(style.fontWeightProperty); - v.style._resetValue(style.fontProperty); v.style._resetValue(style.colorProperty); v.style._resetValue(style.textAlignmentProperty); + v.style._resetValue(style.paddingLeftProperty); + v.style._resetValue(style.paddingRightProperty); + v.style._resetValue(style.paddingTopProperty); + v.style._resetValue(style.paddingBottomProperty); + v.style._resetValue(style.borderColorProperty); + v.style._resetValue(style.borderWidthProperty); + v.style._resetValue(style.borderRadiusProperty); return true; }); } diff --git a/apps/ui-tests-app/pages/text/button.xml b/apps/ui-tests-app/pages/text/button.xml index d15d8ef6d..a056790e1 100644 --- a/apps/ui-tests-app/pages/text/button.xml +++ b/apps/ui-tests-app/pages/text/button.xml @@ -8,17 +8,19 @@