Skip to content

Commit

Permalink
add some paparazzi tests for SquareToolCards
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Mar 8, 2024
1 parent b305ccf commit c451908
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ dependencies {
testImplementation(libs.androidx.arch.core.testing)
testImplementation(libs.androidx.lifecycle.runtime.testing)
testImplementation(libs.androidx.test.espresso.core)
testImplementation(libs.coil.test)
testImplementation(libs.gtoSupport.testing.dagger)
testImplementation(libs.hilt.testing)
testImplementation(libs.kotlin.coroutines.test)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.cru.godtools.ui.tools

import android.graphics.drawable.Drawable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import app.cash.paparazzi.Paparazzi
import coil.Coil
import coil.ImageLoader
import coil.annotation.ExperimentalCoilApi
import coil.test.FakeImageLoaderEngine
import io.mockk.mockk
import java.util.Locale
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.cru.godtools.base.ui.theme.GodToolsTheme
import org.cru.godtools.downloadmanager.DownloadProgress
import org.cru.godtools.model.Language
import org.cru.godtools.model.Tool
import org.cru.godtools.model.randomTool
import org.cru.godtools.model.randomTranslation
import org.junit.Rule

class SquareToolCardPaparazziTest {
@get:Rule
val paparazzi = Paparazzi()

private val toolState = ToolCard.State(
tool = randomTool(
name = "Tool Title",
category = Tool.CATEGORY_GOSPEL,
),
banner = mockk(),
secondLanguage = Language(Locale.FRENCH),
secondTranslation = randomTranslation()
)

@BeforeTest
@OptIn(ExperimentalCoilApi::class, ExperimentalCoroutinesApi::class)
fun setup() {
Dispatchers.setMain(UnconfinedTestDispatcher())
val banner = Drawable.createFromStream(javaClass.getResourceAsStream("banner.jpg"), "banner.jpg")!!
Coil.setImageLoader(
ImageLoader.Builder(paparazzi.context)
.components {
add(
FakeImageLoaderEngine.Builder()
.intercept(toolState.banner!!, banner)
.build()
)
}
.build()
)
}

@AfterTest
@OptIn(ExperimentalCoroutinesApi::class)
fun cleanup() {
Coil.reset()
Dispatchers.resetMain()
}

@Test
fun `SquareToolCard() - Default`() {
paparazzi.snapshot {
GodToolsTheme(disableDagger = true) {
Box {
SquareToolCard(
state = toolState,
modifier = Modifier.align(Alignment.Center),
)
}
}
}
}

@Test
fun `SquareToolCard() - Downloading`() {
paparazzi.snapshot {
GodToolsTheme(disableDagger = true) {
Box {
SquareToolCard(
state = toolState.copy(
downloadProgress = DownloadProgress(2, 5)
),
modifier = Modifier.align(Alignment.Center),
)
}
}
}
}

@Test
fun `SquareToolCard() - Show Second Language`() {
paparazzi.snapshot {
GodToolsTheme(disableDagger = true) {
Box {
SquareToolCard(
state = toolState,
showSecondLanguage = true,
modifier = Modifier.align(Alignment.Center),
)
}
}
}
}
}
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ androidx-room = "2.6.1"
androidx-viewpager2 = "1.0.0"
androidx-work = "2.9.0"
circuit = "0.19.1"
coil = "2.6.0"
dagger = "2.51"
eventbus = "3.3.1"
facebook = "16.3.0"
Expand Down Expand Up @@ -88,7 +89,8 @@ circuit-foundation = { module = "com.slack.circuit:circuit-foundation", version.
circuit-test = { module = "com.slack.circuit:circuit-test", version.ref = "circuit" }
circuitx-android = { module = "com.slack.circuit:circuitx-android", version.ref = "circuit" }
circuitx-effects = { module = "com.slack.circuit:circuitx-effects", version.ref = "circuit" }
coil-compose = "io.coil-kt:coil-compose:2.6.0"
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
coil-test = { module = "io.coil-kt:coil-test", version.ref = "coil" }
compose-reorderable = "org.burnoutcrew.composereorderable:reorderable:0.9.6"
dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" }
dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" }
Expand Down

0 comments on commit c451908

Please sign in to comment.