8000 Merge pull request #3514 from NativeScript/cankov/fix-few-tests · jensWorkGit/NativeScript@602132b · GitHub
[go: up one dir, main page]

Skip to content

Commit 602132b

Browse files
Merge pull request NativeScript#3514 from NativeScript/cankov/fix-few-tests
Enable Button tests, fix AbsoluteLayout tests
2 parents e34b0f6 + 312a996 commit 602132b

File tree

14 files changed

+153
-176
lines changed

14 files changed

+153
-176
lines changed

tests/app/ui/button/button-tests.ts

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import * as viewModule from "ui/core/view";
44
import * as pagesModule from "ui/page";
55
import * as buttonTestsNative from "./button-tests-native";
66
import * as colorModule from "color";
7-
// import * as enums from "ui/enums";
8-
// import * as formattedStringModule from "text/formatted-string";
9-
// import * as spanModule from "text/span";
7+
import * as formattedStringModule from "text/formatted-string";
8+
import * as spanModule from "text/span";
109

1110
// >> button-require
1211
import * as buttonModule from "ui/button";
@@ -310,62 +309,61 @@ export var testNativeTextAlignmentFromLocal = function () {
310309
});
311310
}
312311

313-
// TODO: Enable these when.
314-
// export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () {
315-
// var firstSpan = new spanModule.Span();
316-
// firstSpan.fontSize = 10;
317-
// firstSpan.text = "First";
318-
// var secondSpan = new spanModule.Span();
319-
// secondSpan.fontSize = 15;
320-
// secondSpan.text = "Second";
321-
// var thirdSpan = new spanModule.Span();
322-
// thirdSpan.fontSize = 20;
323-
// thirdSpan.text = "Third";
324-
// var formattedString1 = new formattedStringModule.FormattedString();
325-
// formattedString1.spans.push(firstSpan);
326-
// var formattedString2 = new formattedStringModule.FormattedString();
327-
// formattedString2.spans.push(secondSpan);
328-
// formattedString2.spans.push(thirdSpan);
329-
330-
// var view = new buttonModule.Button();
331-
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
332-
// TKUnit.assertEqual(view.text, "");
333-
334-
// view.formattedText = formattedString1;
335-
// TKUnit.assertEqual(view.text, "First");
336-
337-
// view.formattedText = formattedString2;
338-
// TKUnit.assertEqual(view.text, "SecondThird");
339-
340-
// formattedString2.spans.getItem(0).text = "Mecond";
341-
// TKUnit.assertEqual(view.text, "MecondThird");
342-
343-
// view.formattedText = null;
344-
// TKUnit.assertEqual(view.text, "");
345-
// });
346-
// }
347-
348-
// export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() {
349-
// let view = new buttonModule.Button();
350-
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
351-
// view.text = "NormalText";
352-
// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
353-
354-
// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform");
355-
// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration");
356-
// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
357-
// });
358-
// }
359-
360-
// export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() {
361-
// let view = new buttonModule.Button();
362-
// let formattedString = helper._generateFormattedString();
363-
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
364-
// view.formattedText = formattedString;
365-
// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
366-
367-
// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform");
368-
// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration");
369-
// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
370-
// });
371-
// }
312+
export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () {
313+
var firstSpan = new spanModule< FE6D /span>.Span();
314+
firstSpan.fontSize = 10;
315+
firstSpan.text = "First";
316+
var secondSpan = new spanModule.Span();
317+
secondSpan.fontSize = 15;
318+
secondSpan.text = "Second";
319+
var thirdSpan = new spanModule.Span();
320+
thirdSpan.fontSize = 20;
321+
thirdSpan.text = "Third";
322+
var formattedString1 = new formattedStringModule.FormattedString();
323+
formattedString1.spans.push(firstSpan);
324+
var formattedString2 = new formattedStringModule.FormattedString();
325+
formattedString2.spans.push(secondSpan);
326+
formattedString2.spans.push(thirdSpan);
327+
328+
var view = new buttonModule.Button();
329+
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
330+
TKUnit.assertEqual(view.text, "");
331+
332+
view.formattedText = formattedString1;
333+
TKUnit.assertEqual(view.text, "First");
334+
335+
view.formattedText = formattedString2;
336+
TKUnit.assertEqual(view.text, "SecondThird");
337+
338+
formattedString2.spans.getItem(0).text = "Mecond";
339+
TKUnit.assertEqual(view.text, "MecondThird");
340+
341+
view.formattedText = null;
342+
TKUnit.assertEqual(view.text, "");
343+
});
344+
}
345+
346+
export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() {
347+
let view = new buttonModule.Button();
348+
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
349+
view.text = "NormalText";
350+
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
351+
352+
TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform");
353+
TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration");
354+
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
355+
});
356+
}
357+
358+
export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() {
359+
let view = new buttonModule.Button();
360+
let formattedString = helper._generateFormattedString();
361+
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
362+
view.formattedText = formattedString;
363+
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
364+
365+
TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform");
366+
TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration");
367+
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
368+
});
369+
}

