mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Enable Button tests, fix AbsoluteLayout tests
This commit is contained in:
@@ -4,9 +4,8 @@ import * as viewModule from "ui/core/view";
|
||||
import * as pagesModule from "ui/page";
|
||||
import * as buttonTestsNative from "./button-tests-native";
|
||||
import * as colorModule from "color";
|
||||
// import * as enums from "ui/enums";
|
||||
// import * as formattedStringModule from "text/formatted-string";
|
||||
// import * as spanModule from "text/span";
|
||||
import * as formattedStringModule from "text/formatted-string";
|
||||
import * as spanModule from "text/span";
|
||||
|
||||
// >> button-require
|
||||
import * as buttonModule from "ui/button";
|
||||
@@ -310,62 +309,61 @@ export var testNativeTextAlignmentFromLocal = function () {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Enable these when.
|
||||
// export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () {
|
||||
// var firstSpan = new spanModule.Span();
|
||||
// firstSpan.fontSize = 10;
|
||||
// firstSpan.text = "First";
|
||||
// var secondSpan = new spanModule.Span();
|
||||
// secondSpan.fontSize = 15;
|
||||
// secondSpan.text = "Second";
|
||||
// var thirdSpan = new spanModule.Span();
|
||||
// thirdSpan.fontSize = 20;
|
||||
// thirdSpan.text = "Third";
|
||||
// var formattedString1 = new formattedStringModule.FormattedString();
|
||||
// formattedString1.spans.push(firstSpan);
|
||||
// var formattedString2 = new formattedStringModule.FormattedString();
|
||||
// formattedString2.spans.push(secondSpan);
|
||||
// formattedString2.spans.push(thirdSpan);
|
||||
export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () {
|
||||
var firstSpan = new spanModule.Span();
|
||||
firstSpan.fontSize = 10;
|
||||
firstSpan.text = "First";
|
||||
var secondSpan = new spanModule.Span();
|
||||
secondSpan.fontSize = 15;
|
||||
secondSpan.text = "Second";
|
||||
var thirdSpan = new spanModule.Span();
|
||||
thirdSpan.fontSize = 20;
|
||||
thirdSpan.text = "Third";
|
||||
var formattedString1 = new formattedStringModule.FormattedString();
|
||||
formattedString1.spans.push(firstSpan);
|
||||
var formattedString2 = new formattedStringModule.FormattedString();
|
||||
formattedString2.spans.push(secondSpan);
|
||||
formattedString2.spans.push(thirdSpan);
|
||||
|
||||
// var view = new buttonModule.Button();
|
||||
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
// TKUnit.assertEqual(view.text, "");
|
||||
var view = new buttonModule.Button();
|
||||
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
TKUnit.assertEqual(view.text, "");
|
||||
|
||||
// view.formattedText = formattedString1;
|
||||
// TKUnit.assertEqual(view.text, "First");
|
||||
view.formattedText = formattedString1;
|
||||
TKUnit.assertEqual(view.text, "First");
|
||||
|
||||
// view.formattedText = formattedString2;
|
||||
// TKUnit.assertEqual(view.text, "SecondThird");
|
||||
view.formattedText = formattedString2;
|
||||
TKUnit.assertEqual(view.text, "SecondThird");
|
||||
|
||||
// formattedString2.spans.getItem(0).text = "Mecond";
|
||||
// TKUnit.assertEqual(view.text, "MecondThird");
|
||||
formattedString2.spans.getItem(0).text = "Mecond";
|
||||
TKUnit.assertEqual(view.text, "MecondThird");
|
||||
|
||||
// view.formattedText = null;
|
||||
// TKUnit.assertEqual(view.text, "");
|
||||
// });
|
||||
// }
|
||||
view.formattedText = null;
|
||||
TKUnit.assertEqual(view.text, "");
|
||||
});
|
||||
}
|
||||
|
||||
// export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() {
|
||||
// let view = new buttonModule.Button();
|
||||
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
// view.text = "NormalText";
|
||||
// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
|
||||
|
||||
// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform");
|
||||
// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration");
|
||||
// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
|
||||
// });
|
||||
// }
|
||||
export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() {
|
||||
let view = new buttonModule.Button();
|
||||
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
view.text = "NormalText";
|
||||
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
|
||||
|
||||
// export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() {
|
||||
// let view = new buttonModule.Button();
|
||||
// let formattedString = helper._generateFormattedString();
|
||||
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
// view.formattedText = formattedString;
|
||||
// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
|
||||
|
||||
// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform");
|
||||
// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration");
|
||||
// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
|
||||
// });
|
||||
// }
|
||||
TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform");
|
||||
TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration");
|
||||
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
|
||||
});
|
||||
}
|
||||
|
||||
export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() {
|
||||
let view = new buttonModule.Button();
|
||||
let formattedString = helper._generateFormattedString();
|
||||
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
view.formattedText = formattedString;
|
||||
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
|
||||
|
||||
TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform");
|
||||
TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration");
|
||||
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -377,32 +377,6 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
TKUnit.assertEqual(label.text, secondExpValue);
|
||||
}
|
||||
|
||||
// TODO: Check if bindings will be cleared when the target property is set.
|
||||
// public test_BindingToText_BindingContext_SetingLocalValue() {
|
||||
// const label = this.testView;
|
||||
// this.waitUntilTestElementIsLoaded();
|
||||
|
||||
// const firstExpValue = "Expected Value";
|
||||
// const bindingOptions: bindable.BindingOptions = {
|
||||
// sourceProperty: "sourceProperty",
|
||||
// targetProperty: "text"
|
||||
// };
|
||||
// label.bind(bindingOptions);
|
||||
// const firstSourceObject = new observableModule.Observable();
|
||||
// firstSourceObject.set("sourceProperty", firstExpValue);
|
||||
|
||||
// this.testPage.bindingContext = firstSourceObject;
|
||||
// TKUnit.assertEqual(label.text, firstExpValue);
|
||||
|
||||
// const secondExpValue = "Second value";
|
||||
// label.text = secondExpValue;
|
||||
// TKUnit.assertEqual(label.text, secondExpValue);
|
||||
|
||||
// firstSourceObject.set("sourceProperty", "some value");
|
||||
// // after setting a value one way binding should be gone.
|
||||
// TKUnit.assertEqual(label.text, secondExpValue);
|
||||
// }
|
||||
|
||||
private expectedTextAlignment: "right" = "right";
|
||||
public testLocalTextAlignmentFromCss() {
|
||||
const label = this.testView;
|
||||
|
||||
@@ -82,27 +82,26 @@ export class AbsoluteLayoutTest extends testModule.UITest<absoluteLayoutModule.A
|
||||
layoutHelper.assertLayout(btn, 25, 35, 100, 100);
|
||||
}
|
||||
|
||||
// TODO: This mostly works, but the current logic will check the button to have width and margin and will make it CENTER clearing the effect of the 20 pixels margin
|
||||
// public test_percent_children_support() {
|
||||
// let layout = this.testView;
|
||||
// layout.width = { value: 200, unit: "px" };
|
||||
// layout.height = { value: 200, unit: "px" };
|
||||
public test_percent_children_support() {
|
||||
let layout = this.testView;
|
||||
layout.width = { value: 200, unit: "px" };
|
||||
layout.height = { value: 200, unit: "px" };
|
||||
|
||||
// let btn = new layoutHelper.MyButton();
|
||||
// (<any>btn).width = "50%";
|
||||
// (<any>btn).height = "50%";
|
||||
// btn.margin = "10%";
|
||||
// layout.addChild(btn);
|
||||
let btn = new layoutHelper.MyButton();
|
||||
(<any>btn).width = "50%";
|
||||
(<any>btn).height = "50%";
|
||||
btn.margin = "10%";
|
||||
layout.addChild(btn);
|
||||
|
||||
// this.waitUntilTestElementLayoutIsValid();
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
// // AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it.
|
||||
// layoutHelper.assertMeasure(btn, 100, 100);
|
||||
// layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight());
|
||||
// AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it.
|
||||
layoutHelper.assertMeasure(btn, 100, 100);
|
||||
layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight());
|
||||
|
||||
// TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect");
|
||||
// TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect");
|
||||
// }
|
||||
TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect");
|
||||
TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect");
|
||||
}
|
||||
|
||||
public test_percent_support_nativeLayoutParams_are_correct() {
|
||||
commonTests.percent_support_nativeLayoutParams_are_correct(this);
|
||||
|
||||
@@ -159,30 +159,21 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
|
||||
}, "setColumnSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
// TODO: These 4 asserted that wrong numbers will throw and now they are clamped internally to valid values and does not throw.
|
||||
// public test_setRow_shouldThrow_onNegativeValues() {
|
||||
// TKUnit.assertThrows(() => {
|
||||
// GridLayout.setRow(new Button(), -1);
|
||||
// }, "setRow should throw when value < 0");
|
||||
// }
|
||||
public test_setRow_shouldNotThrow_onNegativeValues() {
|
||||
GridLayout.setRow(new Button(), -1);
|
||||
}
|
||||
|
||||
// public test_setRowSpan_shouldThrow_onNotPositiveValues() {
|
||||
// TKUnit.assertThrows(() => {
|
||||
// GridLayout.setRowSpan(new Button(), 0);
|
||||
// }, "setRowSpan should throw when value <= 0");
|
||||
// }
|
||||
public test_setRowSpan_shouldNotThrow_onNotPositiveValues() {
|
||||
GridLayout.setRowSpan(new Button(), 0);
|
||||
}
|
||||
|
||||
// public test_setColumn_shouldThrow_onNegativeValues() {
|
||||
// TKUnit.assertThrows(() => {
|
||||
// GridLayout.setColumn(new Button(), -1);
|
||||
// }, "setColumn should when value < 0");
|
||||
// }
|
||||
public test_setColumn_shouldNotThrow_onNegativeValues() {
|
||||
GridLayout.setColumn(new Button(), -1);
|
||||
}
|
||||
|
||||
// public test_setColumnSpan_shouldThrow_onNotPositiveValues() {
|
||||
// TKUnit.assertThrows(() => {
|
||||
// GridLayout.setColumnSpan(new Button(), 0);
|
||||
// }, "setColumnSpan should throw when value <= 0");
|
||||
// }
|
||||
public test_setColumnSpan_shouldNotThrow_onNotPositiveValues() {
|
||||
GridLayout.setColumnSpan(new Button(), 0);
|
||||
}
|
||||
|
||||
public test_addRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
@@ -325,12 +316,11 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This used to throw but the underlaying "makeParser" used fallbacks to default value instead of throwing
|
||||
// public test_ItemSpec_constructor_throws_onWrongType() {
|
||||
// TKUnit.assertThrows(() => {
|
||||
// return new ItemSpec(1, <any>"unsupported");
|
||||
// }, "'ItemSpec type' incorrect value.");
|
||||
// }
|
||||
public test_ItemSpec_constructor_throws_onWrongType() {
|
||||
TKUnit.assertThrows(() => {
|
||||
return new ItemSpec(1, <any>"unsupported");
|
||||
}, "Invalid value: unsupported");
|
||||
}
|
||||
|
||||
public test_ItemSpec_auto() {
|
||||
var w = new ItemSpec(1, "auto");
|
||||
|
||||
Reference in New Issue
Block a user