diff --git a/zoomable-image/coil/src/androidTest/kotlin/me/saket/telephoto/zoomable/coil/CoilImageSourceTest.kt b/zoomable-image/coil/src/androidTest/kotlin/me/saket/telephoto/zoomable/coil/CoilImageSourceTest.kt index 71b801a8..159da49e 100644 --- a/zoomable-image/coil/src/androidTest/kotlin/me/saket/telephoto/zoomable/coil/CoilImageSourceTest.kt +++ b/zoomable-image/coil/src/androidTest/kotlin/me/saket/telephoto/zoomable/coil/CoilImageSourceTest.kt @@ -256,6 +256,67 @@ class CoilImageSourceTest { } } + @Test fun uses_updated_async_placeholder_size_when_available() = runTest { + val imageUrl = serverRule.server.url("/slow_placeholder_image.png") + lateinit var state: ZoomableImageState + var displayImage by mutableStateOf(false) + var placeholderLoaded = false + + rule.setContent { + state = rememberZoomableImageState() + + val placeholderPainter = rememberAsyncImagePainter( + model = ImageRequest.Builder(context) + .data(imageUrl) + .allowHardware(false) // Unsupported by Screenshot.capture() + .listener( + onSuccess = { _, _ -> + placeholderLoaded = true + } + ) + .build() + ) + val source = object : ZoomableImageSource { + @Composable + override fun resolve(canvasSize: Flow): ResolveResult { + val delegate = remember(displayImage) { + if (displayImage) { + ZoomableImageSource.SubSamplingDelegate(SubSamplingImageSource.asset("night_watch_14000.jpg")) + } else { + null + } + } + + return ResolveResult( + delegate = delegate, + placeholder = placeholderPainter, + ) + } + } + + ZoomableImage( + modifier = Modifier + .fillMaxSize() + .testTag("image"), + image = source, + contentDescription = null, + state = state, + ) + } + + rule.waitUntil(5.seconds) { placeholderLoaded } + rule.waitForIdle() + rule.runOnIdle { + dropshots.assertSnapshot(rule.activity, name = "${testName.methodName}_placeholder") + } + displayImage = true + rule.waitForIdle() + rule.waitUntil(5.seconds) { state.isImageDisplayed } + rule.runOnIdle { + dropshots.assertSnapshot(rule.activity, name = "${testName.methodName}_full_image") + } + } + @Test fun reload_image_when_image_request_changes() = runTest { var imageUrl by mutableStateOf(serverRule.server.url("placeholder_image.png")) @@ -393,67 +454,6 @@ class CoilImageSourceTest { } } - @Test fun loads_placeholder_for_subsampled_image() = runTest { - val imageUrl = serverRule.server.url("/slow_placeholder_image.png") - lateinit var state: ZoomableImageState - var displayImage by mutableStateOf(false) - var placeholderLoaded = false - - rule.setContent { - state = rememberZoomableImageState() - - val placeholderPainter = rememberAsyncImagePainter( - model = ImageRequest.Builder(context) - .data(imageUrl) - .allowHardware(false) // Unsupported by Screenshot.capture() - .listener( - onSuccess = { _, _ -> - placeholderLoaded = true - } - ) - .build() - ) - val source = object : ZoomableImageSource { - @Composable - override fun resolve(canvasSize: Flow): ResolveResult { - val delegate = remember(displayImage) { - if (displayImage) { - ZoomableImageSource.SubSamplingDelegate(SubSamplingImageSource.asset("night_watch_14000.jpg")) - } else { - null - } - } - - return ResolveResult( - delegate = delegate, - placeholder = placeholderPainter, - ) - } - } - - ZoomableImage( - modifier = Modifier - .fillMaxSize() - .testTag("image"), - image = source, - contentDescription = null, - state = state, - ) - } - - rule.waitUntil(5.seconds) { placeholderLoaded } - rule.waitForIdle() - rule.runOnIdle { - dropshots.assertSnapshot(rule.activity, name = "${testName.methodName}_placeholder") - } - displayImage = true - rule.waitForIdle() - rule.waitUntil(5.seconds) { state.isImageDisplayed } - rule.runOnIdle { - dropshots.assertSnapshot(rule.activity, name = "${testName.methodName}_full_image") - } - } - context(TestScope) private fun resolve( canvasSize: Size = Size(1080f, 1920f), diff --git a/zoomable-image/coil/src/androidTest/screenshots/loads_placeholder_for_subsampled_image_full_image.png b/zoomable-image/coil/src/androidTest/screenshots/uses_updated_async_placeholder_size_when_available_full_image.png similarity index 100% rename from zoomable-image/coil/src/androidTest/screenshots/loads_placeholder_for_subsampled_image_full_image.png rename to zoomable-image/coil/src/androidTest/screenshots/uses_updated_async_placeholder_size_when_available_full_image.png diff --git a/zoomable-image/coil/src/androidTest/screenshots/loads_placeholder_for_subsampled_image_placeholder.png b/zoomable-image/coil/src/androidTest/screenshots/uses_updated_async_placeholder_size_when_available_placeholder.png similarity index 100% rename from zoomable-image/coil/src/androidTest/screenshots/loads_placeholder_for_subsampled_image_placeholder.png rename to zoomable-image/coil/src/androidTest/screenshots/uses_updated_async_placeholder_size_when_available_placeholder.png