Skip to content

Commit

Permalink
Fix image loading in test
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Jun 26, 2024
1 parent 7c110b5 commit ca12096
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation(libs.daggerHiltAndroidTesting)
implementation(libs.roborazzi)
implementation(libs.kermit)
implementation(libs.coilTest)
api(projects.core.testingManifest)
api(libs.composeNavigation)
api(libs.roborazziRule)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.droidkaigi.confsched.testing

import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
Expand All @@ -12,6 +13,10 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.rules.ActivityScenarioRule
import co.touchlab.kermit.CommonWriter
import co.touchlab.kermit.Logger
import coil3.ImageLoader
import coil3.SingletonImageLoader
import coil3.test.FakeImageLoaderEngine
import coil3.test.default
import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.RoborazziOptions.CompareOptions
import com.github.takahirom.roborazzi.RoborazziOptions.PixelBitConfig
Expand Down Expand Up @@ -108,6 +113,18 @@ class RobotTestRule(
),
),
)
.around(object : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
val engine = FakeImageLoaderEngine.Builder()
.default(ColorDrawable(android.graphics.Color.BLUE))
.build()
val imageLoader = ImageLoader.Builder(ApplicationProvider.getApplicationContext())
.components { add(engine) }
.build()
SingletonImageLoader.setUnsafe(imageLoader)
}
})
.around(composeTestRule)
.apply(base, description)
}
Expand Down
2 changes: 1 addition & 1 deletion core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kotlin {
implementation(projects.core.data)
implementation(libs.kermit)
api(projects.core.common)
api(libs.composeImageLoader)
api(libs.coil)
api(libs.kotlinxDatetime)
implementation(libs.moleculeRuntime)
implementation(libs.coreBundle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package io.github.droidkaigi.confsched.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import com.seiko.imageloader.rememberImagePainter

@Composable
fun rememberAsyncImagePainter(url: String): Painter {
return rememberImagePainter(url = url)
return coil3.compose.rememberAsyncImagePainter(
model = url,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.seiko.imageloader.rememberImagePainter
import io.github.droidkaigi.confsched.model.Timetable
import io.github.droidkaigi.confsched.model.TimetableItem
import io.github.droidkaigi.confsched.model.TimetableRoom.Shapes.CIRCLE
Expand All @@ -46,6 +45,7 @@ import io.github.droidkaigi.confsched.model.TimetableRoom.Shapes.SHARP_DIAMOND
import io.github.droidkaigi.confsched.model.TimetableRoom.Shapes.SQUARE
import io.github.droidkaigi.confsched.sessions.TimetableListItemBookmarkIconTestTag
import io.github.droidkaigi.confsched.sessions.TimetableListItemTestTag
import io.github.droidkaigi.confsched.ui.rememberAsyncImagePainter
import kotlinx.collections.immutable.PersistentMap

const val TimetableListTestTag = "TimetableList"
Expand Down Expand Up @@ -144,7 +144,7 @@ fun TimetableList(
timetableItem.speakers.forEach { speaker ->
Row {
// TODO: This style of image loading was included by default but it seems slow
val painter = rememberImagePainter(speaker.iconUrl)
val painter = rememberAsyncImagePainter(speaker.iconUrl)
Image(
painter = painter,
modifier = Modifier
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ kover = "0.7.6"
androidxLifecycleProcess = "2.8.2"
skie = "0.8.2"
composablePreviewScanner = "0.1.1"
coil = "3.0.0-alpha06"

[libraries]
androidGradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
Expand Down Expand Up @@ -107,8 +108,8 @@ composeNavigation = { module = "org.jetbrains.androidx.navigation:navigation-com
coreBundle = { module = "org.jetbrains.androidx.core:core-bundle", version = "1.0.0-alpha01" }
composeHiltNavigtation = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "composeHiltNavigatiaon" }
composeLintCheck = { module = "com.slack.lint.compose:compose-lint-checks", version = "1.3.1" }
composeCoil = { module = "io.coil-kt:coil-compose", version = "2.4.0" }
composeImageLoader = { module = "io.github.qdsfdhvh:image-loader", version = "1.6.7" }
coil = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coilTest = { module = "io.coil-kt.coil3:coil-test", version.ref = "coil" }
composeShimmer = { module = "com.valentinilk.shimmer:compose-shimmer", version = "1.0.5" }
rin = { module = "io.github.takahirom.rin:rin", version.ref = "rin" }
lottieCompose = { module = "com.airbnb.android:lottie-compose", version.ref = "lottie" }
Expand Down

0 comments on commit ca12096

Please sign in to comment.