tests/app/ui/label/label-tests.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -377,32 +377,6 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
377377
TKUnit.assertEqual(label.text, secondExpValue);
378378
}
379379

380-
// TODO: Check if bindings will be cleared when the target property is set.
381-
// public test_BindingToText_BindingContext_SetingLocalValue() {
382-
// const label = this.testView;
383-
// this.waitUntilTestElementIsLoaded();
384-
385-
// const firstExpValue = "Expected Value";
386-
// const bindingOptions: bindable.BindingOptions = {
387-
// sourceProperty: "sourceProperty",
388-
// targetProperty: "text"
389-
// };
390-
// label.bind(bindingOptions);
391-
// const firstSourceObject = new observableModule.Observable();
392-
// firstSourceObject.set("sourceProperty", firstExpValue);
393-
394-
// this.testPage.bindingContext = firstSourceObject;
395-
// TKUnit.assertEqual(label.text, firstExpValue);
396-
397-
// const secondExpValue = "Second value";
398-
// label.text = secondExpValue;
399-
// TKUnit.assertEqual(label.text, secondExpValue);
400-
401-
// firstSourceObject.set("sourceProperty", "some value");
402-
// // after setting a value one way binding should be gone.
403-
// TKUnit.assertEqual(label.text, secondExpValue);
404-
// }
405-
406380
private expectedTextAlignment: "right" = "right";
407381
public testLocalTextAlignmentFromCss() {
408382
const label = this.testView;

tests/app/ui/layouts/absolute-layout-tests.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,26 @@ export class AbsoluteLayoutTest extends testModule.UITest<absoluteLayoutModule.A
8282
layoutHelper.assertLayout(btn, 25, 35, 100, 100);
8383
}
8484

85-
// 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
86-
// public test_percent_children_support() {
87-
// let layout = this.testView;
88-
// layout.width = { value: 200, unit: "px" };
89-
// layout.height = { value: 200, unit: "px" };
90-
91-
// let btn = new layoutHelper.MyButton();
92-
// (<any>btn).width = "50%";
93-
// (<any>btn).height = "50%";
94-
// btn.margin = "10%";
95-
// layout.addChild(btn);
96-
97-
// this.waitUntilTestElementLayoutIsValid();
98-
99-
// // AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it.
100-
// layoutHelper.assertMeasure(btn, 100, 100);
101-
// layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight());
102-
103-
// TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect");
104-
// TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect");
105-
// }
85+
public test_percent_children_support() {
86+
let layout = this.testView;
87+
layout.width = { value: 200, unit: "px" };
88+
layout.height = { value: 200, unit: "px" };
89+
90+
let btn = new layoutHelper.MyButton();
91+
(<any>btn).width = "50%";
92+
(<any>btn).height = "50%";
93+
btn.margin = "10%";
94+
layout.addChild(btn);
95+
96+
this.waitUntilTestElementLayoutIsValid();
97+
98+
// AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it.
99+
layoutHelper.assertMeasure(btn, 100, 100);
100+
layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight());
101+
102+
TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect");
103+
TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect");
104+
}
106105

