Skip to content

Commit 9388a4e

Browse files
authored
test(ios): add repeater and webview safe area tests (#6578)
1 parent f90995f commit 9388a4e

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed

tests/app/testRunner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ allTests["FLEXBOXLAYOUT"] = flexBoxLayoutTests;
136136
import * as safeAreaLayoutTests from "./ui/layouts/safe-area-tests";
137137
import * as safeAreaListViewtTests from "./ui/list-view/list-view-safe-area-tests";
138138
import * as scrollViewSafeAreaTests from "./ui/scroll-view/scroll-view-safe-area-tests";
139+
import * as repeaterSafeAreaTests from "./ui/repeater/repeater-safe-area-tests";
140+
import * as webViewSafeAreaTests from "./ui/web-view/web-view-safe-area-tests";
139141

140142
if (platform.isIOS && ios.MajorVersion > 10) {
141143
allTests["SAFEAREALAYOUT"] = safeAreaLayoutTests;
142144
allTests["SAFEAREA-LISTVIEW"] = safeAreaListViewtTests;
143145
allTests["SAFEAREA-SCROLL-VIEW"] = scrollViewSafeAreaTests;
146+
allTests["SAFEAREA-REPEATER"] = repeaterSafeAreaTests;
147+
allTests["SAFEAREA-WEBVIEW"] = webViewSafeAreaTests;
144148
}
145149

146150
import * as stylePropertiesTests from "./ui/styling/style-properties-tests";
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import * as helper from "../helper";
2+
import * as TKUnit from "../../TKUnit";
3+
import { parse } from "tns-core-modules/ui/builder";
4+
import * as view from "tns-core-modules/ui/core/view";
5+
import * as platform from "tns-core-modules/platform";
6+
import { Repeater } from "tns-core-modules/ui/repeater";
7+
import { ios as iosUtils } from "tns-core-modules/utils/utils";
8+
import { UITest } from "../../ui-test";
9+
import {
10+
dipToDp, left, top, right, bottom, height, width,
11+
equal, check, lessOrCloseEnough, greaterOrCloseEnough,
12+
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith
13+
} from "../layouts/layout-tests-helper";
14+
15+
export class RepeaterSafeAreaTest extends UITest<Repeater> {
16+
17+
private executeSnippet<U extends { root: view.View }>(ui: U, setup: (ui: U) => void, test: (ui: U) => void, pageOptions?: helper.PageOptions): void {
18+
function waitUntilTestElementLayoutIsValid(view: view.View, timeoutSec?: number): void {
19+
TKUnit.waitUntilReady(() => {
20+
return view.isLayoutValid;
21+
}, timeoutSec || 1);
22+
}
23+
24+
setup(ui);
25+
helper.buildUIAndRunTest(ui.root, () => {
26+
waitUntilTestElementLayoutIsValid(ui.root);
27+
test(ui);
28+
}, pageOptions);
29+
};
30+
31+
private noop() {
32+
// no operation
33+
};
34+
35+
private getViews(template: string) {
36+
let root = parse(template);
37+
return {
38+
root,
39+
list: root.getViewById("repeater") as Repeater
40+
};
41+
};
42+
43+
private repeater_in_full_screen(repeater: Repeater, pageOptions?: helper.PageOptions) {
44+
let expectedTop = 0;
45+
if (pageOptions && pageOptions.actionBarFlat) {
46+
const actionBarHeight = round(dipToDp(repeater.page.actionBar.nativeViewProtected.frame.size.height));
47+
const app = iosUtils.getter(UIApplication, UIApplication.sharedApplication);
48+
const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height));
49+
expectedTop = actionBarHeight + statusBarHeight;
50+
}
51+
52+
const l = left(repeater);
53+
const t = top(repeater);
54+
const r = right(repeater);
55+
const b = bottom(repeater);
56+
equal(l, 0, `${repeater}.left - actual:${l}; expected: ${0}`);
57+
equal(t, expectedTop, `${repeater}.top - actual:${t}; expected: ${expectedTop}`);
58+
equal(r, platform.screen.mainScreen.widthPixels, `${repeater}.right - actual:${r}; expected: ${platform.screen.mainScreen.widthPixels}`);
59+
equal(b, platform.screen.mainScreen.heightPixels, `${repeater}.bottom - actual:${b}; expected: ${platform.screen.mainScreen.heightPixels}`);
60+
}
61+
62+
private repeater_in_full_screen_test(pageOptions?: helper.PageOptions) {
63+
const snippet = `
64+
<Repeater id="repeater" loaded="onLoaded" backgroundColor="Crimson"></Repeater>
65+
`;
66+
this.executeSnippet(
67+
this.getViews(snippet),
68+
this.noop,
69+
({ list }) => {
70+
this.repeater_in_full_screen(list, pageOptions);
71+
},
72+
pageOptions
73+
);
74+
}
75+
76+
public test_repeater_in_full_screen_action_bar() {
77+
this.repeater_in_full_screen_test({ actionBar: true });
78+
}
79+
80+
public test_repeater_in_full_screen_action_bar_hidden() {
81+
this.repeater_in_full_screen_test({ actionBarHidden: true });
82+
}
83+
84+
public test_repeater_in_full_screen_action_bar_flat() {
85+
this.repeater_in_full_screen_test({ actionBarFlat: true });
86+
}
87+
88+
public test_repeater_in_full_screen_tab_bar() {
89+
this.repeater_in_full_screen_test({ tabBar: true });
90+
}
91+
}
92+
93+
export function createTestCase(): RepeaterSafeAreaTest {
94+
return new RepeaterSafeAreaTest();
95+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import * as helper from "../helper";
2+
import * as TKUnit from "../../TKUnit";
3+
import { parse } from "tns-core-modules/ui/builder";
4+
import * as view from "tns-core-modules/ui/core/view";
5+
import * as platform from "tns-core-modules/platform";
6+
import { WebView } from "tns-core-modules/ui/web-view";
7+
import { ios as iosUtils } from "tns-core-modules/utils/utils";
8+
import { UITest } from "../../ui-test";
9+
import {
10+
dipToDp, left, top, right, bottom, height, width,
11+
equal, check, lessOrCloseEnough, greaterOrCloseEnough,
12+
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith
13+
} from "../layouts/layout-tests-helper";
14+
15+
export class WebViewSafeAreaTest extends UITest<WebView> {
16+
17+
private executeSnippet<U extends { root: view.View }>(ui: U, setup: (ui: U) => void, test: (ui: U) => void, pageOptions?: helper.PageOptions): void {
18+
function waitUntilTestElementLayoutIsValid(view: view.View, timeoutSec?: number): void {
19+
TKUnit.waitUntilReady(() => {
20+
return view.isLayoutValid;
21+
}, timeoutSec || 1);
22+
}
23+
24+
setup(ui);
25+
helper.buildUIAndRunTest(ui.root, () => {
26+
waitUntilTestElementLayoutIsValid(ui.root);
27+
test(ui);
28+
}, pageOptions);
29+
};
30+
31+
private noop() {
32+
// no operation
33+
};
34+
35+
private getViews(template: string) {
36+
let root = parse(template);
37+
return {
38+
root,
39+
list: root.getViewById("webview") as WebView
40+
};
41+
};
42+
43+
private webview_in_full_screen(webView: WebView, pageOptions?: helper.PageOptions) {
44+
let expectedTop = 0;
45+
if (pageOptions && pageOptions.actionBarFlat) {
46+
const actionBarHeight = round(dipToDp(webView.page.actionBar.nativeViewProtected.frame.size.height));
47+
const app = iosUtils.getter(UIApplication, UIApplication.sharedApplication);
48+
const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height));
49+
expectedTop = actionBarHeight + statusBarHeight;
50+
}
51+
52+
const l = left(webView);
53+
const t = top(webView);
54+
const r = right(webView);
55+
const b = bottom(webView);
56+
equal(l, 0, `${webView}.left - actual:${l}; expected: ${0}`);
57+
equal(t, expectedTop, `${webView}.top - actual:${t}; expected: ${expectedTop}`);
58+
equal(r, platform.screen.mainScreen.widthPixels, `${webView}.right - actual:${r}; expected: ${platform.screen.mainScreen.widthPixels}`);
59+
equal(b, platform.screen.mainScreen.heightPixels, `${webView}.bottom - actual:${b}; expected: ${platform.screen.mainScreen.heightPixels}`);
60+
}
61+
62+
private webview_in_full_screen_test(pageOptions?: helper.PageOptions) {
63+
const snippet = `
64+
<WebView id="webview" loaded="onLoaded" backgroundColor="Crimson"></WebView>
65+
`;
66+
this.executeSnippet(
67+
this.getViews(snippet),
68+
this.noop,
69+
({ list }) => {
70+
this.webview_in_full_screen(list, pageOptions);
71+
},
72+
pageOptions
73+
);
74+
}
75+
76+
public test_webview_in_full_screen_action_bar() {
77+
this.webview_in_full_screen_test({ actionBar: true });
78+
}
79+
80+
public test_webview_in_full_screen_action_bar_hidden() {
81+
this.webview_in_full_screen_test({ actionBarHidden: true });
82+
}
83+
84+
public test_webview_in_full_screen_action_bar_flat() {
85+
this.webview_in_full_screen_test({ actionBarFlat: true });
86+
}
87+
88+
public test_webview_in_full_screen_tab_bar() {
89+
this.webview_in_full_screen_test({ tabBar: true });
90+
}
91+
}
92+
93+
export function createTestCase(): WebViewSafeAreaTest {
94+
return new WebViewSafeAreaTest();
95+
}

0 commit comments

Comments
 (0)