Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix density handling in robolectric screenshot tests. #1828

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

yschimke
Copy link
Collaborator

WHAT

Fix density handling in robolectric screenshot tests.

WHY

Current code doesn't correctly handle the Samsung device with a density > 2

HOW

Checklist 📋

  • Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • Update metalava's signature text files

@yschimke yschimke requested a review from luizgrp November 22, 2023 05:42
@yschimke
Copy link
Collaborator Author

@luizgrp landing as a test fix, will follow up with review comments.

@yschimke yschimke merged commit 61404ae into google:main Nov 22, 2023
Copy link
Member

@luizgrp luizgrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

fun Context.setDisplayScale(density: Float) = apply {
// Modified from https://sergiosastre.hashnode.dev/efficient-testing-with-robolectric-roborazzi-across-many-ui-states-devices-and-configurations?ref=twitter-share
val config = Configuration(resources.configuration)
config.densityDpi = (density * 160f).toInt()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extract magic number to a constant to make it explicit it represents "display scale" and explain why this value

@yschimke yschimke deleted the fix_density branch December 18, 2023 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants