diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - App Language Not Available.png b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - App Language Not Available.png new file mode 100644 index 0000000000..6f4fe955da --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - App Language Not Available.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c063f4e68d7ccc301983f03479b18de19aee278925d84622bed4db997c6970c1 +size 46304 diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Default.png b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Default.png new file mode 100644 index 0000000000..83679cbd6f --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Default.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7e068b022bc8e2e2ee76e0c95334738930e674dce3b1090ce57a2e27d53a73a +size 44787 diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - No second Language.png b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - No second Language.png new file mode 100644 index 0000000000..9d068f49f9 --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - No second Language.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfc60c73cb924bc0194cb1916f452a21cb68f8ba195a1dd745aa34f38db6040f +size 44042 diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Second Language Not Available.png b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Second Language Not Available.png new file mode 100644 index 0000000000..df7752d25b --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Second Language Not Available.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab51ae777d9ad9de7a1730094295ee9d62ca1417fc1a46f99dcf33307fe80428 +size 46286 diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Selected.png b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Selected.png new file mode 100644 index 0000000000..ab52eda53d --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.tools_VariantToolCardPaparazziTest_VariantToolCard() - Selected.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7580ffa64894918dc113d53d7113a38aad422e3d3a82368134765213cce36594 +size 44939 diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardPaparazziTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardPaparazziTest.kt new file mode 100644 index 0000000000..066d5ff97c --- /dev/null +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardPaparazziTest.kt @@ -0,0 +1,123 @@ +package org.cru.godtools.ui.tools + +import android.graphics.drawable.Drawable +import androidx.compose.foundation.layout.Box +import androidx.compose.ui.Alignment +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.model.Language +import org.cru.godtools.model.randomTool +import org.cru.godtools.model.randomTranslation +import org.junit.Rule + +class VariantToolCardPaparazziTest { + @get:Rule + val paparazzi = Paparazzi() + + private val toolState = ToolCard.State( + tool = randomTool( + name = "Tool Title", + description = "Description of tool", + ), + banner = mockk(), + availableLanguages = 1234, + appLanguage = Language(Locale.ENGLISH), + appTranslation = randomTranslation(), + secondLanguage = Language(Locale.FRENCH), + secondLanguageAvailable = true, + ) + + @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 `VariantToolCard() - Default`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + Box(contentAlignment = Alignment.Center) { + VariantToolCard(state = toolState) + } + } + } + } + + @Test + fun `VariantToolCard() - Selected`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + Box(contentAlignment = Alignment.Center) { + VariantToolCard(state = toolState, isSelected = true) + } + } + } + } + + @Test + fun `VariantToolCard() - No second Language`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + Box(contentAlignment = Alignment.Center) { + VariantToolCard(state = toolState.copy(secondLanguage = null, secondLanguageAvailable = false)) + } + } + } + } + + @Test + fun `VariantToolCard() - App Language Not Available`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + Box(contentAlignment = Alignment.Center) { + VariantToolCard(state = toolState.copy(appTranslation = null)) + } + } + } + } + + @Test + fun `VariantToolCard() - Second Language Not Available`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + Box(contentAlignment = Alignment.Center) { + VariantToolCard(state = toolState.copy(secondLanguageAvailable = false)) + } + } + } + } +}