Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a211bbd

Browse files
authored
test(safe-area): fix ios 12 landscape tests (NativeScript#6434)
1 parent c0438df commit a211bbd

File tree

5 files changed

+83
-21
lines changed

5 files changed

+83
-21
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export function lessOrCloseEnough(a: number, b: number, message?: string) {
3939
message ? TKUnit.assertTrue(less || close, message) : TKUnit.assertTrue(less || close);
4040
}
4141

42+
export function greaterOrCloseEnough(a: number, b: number, message?: string) {
43+
const greater = a > b;
44+
const close = Math.abs(a - b) <= EPS;
45+
message ? TKUnit.assertTrue(greater || close, message) : TKUnit.assertTrue(greater || close);
46+
}
47+
4248
export function notEqual<T>(a: T, b: T, message?: string) {
4349
message ? TKUnit.assertNotEqual(a, b, message) : TKUnit.assertNotEqual(a, b);
4450
}

tests/app/ui/layouts/safe-area-tests.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as helper from "../helper";
88
import { parse } from "tns-core-modules/ui/builder";
99
import {
1010
dipToDp, left, top, right, bottom, height, width,
11-
equal, closeEnough, lessOrCloseEnough, check,
11+
equal, closeEnough, lessOrCloseEnough, greaterOrCloseEnough, check,
1212
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
1313
isLeftWith, isAboveWith, isRightWith, isBelowWith
1414
} from "./layout-tests-helper";
@@ -1011,13 +1011,15 @@ export class SafeAreaTests extends testModule.UITest<any> {
10111011
isBottomAlignedWith(grid, cells[2][1]);
10121012
isBottomAlignedWith(grid, cells[2][2]);
10131013

1014-
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
1015-
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
1014+
greaterOrCloseEnough(height(cells[0][1]), height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or close enough cell11 height<${height(cells[1][1])}>`);
1015+
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or close enough cell21 height<${height(cells[2][1])}>`);
1016+
10161017
const sumOfNestedGridHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
10171018
equal(height(grid), sumOfNestedGridHeights, `grid height<${height(grid)}> sum of nested grids height <${sumOfNestedGridHeights}>`);
10181019

1019-
check(width(cells[1][0]) >= width(cells[1][1]), `cell10 width<${width(cells[1][0])}> not greater or equal cell11 width<${width(cells[1][1])}>`);
1020-
check(width(cells[1][1]) <= width(cells[1][2]), `cell11 width<${width(cells[1][1])}> not less or equal cell12 width<${width(cells[1][2])}>`);
1020+
greaterOrCloseEnough(width(cells[1][0]), width(cells[1][1]), `cell10 width<${width(cells[1][0])}> not greater or close enough cell11 width<${width(cells[1][1])}>`);
1021+
lessOrCloseEnough(width(cells[1][1]), width(cells[1][2]), `cell11 width<${width(cells[1][1])}> not less or close enough cell12 width<${width(cells[1][2])}>`);
1022+
10211023
const sumOfNestedGridWidths = width(cells[1][0]) + width(cells[1][1]) + width(cells[1][2])
10221024
equal(width(grid), sumOfNestedGridWidths, `grid width<${width(grid)}> sum of nested grids width <${sumOfNestedGridWidths}>`);
10231025
},
@@ -1364,8 +1366,8 @@ export class SafeAreaTests extends testModule.UITest<any> {
13641366

13651367
private wrap_horizontal_children_components_in_safe_area(pageOptions?: helper.PageOptions) {
13661368
const snippet = `
1367-
<WrapLayout id="wrap" orientation="horizontal">
1368-
<Button id="child0" text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet" height="100%"></Button>
1369+
<WrapLayout id="wrap" orientation="horizontal" backgroundColor="Crimson">
1370+
<Button id="child0" text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet." height="100%"></Button>
13691371
<Button id="child1" text="H" backgroundColor="Pink"></Button>
13701372
</WrapLayout>
13711373
`;
@@ -1400,8 +1402,8 @@ export class SafeAreaTests extends testModule.UITest<any> {
14001402

14011403
private wrap_vertical_children_components_in_safe_area(pageOptions?: helper.PageOptions) {
14021404
const snippet = `
1403-
<WrapLayout id="wrap" orientation="vertical">
1404-
<Button id="child0" text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet" height="100%"></Button>
1405+
<WrapLayout id="wrap" orientation="vertical" backgroundColor="Crimson">
1406+
<Button id="child0" text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet." height="100%"></Button>
14051407
<Button id="child1" text="V" backgroundColor="Pink"></Button>
14061408
</WrapLayout>
14071409
`;
@@ -1438,7 +1440,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
14381440
const snippet = `
14391441
<WrapLayout id="wrap" backgroundColor="Crimson">
14401442
<WrapLayout id="child0" backgroundColor="SkyBlue">
1441-
<Button text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"/>
1443+
<Button text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet."/>
14421444
</WrapLayout>
14431445
</WrapLayout>
14441446
`;

tests/app/ui/list-view/list-view-safe-area-tests.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ViewModel } from "./list-view-view-model";
99
import { UITest } from "../../ui-test";
1010
import {
1111
dipToDp, left, top, right, bottom, height, width,
12-
equal, check, lessOrCloseEnough,
12+
equal, check, lessOrCloseEnough, greaterOrCloseEnough,
1313
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith
1414
} from "../layouts/layout-tests-helper";
1515

@@ -182,13 +182,15 @@ export class ListViewSafeAreaTest extends UITest<ListView> {
182182
isRightAlignedWith(root, cells[1][2]);
183183
isRightAlignedWith(root, cells[2][2]);
184184

185-
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
186-
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
185+
greaterOrCloseEnough(height(cells[0][1]), height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or close enough cell11 height<${height(cells[1][1])}>`);
186+
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or close enough cell21 height<${height(cells[2][1])}>`);
187+
187188
const sumOfNestedListViewHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
188189
equal(height(root), sumOfNestedListViewHeights, `grid height<${height(root)}> sum of nested list views height <${sumOfNestedListViewHeights}>`);
189190

190-
check(width(cells[1][0]) >= width(cells[1][1]), `cell10 width<${width(cells[1][0])}> not greater or equal cell11 width<${width(cells[1][1])}>`);
191-
check(width(cells[1][1]) <= width(cells[1][2]), `cell11 width<${width(cells[1][1])}> not less or equal cell12 width<${width(cells[1][2])}>`);
191+
greaterOrCloseEnough(width(cells[1][0]), width(cells[1][1]), `cell10 width<${width(cells[1][0])}> not greater or close enough cell11 width<${width(cells[1][1])}>`);
192+
lessOrCloseEnough(width(cells[1][1]), width(cells[1][2]), `cell11 width<${width(cells[1][1])}> not less or close enough cell12 width<${width(cells[1][2])}>`);
193+
192194
const sumOfNestedListViewWidths = width(cells[1][0]) + width(cells[1][1]) + width(cells[1][2])
193195
equal(width(root), sumOfNestedListViewWidths, `grid width<${width(root)}> sum of nested list views width <${sumOfNestedListViewWidths}>`);
194196
},

tests/app/ui/page/page-tests-common.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ function _test_WhenInnerViewCallsCloseModal(closeModalGetter: (ShownModallyData)
497497
helper.navigate(masterPageFactory);
498498

499499
TKUnit.waitUntilReady(() => modalClosedWithResult);
500+
501+
if (isIOS) {
502+
// Remove this line when we have a good way to detect actual modal close on ios
503+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
504+
}
500505
}
501506

502507
export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal() {
@@ -554,10 +559,16 @@ export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal()
554559
helper.navigate(masterPageFactory);
555560

556561
TKUnit.waitUntilReady(() => modalClosed);
562+
563+
if (isIOS) {
564+
// Remove this line when we have a good way to detect actual modal close on ios
565+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
566+
}
557567
}
558568

559569
export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
560570
let navigatedTo = false;
571+
let modalThrows = false;
561572

562573
const createTabItems = function(count: number) {
563574
var items = new Array<TabViewItem>();
@@ -581,7 +592,11 @@ export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
581592

582593
const hostPage = <Page>args.object;
583594
const tabViewItem = (<TabView>page.content).items[0];
584-
TKUnit.assertThrows(() => tabViewItem.showModal());
595+
try {
596+
tabViewItem.showModal();
597+
} catch (e) {
598+
modalThrows = true;
599+
}
585600

586601
navigatedTo = true;
587602
}
@@ -601,6 +616,7 @@ export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
601616
helper.navigate(masterPageFactory);
602617

603618
TKUnit.waitUntilReady(() => navigatedTo);
619+
TKUnit.assertTrue(modalThrows);
604620
}
605621

606622
export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() {
@@ -696,6 +712,11 @@ export function test_WhenRootTabViewShownModallyItCanCloseModal() {
696712
helper.navigate(masterPageFactory);
697713

698714
TKUnit.waitUntilReady(() => modalClosed);
715+
716+
if (isIOS) {
717+
// Remove this line when we have a good way to detect actual modal close on ios
718+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
719+
}
699720
}
700721

701722
export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
@@ -775,6 +796,11 @@ export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
775796
TKUnit.assertEqual(modalUnloaded, 1, "modalUnloaded");
776797

777798
masterPage.off(Page.navigatedToEvent, navigatedToEventHandler);
799+
800+
if (isIOS) {
801+
// Remove this line when we have a good way to detect actual modal close on ios
802+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
803+
}
778804
}
779805

780806
export function test_WhenModalPageShownHostPageNavigationEventsShouldNotBeRaised() {
@@ -846,6 +872,11 @@ export function test_WhenModalPageShownHostPageNavigationEventsShouldNotBeRaised
846872

847873
TKUnit.waitUntilReady(() => ready);
848874

875+
if (isIOS) {
876+
// Remove this line when we have a good way to detect actual modal close on ios
877+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
878+
}
879+
849880
// only raised by the initial navigation to the master page
850881
TKUnit.assertTrue(hostNavigatingToCount === 1);
851882
TKUnit.assertTrue(hostNavigatedToCount === 1);
@@ -926,6 +957,11 @@ export function test_WhenModalPageShownModalNavigationToEventsShouldBeRaised() {
926957

927958
TKUnit.waitUntilReady(() => ready && !modalFrame.isLoaded);
928959

960+
if (isIOS) {
961+
// Remove this line when we have a good way to detect actual modal close on ios
962+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
963+
}
964+
929965
// only raised by the initial show modal navigation
930966
TKUnit.assertTrue(modalNavigatingToCount === 1);
931967
TKUnit.assertTrue(modalNavigatedToCount === 1);
@@ -996,6 +1032,11 @@ export function test_WhenModalFrameShownModalEventsRaisedOnRootModalFrame() {
9961032

9971033
TKUnit.waitUntilReady(() => ready && !modalFrame.isLoaded);
9981034

1035+
if (isIOS) {
1036+
// Remove this line when we have a good way to detect actual modal close on ios
1037+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
1038+
}
1039+
9991040
TKUnit.assertTrue(showingModallyCount === 1);
10001041
TKUnit.assertTrue(shownModallyCount === 1);
10011042
}
@@ -1053,6 +1094,11 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalPage() {
10531094

10541095
TKUnit.waitUntilReady(() => ready);
10551096

1097+
if (isIOS) {
1098+
// Remove this line when we have a good way to detect actual modal close on ios
1099+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
1100+
}
1101+
10561102
TKUnit.assertTrue(showingModallyCount === 1);
10571103
TKUnit.assertTrue(shownModallyCount === 1);
10581104
}
@@ -1115,6 +1161,11 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalTabView()
11151161

11161162
TKUnit.waitUntilReady(() => ready);
11171163

1164+
if (isIOS) {
1165+
// Remove this line when we have a good way to detect actual modal close on ios
1166+
TKUnit.waitUntilReady(() => !(<UIViewController>topmost().currentPage.viewController).presentedViewController);
1167+
}
1168+
11181169
TKUnit.assertEqual(stack().length, 1, "Single host frame should be instantiated at this point!");
11191170

11201171
TKUnit.assertTrue(showingModallyCount === 1);

tests/app/ui/scroll-view/scroll-view-safe-area-tests.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as helper from "../helper";
1010
import { parse } from "tns-core-modules/ui/builder";
1111
import {
1212
dipToDp, left, top, right, bottom, height, width,
13-
equal, check, lessOrCloseEnough,
13+
equal, check, lessOrCloseEnough, greaterOrCloseEnough,
1414
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
1515
isLeftWith, isRightWith, isBelowWith
1616
} from "../layouts/layout-tests-helper";
@@ -425,13 +425,14 @@ class ScrollLayoutSafeAreaTest extends UITest<ScrollView> {
425425
isBottomAlignedWith(grid, cells[2][1]);
426426
isBottomAlignedWith(grid, cells[2][2]);
427427

428-
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
429-
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
428+
greaterOrCloseEnough(height(cells[0][1]), height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or close enough cell11 height<${height(cells[1][1])}>`);
429+
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or close enough cell21 height<${height(cells[2][1])}>`);
430+
430431
const sumOfNestedScrollViewHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
431432
equal(height(grid), sumOfNestedScrollViewHeights, `grid height<${height(grid)}> sum of nested scroll views height <${sumOfNestedScrollViewHeights}>`);
432433

433-
check(width(cells[1][0]) >= width(cells[1][1]), `cell10 width<${width(cells[1][0])}> not greater or equal cell11 width<${width(cells[1][1])}>`);
434-
check(width(cells[1][1]) <= width(cells[1][2]), `cell11 width<${width(cells[1][1])}> not less or equal cell12 width<${width(cells[1][2])}>`);
434+
greaterOrCloseEnough(width(cells[1][0]), width(cells[1][1]), `cell10 width<${width(cells[1][0])}> not greater or close enough cell11 width<${width(cells[1][1])}>`);
435+
lessOrCloseEnough(width(cells[1][1]), width(cells[1][2]), `cell11 width<${width(cells[1][1])}> not less or close enough cell12 width<${width(cells[1][2])}>`);
435436
const sumOfNestedScrollViewWidths = width(cells[1][0]) + width(cells[1][1]) + width(cells[1][2])
436437
equal(width(grid), sumOfNestedScrollViewWidths, `grid width<${width(grid)}> sum of nested scroll views width <${sumOfNestedScrollViewWidths}>`);
437438
},

0 commit comments

Comments
 (0)