107106
public test_percent_support_nativeLayoutParams_are_correct() {
108107
commonTests.percent_support_nativeLayoutParams_are_correct(this);

tests/app/ui/layouts/grid-layout-tests.ts

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,21 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
159159
}, "setColumnSpan called with null should throw exception");
160160
}
161161

162-
// TODO: These 4 asserted that wrong numbers will throw and now they are clamped internally to valid values and does not throw.
163-
// public test_setRow_shouldThrow_onNegativeValues() {
164-
// TKUnit.assertThrows(() => {
165-
// GridLayout.setRow(new Button(), -1);
166-
// }, "setRow should throw when value < 0");
167-
// }
168-
169-
// public test_setRowSpan_shouldThrow_onNotPositiveValues() {
170-
// TKUnit.assertThrows(() => {
171-
// GridLayout.setRowSpan(new Button(), 0);
172-
// }, "setRowSpan should throw when value <= 0");
173-
// }
174-
175-
// public test_setColumn_shouldThrow_onNegativeValues() {
176-
// TKUnit.assertThrows(() => {
177-
// GridLayout.setColumn(new Button(), -1);
178-
// }, "setColumn should when value < 0");
179-
// }
180-
181-
// public test_setColumnSpan_shouldThrow_onNotPositiveValues() {
182-
// TKUnit.assertThrows(() => {
183-
// GridLayout.setColumnSpan(new Button(), 0);
184-
// }, "setColumnSpan should throw when value <= 0");
185-
// }
162+
public test_setRow_shouldNotThrow_onNegativeValues() {
163+
GridLayout.setRow(new Button(), -1);
164+
}
165+
166+
public test_setRowSpan_shouldNotThrow_onNotPositiveValues() {
167+
GridLayout.setRowSpan(new Button(), 0);
168+
}
169+
170+
public test_setColumn_shouldNotThrow_onNegativeValues() {
171+
GridLayout.setColumn(new Button(), -1);
172+
}
173+
174+
public test_setColumnSpan_shouldNotThrow_onNotPositiveValues() {
175+
GridLayout.setColumnSpan(new Button(), 0);
176+
}
186177

