Hi Team, I have been using Paparazzi for snapshot tests of our views built using Jetpack compose. We are using Reflections API to scan the code to find the method annotated with previews. These methods are then passed to Paparazzi for snapshot tests. Can we have capability of passing parameters to previews using ParameterPreviewProvider class from previews to snapshot tests. Is it possible ?. What about different previews that got generated with annotations like @PreviewScreenSizes, @PreviewFontScales, @PreviewLightDark, and @PreviewDynamicColors .
Here is my paparazzi snapshot test class
`class PaparazziTest {
@get:Rule
val paparazzi: Paparazzi = Paparazzi()
@Test
fun generateSnapshots() {
val reflections = Reflections("xxx.zpreview", Scanners.MethodsAnnotated)
val methods = reflections.getMethodsAnnotatedWith(Preview::class.java)
.filterNot { java.lang.reflect.Modifier.isPrivate(it.modifiers) }
val composeProxy = ComposeProxy()
for (method in methods) {
val name = "${method.declaringClass.simpleName}_${method.name}"
try {
snapshot(name = name) {
composeProxy.wrappedInstance(method).GenerateSnapshot()
}
} catch (e: Throwable) {
throw RuntimeException("Error generating snapshot $name", e)
}
}
}
private fun snapshot(name: String, composable: @Composable () -> Unit) {
paparazzi.snapshot(name) {
Box {
composable()
}
}
}
private interface ComposeProxyInterface {
@Composable
fun GenerateSnapshot()
}
@Suppress("EmptyFunctionBlock")
private class ComposeProxy : ComposeProxyInterface {
@Composable
override fun GenerateSnapshot() {
}
fun wrappedInstance(composableFunction: Method): ComposeProxyInterface {
val proxyClass = Proxy.getProxyClass(
ComposeProxy::class.java.classLoader,
ComposeProxyInterface::class.java
)
val invocationHandler = InvocationHandler { _, _, args: Array<out Any>? ->
composableFunction.invoke(null, *args!!)
}
return proxyClass
.getConstructor(InvocationHandler::class.java)
.newInstance(invocationHandler) as ComposeProxyInterface
}
}
Hi Team, I have been using Paparazzi for snapshot tests of our views built using Jetpack compose. We are using Reflections API to scan the code to find the method annotated with previews. These methods are then passed to Paparazzi for snapshot tests. Can we have capability of passing parameters to previews using ParameterPreviewProvider class from previews to snapshot tests. Is it possible ?. What about different previews that got generated with annotations like @PreviewScreenSizes, @PreviewFontScales, @PreviewLightDark, and @PreviewDynamicColors .
Here is my paparazzi snapshot test class
`class PaparazziTest {
}`