Fix scroll-view-tests

This commit is contained in:
Hristo Hristov
2017-10-24 16:13:49 +03:00
parent 3a5006db10
commit 6cff5f4796

View File

@ -57,7 +57,7 @@ class ScrollLayoutTest extends UITest<ScrollView> {
if (isIOS) { if (isIOS) {
TKUnit.assert(this.testView.ios instanceof UIScrollView, "ios property is UIScrollView"); TKUnit.assert(this.testView.ios instanceof UIScrollView, "ios property is UIScrollView");
} else { } else {
TKUnit.assert(this.testView.android instanceof org.nativescript.widgets.HorizontalScrollView, "android property should be instanceof org.nativescript.widgets.HorizontalScrollView"); TKUnit.assert(this.testView.android instanceof org.nativescript.widgets.HorizontalScrollView, "android property should be instanceof org.nativescript.widgets.HorizontalScrollView");
} }
} }
@ -145,30 +145,34 @@ class ScrollLayoutTest extends UITest<ScrollView> {
public test_scrollView_persistsState_vertical() { public test_scrollView_persistsState_vertical() {
this.waitUntilTestElementLayoutIsValid(); this.waitUntilTestElementLayoutIsValid();
const expected = layoutHelper.dp(100); this.testView.scrollToVerticalOffset(90, false);
this.testView.scrollToVerticalOffset(expected, false); this.waitUntilTestElementLayoutIsValid();
// TKUnit.assertAreClose(this.testView.verticalOffset, expected, 0.1, "this.testView.verticalOffset before navigation");
const offset = Math.floor(this.testView.verticalOffset);
// assert we did scroll;
TKUnit.assertTrue(offset > 22, "this.testView.verticalOffset before navigation should be >22");
helper.navigateWithHistory(() => new Page()); helper.navigateWithHistory(() => new Page());
helper.goBack(); helper.goBack();
// Check verticalOffset after navigation // Check verticalOffset after navigation
TKUnit.assertAreClose(this.testView.verticalOffset, expected, 0.1, "this.testView.verticalOffset after navigation"); TKUnit.assertEqual(Math.floor(this.testView.verticalOffset), offset, "this.testView.verticalOffset after navigation");
} }
public test_scrollView_persistsState_horizontal() { public test_scrollView_persistsState_horizontal() {
this.testView.orientation = "horizontal"; this.testView.orientation = "horizontal";
this.waitUntilTestElementLayoutIsValid(); this.waitUntilTestElementLayoutIsValid();
this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false); this.testView.scrollToHorizontalOffset(100, false);
const offset = this.testView.horizontalOffset;
TKUnit.assertAreClose(layoutHelper.dip(this.testView.horizontalOffset), 100, 0.1, "this.testView.horizontalOffset before navigation"); // assert we did scroll;
TKUnit.assertTrue(offset > 22, "this.testView.horizontalOffset before navigation should be >22");
helper.navigateWithHistory(() => new Page()); helper.navigateWithHistory(() => new Page());
helper.goBack(); helper.goBack();
// Check horizontalOffset after navigation // Check horizontalOffset after navigation
TKUnit.assertAreClose(layoutHelper.dip(this.testView.horizontalOffset), 100, 0.1, "this.testView.horizontalOffset after navigation"); TKUnit.assertEqual(this.testView.horizontalOffset, 100, "this.testView.horizontalOffset after navigation");
} }
public test_scrollView_vertical_raised_scroll_event() { public test_scrollView_vertical_raised_scroll_event() {