187178
public test_addRow_shouldThrow_onNullValues() {
188179
TKUnit.assertThrows(() => {
@@ -325,12 +316,11 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
325316
}
326317
}
327318

328-
// TODO: This used to throw but the underlaying "makeParser" used fallbacks to default value instead of throwing
329-
// public test_ItemSpec_constructor_throws_onWrongType() {
330-
// TKUnit.assertThrows(() => {
331-
// return new ItemSpec(1, <any>"unsupported");
332-
// }, "'ItemSpec type' incorrect value.");
333-
// }
319+
public test_ItemSpec_constructor_throws_onWrongType() {
320+
TKUnit.assertThrows(() => {
321+
return new ItemSpec(1, <any>"unsupported");
322+
}, "Invalid value: unsupported");
323+
}
334324

335325
public test_ItemSpec_auto() {
336326
var w = new ItemSpec(1, "auto");

tns-core-modules/ui/core/properties.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,13 @@ export function makeValidator<T>(...values: T[]): (value: any) => value is T {
946946
return (value: any): value is T => set.has(value);
947947
}
948948

949-
export function makeParser<T>(isValid: (value: any) => boolean, def: T): (value: any) => T {
949+
export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T {
950950
return value => {
951951
const lower = value && value.toLowerCase();
952-
return isValid(lower) ? lower : def;
952+
if (isValid(lower)) {
953+
return lower;
954+
} else {
955+
throw new Error("Invalid value: " + value);
956+
}
953957
}
954958
}

tns-core-modules/ui/core/view-common.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ export namespace HorizontalAlignment {
12371237
export const RIGHT: "right" = "right";
12381238
export const STRETCH: "stretch" = "stretch";
12391239
export const isValid = makeValidator<HorizontalAlignment>(LEFT, CENTER, RIGHT, STRETCH);
1240-
export const parse = makeParser(isValid, STRETCH);
1240+
export const parse = makeParser<HorizontalAlignment>(isValid);
12411241
}
12421242

12431243
export const horizontalAlignmentProperty = new CssProperty<Style, HorizontalAlignment>({ name: "horizontalAlignment", cssName: "horizontal-align", defaultValue: HorizontalAlignment.STRETCH, affectsLayout: isIOS, valueConverter: HorizontalAlignment.parse });
@@ -1250,7 +1250,16 @@ export namespace VerticalAlignment {
12501250
export const BOTTOM: "bottom" = "bottom";
12511251
export const STRETCH: "stretch" = "stretch";
12521252
export const isValid = makeValidator<VerticalAlignment>(TOP, MIDDLE, BOTTOM, STRETCH);
1253-
export const parse = makeParser(isValid, STRETCH);
1253+
export const parse = value => {
1254+
const lower = value && value.toLowerCase();
1255+
if (lower === "canter") {
1256+
return MIDDLE;
1257+
} else if (isValid(lower)) {
1258+
return lower;
1259+
} else {
1260+
throw new Error("Invalid value: " + value);
1261+
}
1262+
}
12541263
}
12551264

12561265
export const verticalAlignmentProperty = new CssProperty<Style, VerticalAlignment>({ name: "verticalAlignment", cssName: "vertical-align", defaultValue: VerticalAlignment.STRETCH, affectsLayout: isIOS, valueConverter: VerticalAlignment.parse });
@@ -1559,7 +1568,7 @@ export namespace BackgroundRepeat {
15591568
export const REPEAT_Y: "repeat-y" = "repeat-y";
15601569
export const NO_REPEAT: "no-repeat" = "no-repeat";
15611570
export const isValid = makeValidator<BackgroundRepeat>(REPEAT, REPEAT_X, REPEAT_Y, NO_REPEAT);
1562-
export const parse = makeParser(isValid, undefined);
1571+
export const parse = makeParser<BackgroundRepeat>(isValid);
15631572
}
15641573

15651574
export const backgroundRepeatProperty = new CssProperty<Style, BackgroundRepeat>({
@@ -2016,12 +2025,12 @@ export namespace Visibility {
20162025
export const HIDDEN: "hidden" = "hidden";
20172026
export const COLLAPSE: "collapse" = "collapse";
20182027
export const isValid = makeValidator<Visibility>(VISIBLE, HIDDEN, COLLAPSE);
2019-
export const parse = makeParser(isValid, VISIBLE);
2028+
export const parse = makeParser<Visibility>(isValid);
20202029
}
20212030

20222031
export const visibilityProperty = new CssProperty<Style, Visibility>({
20232032
name: "visibility", cssName: "visibility", defaultValue: Visibility.VISIBLE, affectsLayout: isIOS, valueConverter: Visibility.parse, valueChanged: (target, oldValue, newValue) => {
20242033
target.view.isCollapsed = (newValue === Visibility.COLLAPSE);
20252034
}
20262035
});
2027-
visibilityProperty.register(Style);
2036+
visibilityProperty.register(Style);

tns-core-modules/ui/definitions.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,5 @@ declare module "ui/core/properties" {
270270
export function resetCSSProperties(style: Style): void;
271271

272272
export function makeValidator<T>(...values: T[]): (value: any) => value is T;
273-
export function makeParser<T>(isValid: (value: any) => boolean, def: T): (value: any) => T;
273+
export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T;
274274
}

tns-core-modules/ui/layouts/absolute-layout/absolute-layout.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class AbsoluteLayout extends AbsoluteLayoutBase {
5454

5555
const childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + child.effectiveLeft;
5656
const childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + child.effectiveTop;
57-
const childRight = childLeft + childWidth + this.effectiveMarginLeft + this.effectiveMarginRight;
58-
const childBottom = childTop + childHeight + this.effectiveMarginTop + this.effectiveMarginBottom;
57+
const childRight = childLeft + childWidth + child.effectiveMarginLeft + child.effectiveMarginRight;
58+
const childBottom = childTop + childHeight + child.effectiveMarginTop + child.effectiveMarginBottom;
5959

6060
View.layoutChild(this, child, childLeft, childTop, childRight, childBottom);
6161
});

0 commit comments

Comments
 (0)
0