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

The name of the screenshot file #1033

Closed
michwar opened this issue Aug 2, 2023 · 6 comments
Closed

The name of the screenshot file #1033

michwar opened this issue Aug 2, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@michwar
Copy link

michwar commented Aug 2, 2023

Description
I found a problem with file names when we have already added some golden screen values to our repo but then we want to add another one, the previous one may change its name which causes a lot of changes in git history.
The problem causes an integer number placed before a group name.
e.g. {path}[1.{groupName}:{name},1.1,1.light]
The integer number should not be associated with the to not affect other previews?

Is there any way to define screen name by myself? Or add any regex or change the current pattern?
Or other way that will not change the old value when we add now one.

Steps to Reproduce
Add some golden values. Push them to the repo. Add another preview, generate golden values for them.

Expected behavior
The new files should not affect on the old ones.

Additional information:

  • Paparazzi Version: 1.3.1
  • Compile SDK: 33
  • Android Gradle Plugin Version: 8.1.0

@edit
I found that the problem is caused by @PreviewParameter. When composable preview has a @PreviewParameter argument, the method name contains an integer but in non-deterministic way. Thats why after any change in previews many of screenshot files change their names

@michwar michwar added the bug Something isn't working label Aug 2, 2023
@michwar michwar changed the title The name of the file The name of the screenshot file Aug 2, 2023
@SumeraMartin
Copy link

SumeraMartin commented Aug 11, 2023

I just found out that I have the same problem. It seems like that all of my previews has this index in the name even when only few of them are using preview parameter so not sure if it is related. But I'm using MultiPreview so that could be the issues.

I did some small change which moved all the indexes and suddenly almost all of my previews are marked as changed due filename change. I wonder if this is related to Paparazzi or Showkase 🤔

Edit:

seems like a paparazzi issues since name generated from the showkase doesn't contain index:
my.very.long.package.name_ScreenshotTest_test[1.MainButtonPreview1 - 0_d=0_fs=1.0]
which is basically the following information
{package_name}_{class_name}_{test_name}[{index}{showkase_name}]

@SumeraMartin
Copy link

Also, as I feel that it is related to this, it would be nice to be able to customize the name of the snapshot. My app has a long a package name which causes that name is too long without any additional value.

@michwar
Copy link
Author

michwar commented Aug 11, 2023

As I found in the code the part {test_name}[{index}{showkase_name}] is the method name because the delimiter is delimiter: String = "_"
Try to override ComponentPreview.toString() and return ShowkaseBrowserComponent.componentKey

@SumeraMartin
Copy link

I'm already doing this:

data class ScreenshotTestData(
    val component: ShowkaseBrowserComponent,
    val isDarkMode: Boolean,
    val fontSize: Float,
) {
    override fun toString(): String {
        val key = component.componentName
        val darkMode = if (isDarkMode) "1" else "0"
        return "${key}_d=${darkMode}_fs=$fontSize"
    }
}

This generates a string like MainButtonPreview1 - 0_d=0_fs=1.0. The [1.{}] and other parts are generated by Paparazzi.

However, I've just realized that in my case, the reason this index is present isn't due to PreviewParameter, but rather TestParameter from the TestParameterInjector library. I've drawn inspiration from this combination of tools: https://proandroiddev.com/automatic-screenshot-testing-for-all-your-compose-previews-6add202fecc7, which includes Paparazzi, Showkase, and TestParameterInjector.

@SumeraMartin
Copy link

I was able to solve my issue by realising that some of my previews had the same name so TestParameterInjection automatically added indexing. When I get rid of these then it started to work fine.

@jrodbx
Copy link
Collaborator

jrodbx commented Jan 19, 2024

Duplicate of #549

@jrodbx jrodbx marked this as a duplicate of #549 Jan 19, 2024
@jrodbx jrodbx closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants