qdsfdhvh / compose-imageloader

Compose Image library for Kotlin Multiplatform.
https://qdsfdhvh.github.io/compose-imageloader/
MIT License
441 stars 15 forks source link

no image in Paparazzi snapshot #367

Open fbattet opened 1 year ago

fbattet commented 1 year ago

I'm trying to write a Paparazzi ui test, but no image is displayed :

my test :

class TempTest {
    private fun generateImageLoader() = ImageLoader {
        interceptor {
            useDefaultInterceptors = false
            addInterceptor { ImageResult.OfPainter(ColorPainter(Color.Green)) }
        }
    }

    @get:Rule
    val paparazzi = Paparazzi(
        deviceConfig = DeviceConfig.PIXEL_6,
        theme = "android:Theme.Material.NoActionBar",
    )

    @Test
    fun launchComposable() {
        paparazzi.snapshot {
            CompositionLocalProvider(LocalImageLoader provides remember { generateImageLoader() }) {
                AutoSizeImage("", null, modifier = Modifier.size(200.dp))
            }
        }
    }
}

PS : I managed to write this kind of test with Coil

qdsfdhvh commented 1 year ago

The problem seems to be in AsyncSizeResolver, For now workaround you can try this:

// rememberImagePainter will not auto set AsyncSizeResolver
Image(
    rememberImagePainter("", imageLoader = imageLoader),
    contentDescription = "image",
    modifier = Modifier.size(100.dp),
)
// or
AutoSizeImage(
    ImageRequest("") {
        // set custom SizeResolver
        size(SizeResolver(Size(100f, 100f)))
    },
    contentDescription = "image",
    modifier = Modifier.size(100.dp),
    imageLoader = imageLoader,
)
fbattet commented 1 year ago

Neither works.

qdsfdhvh commented 1 year ago

https://github.com/qdsfdhvh/compose-imageloader/pull/368 here is my test code, maybe it helps.

fbattet commented 1 year ago

I got it

all tests
./gradlew composeApp:recordPaparazziDebug
individual test
./gradlew composeApp:recordPaparazziDebug --tests="SampleTest"
mockmp + koin-test
mockative + koin-test
koint-test
mockmp
mockative

Thank you for your help.

qdsfdhvh commented 1 year ago

Sorry, I don't see the other side on my phone, I'll test it later ./gradlew composeApp:recordPaparazziDebug --tests="SampleTest"

qdsfdhvh commented 1 year ago

https://github.com/qdsfdhvh/compose-imageloader/pull/368/commits/ec4071a95a2faa7525d754ce169c20c8283f3e54 replace imageLoader dispatcher maybe is a way.