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

Consider passing RoborazziOptions to Compose Preview Support #447

Open
takahirom opened this issue Jul 27, 2024 · 3 comments
Open

Consider passing RoborazziOptions to Compose Preview Support #447

takahirom opened this issue Jul 27, 2024 · 3 comments

Comments

@takahirom
Copy link
Owner

My suggestion is to create a roborazziOptions(): RoborazziOptions function in the tester interface to set up the RoborazziOptions. However, we might want to access the annotations of the Preview function within roborazziOptions(). We could pass a ComposablePreview instance as a parameter, but I'm unsure if there's a more efficient approach.

@sergio-sastre
Copy link
Contributor

This would be for default options right?
For options applying to a single Preview, I’d bet the best is to provide a @ RoborazziConfig annotation with params matching the options -and annotate your @ Previews with it.

then you can get that info via

AndroidComposablePreviewScanner()
  …
  .includeAnnotationInfoForAllOf(RoborazziConfig::class.java)

and map them in the tests with
ComposablePreview<AndroidPreview>.getAnnotation<RoborazziConfig>()

You can find some examples here:

https://github.com/sergio-sastre/Android-screenshot-testing-playground/tree/master/lazycolumnscreen-previews/roborazzi/src

@takahirom
Copy link
Owner Author

takahirom commented Jul 27, 2024

Thanks! I believe we have two main use cases for this:

  1. Users can set up tests using @RoborazziConfig. We should add @RoborazziConfig to allow users to configure tests using a prepared annotation, as you suggested.
(In Roborazzi)
annotation class RoborazziConfig(xxxx)

class AndroidComposePreviewTester : ComposePreviewTester<AndroidPreviewInfo> {
  // This will be a new method of ComposePreviewTester
  override fun roborazziOptions(): RoborazziOptions {
     // How to access the composablePreview here?
     // options().composablePreview or passing as a parameter
     val someOptions = composablePreview.getAnnotation<RoborazziConfig>().xxxx
     return RoborazziOptions(xxx)
  }

  override fun test(composablePreview) {
      val roborazziOptions = roborazziOptions()
...
  }
}

https://github.com/takahirom/roborazzi/blob/main/roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt#L85C1-L85C34 (The current implementation of AndroidComposePreviewTester)

  1. Users want to set the default diff tolerance or their custom annotations
(In user project)
class MyCustomComposePreviewTester : ComposePreviewTester<AndroidPreviewInfo> by AndroidComposePreviewTester() {
  override fun roborazziOptions(): RoborazziOptions {
     // How to access the composablePreview here?
     // options().composablePreview or passing as a parameter
     val someOptions = composablePreview.getAnnotation<UserCustomConfig>().xxxx
     return RoborazziOptions(xxx)
  }
}

I think we need to consider adding a new roborazziOptions() method to the tester interface and determine how we can pass composablePreview to roborazziOptions(), or explore other approaches.

@sergio-sastre
Copy link
Contributor

sergio-sastre commented Jul 27, 2024

So for me there are 3 use cases then:

  1. Default Roborazzi options, set in the plugin
  2. Per test Roborazzi Options set via a @RoborazziConfig provided by Roborazzi
  3. Per test Roborazzi Options set via a custom annotation

I'd focus first on providing options 1 & 2
3rd is definitely harder to maintain and for more advanced users. I'd rather add it later, if ever.

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

No branches or pull requests

2 participants