Hello <@US0N1RBAM> :wave: I hope you are doing goo...
# compose-android
t
Hello @skydoves 👋 I hope you are doing good. Let me know if this question belongs to some other source (maybe Stackoverflow or Github repo). The question regarding landscapist. I am trying to create a snapshot test using Paparazzi. The Landscapist uses Glide to perform loading. Any thoughts on how to approach generation of snapshots for
GlideImage
in Paparazzi env?
In test I am loading image from
src/test/resources
dir.
Copy code
@Test
fun image() {
    val classLoader = this::class.java.classLoader!!
    val hostView = ComposeView(RenderAction.getCurrentContext()).apply {
        setContent {
                GlideImage(
                    modifier = Modifier
                        .height(64.dp)
                        .width(64.dp),
                    imageModel = {
                        classLoader.getResource("face.png").toURI().toString()
                    },
                )
        }
    }
//  paparazzi.gif(hostView, end = 1_000L)
    paparazzi.snapshot(hostView)
}
I’ve changed test to
paparazzi.gif(hostView, end = 1_000L)
.
gif
runs a while loop until all frames exhausted and records frames into APNG(Animated PNG). With the help of a debug tool I’ve sneak picked inside the runtime. Glide instantiates then sends jobs to diskCacheExecutor. The GlideImage receives
GlideImageState.None
,
GlideImageState.Loading
,
GlideImageState.Success
at different frames. So far it makes sense, because that is how the component works in real life. We first see empty preview and then Bitmap drawn on Canvas. I am looking for the way to advance ahead to
GlideImageState.Success
and then make a snapshot(wait for image loaded, make a screenshot). The problem is that I can not come up with any smart way to exhaust all work sent to MAIN_DISPATCHER used by WindowRecomposer + wait for the diskCacheExecutor IDLE state. P.S. I’ve attached APNG generate with
gif
. On MacOs you can see dedicated frames.
s
Hi @Tom Koptel, have you had a chance to read the documentation on Snapshots with Paparazzi?
👀 1
t
I see, so you are proposing to not go extra mile of loading image with Glide and instead stick to force preview mode + dummy placeholder.
Copy code
if (LocalInspectionMode.current && previewPlaceholder != null) {
    with(imageOptions) {
      Image(
        modifier = modifier,
        painter = previewPlaceholder,
        alignment = alignment,
        contentScale = contentScale,
        alpha = alpha,
        colorFilter = colorFilter,
        contentDescription = contentDescription,
      )
      return
    }
  }
This will work for sure. Though it want be enough in case when we need to capture the outcome of
transform()
API used by Glide to manipulate final Bitmap (e.g. CircleCrop()). With the
LocalInspectionMode
set to true this won’t be possible, so, unfortunatelly, this won’t work for me. Maybe Paparazzi snapshot tests is not a good pick here 🤷 and I need to either stick to Robolectric + Roborazzi or old school Android instrumentation test. Any ideas/thoughts on how to properly e2e test Landscapist + Glide combo?