Skip to content

Commit 5511282

Browse files
committed
chore(test): zero out safe-area insets in test environments
1 parent 4fe98a4 commit 5511282

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

core/scripts/testing/scripts.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@
4848
document.head.appendChild(style);
4949
}
5050

51+
/**
52+
* Zero out safe-area insets in test environments.
53+
* The default 20px --ion-safe-area-top from core.scss is for legacy
54+
* status bar simulation but doesn't represent real browser behavior.
55+
* Tests that need to verify safe-area handling should explicitly set
56+
* these values in their test HTML files.
57+
*/
58+
const safeAreaStyle = document.createElement('style');
59+
safeAreaStyle.innerHTML = `
60+
:root {
61+
--ion-safe-area-top: 0px;
62+
--ion-safe-area-bottom: 0px;
63+
--ion-safe-area-left: 0px;
64+
--ion-safe-area-right: 0px;
65+
}
66+
`;
67+
document.head.appendChild(safeAreaStyle);
68+
5169
/**
5270
* The `palette` param is used to load a specific palette
5371
* for the theme.

core/src/components/app/test/safe-area/app.e2e.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ configs({ directions: ['ltr'] }).forEach(({ config, title, screenshot }) => {
5353
// Remove the safe area class
5454
html.classList.remove('safe-area');
5555

56-
// Set the safe area inset variables
56+
// Set the Capacitor safe area inset variables.
57+
// Also set --ion-safe-area-* directly since test environments zero these out,
58+
// which would prevent the CSS var() cascade from working.
5759
html.style.setProperty('--safe-area-inset-top', '10px');
5860
html.style.setProperty('--safe-area-inset-bottom', '20px');
5961
html.style.setProperty('--safe-area-inset-left', '30px');
6062
html.style.setProperty('--safe-area-inset-right', '40px');
63+
html.style.setProperty('--ion-safe-area-top', 'var(--safe-area-inset-top)');
64+
html.style.setProperty('--ion-safe-area-bottom', 'var(--safe-area-inset-bottom)');
65+
html.style.setProperty('--ion-safe-area-left', 'var(--safe-area-inset-left)');
66+
html.style.setProperty('--ion-safe-area-right', 'var(--safe-area-inset-right)');
6167
});
6268

6369
const top = await page.evaluate(() =>

0 commit comments

Comments
 (0)