android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
15.92k stars 2.81k forks source link

Add DeviceConfigurationOverride for insets to allow screenshot testing insets #1498

Closed alexvanyo closed 2 days ago

alexvanyo commented 3 weeks ago

This adds a way to test for #1295, by creating a DeviceConfigurationOverride.WindowInsets that allows injecting arbitrary window insets for content under test.

By using this override in host-side screenshot tests to inject a non-zero amount of system bar insets on all sides, we can visually show how the snackbar is not being inset properly, and can be obscured by the system insets.

This is a prototype for the upstream request for a DeviceConfigurationOverride.WindowInsets: https://issuetracker.google.com/343474632

github-actions[bot] commented 3 weeks ago

Combined test coverage report

Overall Project 41.4% :green_apple:

There is no coverage information present for the Files changed

github-actions[bot] commented 3 weeks ago

Combined test coverage report

Overall Project 41.37% :green_apple:

There is no coverage information present for the Files changed

github-actions[bot] commented 3 weeks ago

Combined test coverage report

Overall Project 41.4% :green_apple:

There is no coverage information present for the Files changed

Jaehwa-Noh commented 3 weeks ago

I have a question. I used WindowInsets.safeDrawing.getBottom to avoid the System UI in https://github.com/android/nowinandroid/pull/1296/files#diff-3fcb081475d70c62cae861a437429902dd21cd40067b7b52ec0c9c5184a1bf06R90-R95

val density = LocalDensity.current val bottomSystemUiHeight = density.run { WindowInsets.safeDrawing .getBottom(density = density) .toDp() }

If I set the windowInsets like yours to test, the windowInsets would be set to the safeDrawing? Is there any way to set SafeDrawing manually?


Aha, I found the code you set the navigation insets. https://github.com/android/nowinandroid/pull/1498/files#diff-b76aa2071cc8cc921b26f6a03e5c8679ca440ea7b1950fecfe58f57d6abeaa3aR253-R260

.setInsets( WindowInsetsCompat.Type.navigationBars(), DpRect( left = 64.dp, top = 0.dp, right = 64.dp, bottom = 64.dp, ).toInsets(),