mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
grid-layout distribute remaining space over stars but preserve their aspect.
ts lint errors fixed android scroll-view tests fixed for different device density added grid-layout test
This commit is contained in:
@@ -689,25 +689,36 @@ export class GridLayoutTest extends testModule.UITest<GridLayout> {
|
||||
}
|
||||
|
||||
public test_columns_widths() {
|
||||
this.testView.width = layoutHelper.dp(300);
|
||||
this.testView.height = layoutHelper.dp(500);
|
||||
this.testView.width = layoutHelper.dp(400);
|
||||
this.testView.height = layoutHelper.dp(600);
|
||||
|
||||
this.testView.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addColumn(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel));
|
||||
this.testView.addColumn(new ItemSpec(2, GridUnitType.star));
|
||||
|
||||
this.testView.addRow(new ItemSpec(1, GridUnitType.star));
|
||||
this.testView.addRow(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel));
|
||||
this.testView.addRow(new ItemSpec(2, GridUnitType.star));
|
||||
let grid = new GridLayout();
|
||||
this.testView.addChild(grid);
|
||||
grid.horizontalAlignment = enums.HorizontalAlignment.left;
|
||||
grid.verticalAlignment = enums.VerticalAlignment.top;
|
||||
|
||||
grid.addColumn(new ItemSpec(1, GridUnitType.star));
|
||||
grid.addColumn(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel));
|
||||
grid.addColumn(new ItemSpec(2, GridUnitType.star));
|
||||
|
||||
grid.addRow(new ItemSpec(1, GridUnitType.star));
|
||||
grid.addRow(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel));
|
||||
grid.addRow(new ItemSpec(2, GridUnitType.star));
|
||||
|
||||
let btn = new Button();
|
||||
btn.width = layoutHelper.dp(300);
|
||||
btn.height = layoutHelper.dp(500);
|
||||
grid.addChild(btn);
|
||||
GridLayout.setColumnSpan(btn, 3);
|
||||
GridLayout.setRowSpan(btn, 3);
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
var cols = this.testView.getColumns();
|
||||
var cols = grid.getColumns();
|
||||
TKUnit.assertAreClose(cols[0].actualLength, layoutHelper.dp(67), DELTA, "Column[0] actual length should be 67");
|
||||
TKUnit.assertAreClose(cols[1].actualLength, layoutHelper.dp(100), DELTA, "Column[1] actual length should be 100");
|
||||
TKUnit.assertAreClose(cols[2].actualLength, layoutHelper.dp(133), DELTA, "Column[2] actual length should be 133");
|
||||
|
||||
var rows = this.testView.getRows();
|
||||
var rows = grid.getRows();
|
||||
TKUnit.assertAreClose(rows[0].actualLength, layoutHelper.dp(133), DELTA, "Row[0] actual length should be 133");
|
||||
TKUnit.assertAreClose(rows[1].actualLength, layoutHelper.dp(100), DELTA, "Row[1] actual length should be 100");
|
||||
TKUnit.assertAreClose(rows[2].actualLength, layoutHelper.dp(267), DELTA, "Row[2] actual length should be 267");
|
||||
|
||||
@@ -27,8 +27,21 @@ import scrollViewModule = require("ui/scroll-view");
|
||||
// </snippet>
|
||||
|
||||
class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
|
||||
public create(): scrollViewModule.ScrollView {
|
||||
return new scrollViewModule.ScrollView();
|
||||
let scrollView = new scrollViewModule.ScrollView();
|
||||
scrollView.orientation = enums.Orientation.vertical;
|
||||
|
||||
scrollView.width = layoutHelper.dp(200);
|
||||
scrollView.height = layoutHelper.dp(300);
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = layoutHelper.dp(500);
|
||||
btn.height = layoutHelper.dp(500);
|
||||
scrollView.content = btn;
|
||||
|
||||
return scrollView;
|
||||
}
|
||||
|
||||
public test_snippets() {
|
||||
@@ -69,78 +82,38 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
}
|
||||
|
||||
public test_scrollabeHeight_vertical_orientation_when_content_is_small() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 100;
|
||||
this.testView.content = btn;
|
||||
|
||||
this.testView.content.height = 100;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight");
|
||||
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||
}
|
||||
|
||||
public test_scrollabeHeight_vertical_orientation_when_content_is_big() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
TKUnit.assertAreClose(this.testView.scrollableHeight, 200, 0.4, "this.testView.scrollableHeight");
|
||||
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||
|
||||
TKUnit.assertAreClose(layoutHelper.dip(this.testView.scrollableHeight), 200, 0.4, "this.testView.scrollableHeight");
|
||||
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||
}
|
||||
|
||||
public test_scrollabeWidth_horizontal_orientation_when_content_is_small() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 100;
|
||||
this.testView.content = btn;
|
||||
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
this.testView.content.width = 100;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight");
|
||||
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||
}
|
||||
|
||||
public test_scrollabeWidth_horizontal_orientation_when_content_is_big() {
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight");
|
||||
TKUnit.assertAreClose(this.testView.scrollableWidth, 300, 0.4, "this.testView.scrollableWidth");
|
||||
TKUnit.assertAreClose(layoutHelper.dip(this.testView.scrollableWidth), 300, 0.4, "this.testView.scrollableWidth");
|
||||
}
|
||||
|
||||
public test_scrollToVerticalOffset_no_animation() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset");
|
||||
@@ -149,15 +122,6 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
}
|
||||
|
||||
public test_scrollToVerticalOffset_with_animation() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset");
|
||||
@@ -174,14 +138,6 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
|
||||
public test_scrollToHorizontalOffset_no_animation() {
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset");
|
||||
@@ -191,14 +147,6 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
|
||||
public test_scrollToHorizontalOffset_with_animation() {
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
let btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset");
|
||||
@@ -214,19 +162,9 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
}
|
||||
|
||||
public test_scrollView_persistsState_vertical() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false);
|
||||
|
||||
TKUnit.assertAreClose(layoutHelper.dip(this.testView.verticalOffset), 100, 0.1, "this.testView.verticalOffset before navigation");
|
||||
|
||||
helper.do_PageTest_WithButton((t) => {
|
||||
@@ -242,14 +180,6 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
|
||||
public test_scrollView_persistsState_horizontal() {
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false);
|
||||
@@ -268,23 +198,14 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
}
|
||||
|
||||
public test_scrollView_vertical_raised_scroll_event() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
var scrollY: number;
|
||||
this.testView.on(scrollViewModule.ScrollView.scrollEvent, (args: scrollViewModule.ScrollEventData) => {
|
||||
scrollY = args.scrollY;
|
||||
});
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToVerticalOffset(100, false);
|
||||
this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false);
|
||||
TKUnit.waitUntilReady(function () { return scrollY > 0; });
|
||||
TKUnit.assertEqual(scrollY, this.testView.verticalOffset);
|
||||
}
|
||||
@@ -297,23 +218,14 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
scrollX = args.scrollX;
|
||||
});
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToHorizontalOffset(100, false);
|
||||
this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false);
|
||||
TKUnit.waitUntilReady(function () { return scrollX > 0; });
|
||||
TKUnit.assertEqual(scrollX, this.testView.horizontalOffset);
|
||||
}
|
||||
|
||||
public test_scrollView_vertical_raised_scroll_event_after_loaded() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var scrollY: number;
|
||||
@@ -321,23 +233,14 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
scrollY = args.scrollY;
|
||||
});
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToVerticalOffset(100, false);
|
||||
this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false);
|
||||
TKUnit.waitUntilReady(function () { return scrollY > 0; });
|
||||
TKUnit.assertEqual(scrollY, this.testView.verticalOffset);
|
||||
TKUnit.assertEqual(scrollY, layoutHelper.dp(100));
|
||||
}
|
||||
|
||||
public test_scrollView_horizontal_raised_scroll_event_after_loaded() {
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var scrollX: number;
|
||||
@@ -345,18 +248,12 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
scrollX = args.scrollX;
|
||||
});
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToHorizontalOffset(100, false);
|
||||
this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false);
|
||||
TKUnit.waitUntilReady(function () { return scrollX > 0; });
|
||||
TKUnit.assertEqual(scrollX, this.testView.horizontalOffset);
|
||||
TKUnit.assertEqual(scrollX, layoutHelper.dp(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user