From 5f96ffe7d99016811e1dce575a37c83400b80fe1 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Wed, 22 Mar 2023 12:14:21 -0300 Subject: [PATCH] test: fix safe area tests on iOS (#10240) --- .../automated/src/ui/layouts/safe-area-tests.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/automated/src/ui/layouts/safe-area-tests.ts b/apps/automated/src/ui/layouts/safe-area-tests.ts index 9b990e55a..ffed6c663 100644 --- a/apps/automated/src/ui/layouts/safe-area-tests.ts +++ b/apps/automated/src/ui/layouts/safe-area-tests.ts @@ -70,10 +70,14 @@ export class SafeAreaTests extends testModule.UITest { } private layout_insets_top_action_bar_test(layout: view.View) { - const app = UIApplication.sharedApplication; - const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height)); - const actionBarHeight = round(dipToDp(layout.page.actionBar.nativeViewProtected.frame.size.height)); - const topInset = statusBarHeight + actionBarHeight; + // const app = UIApplication.sharedApplication; + // const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height)); + // const actionBarHeight = round(dipToDp(layout.page.actionBar.nativeViewProtected.frame.size.height)); + // const topInset = statusBarHeight + actionBarHeight; + + const view: UIView = layout.page.actionBar.nativeViewProtected; + // use the action bar position and size instead of the status bar and action bar heights as those are unreliable on iOS 16+ + const topInset = round(dipToDp(view.frame.origin.y + view.frame.size.height)); const insets = layout.getSafeAreaInsets(); equal(insets.top, topInset, `${layout}.topInset - actual:${insets.top}; expected: ${topInset}`); @@ -81,8 +85,9 @@ export class SafeAreaTests extends testModule.UITest { private layout_insets_top_action_bar_hidden_test(layout: view.View) { const app = UIApplication.sharedApplication; - const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height)); - const topInset = statusBarHeight; + // const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height)); + // use window inset instead of status bar frame as that's unreliable on iOS 16+ + const topInset = round(dipToDp(app.keyWindow.safeAreaInsets.top)); const insets = layout.getSafeAreaInsets(); equal(insets.top, topInset, `${layout}.topInset - actual:${insets.top}; expected: ${topInset}`);