Tom Koptel
10/23/2024, 12:18 PMGlideImage
in Paparazzi env?
In test I am loading image from src/test/resources
dir.
@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.skydoves
10/23/2024, 1:12 PMTom Koptel
10/23/2024, 1:23 PMif (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?