diff --git a/app/feature/feature-terminate-insurance/build.gradle.kts b/app/feature/feature-terminate-insurance/build.gradle.kts index cbf3aa70d1..345aa5034d 100644 --- a/app/feature/feature-terminate-insurance/build.gradle.kts +++ b/app/feature/feature-terminate-insurance/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("hedvig.android.library") + alias(libs.plugins.paparazzi) id("hedvig.gradle.plugin") } @@ -10,7 +11,15 @@ hedvig { } android { + androidResources.enable = true + testOptions.unitTests.isReturnDefaultValues = true + + testOptions { + unitTests { + isIncludeAndroidResources = true + } + } } dependencies { diff --git a/app/feature/feature-terminate-insurance/src/main/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestination.kt b/app/feature/feature-terminate-insurance/src/main/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestination.kt index 9be0afec44..473b555c61 100644 --- a/app/feature/feature-terminate-insurance/src/main/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestination.kt +++ b/app/feature/feature-terminate-insurance/src/main/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestination.kt @@ -69,7 +69,7 @@ internal fun ChooseInsuranceToTerminateDestination( } @Composable -private fun ChooseInsuranceToTerminateScreen( +internal fun ChooseInsuranceToTerminateScreen( uiState: ChooseInsuranceToTerminateStepUiState, navigateUp: () -> Unit, reload: () -> Unit, diff --git a/app/feature/feature-terminate-insurance/src/test/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestinationSnapshotTest.kt b/app/feature/feature-terminate-insurance/src/test/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestinationSnapshotTest.kt new file mode 100644 index 0000000000..db16a2852b --- /dev/null +++ b/app/feature/feature-terminate-insurance/src/test/kotlin/com/hedvig/android/feature/terminateinsurance/step/choose/ChooseInsuranceToTerminateDestinationSnapshotTest.kt @@ -0,0 +1,275 @@ +package com.hedvig.android.feature.terminateinsurance.step.choose + +import androidx.compose.runtime.Composable +import app.cash.paparazzi.DeviceConfig +import app.cash.paparazzi.Paparazzi +import com.android.ide.common.rendering.api.SessionParams.RenderingMode +import com.hedvig.android.data.contract.ContractGroup +import com.hedvig.android.data.termination.data.TerminatableInsurance +import com.hedvig.android.design.system.hedvig.HedvigTheme +import com.hedvig.android.design.system.hedvig.Surface +import org.junit.Rule +import org.junit.Test + +/** + * Paparazzi Snapshot Testing Commands: + * + * Record/Update snapshots: + * `./gradlew recordPaparazziDebug` + * + * Verify snapshots: + * `./gradlew verifyPaparazziDebug` + * + * Snapshot location: app/feature/feature-terminate-insurance/src/test/snapshots/images/ + */ +class ChooseInsuranceToTerminateDestinationSnapshotTest { + + @get:Rule + val paparazzi = Paparazzi( + deviceConfig = DeviceConfig.PIXEL_5, + renderingMode = RenderingMode.SHRINK, + showSystemUi = false, + ) + + @Test + fun loadingState() { + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Loading, + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun failureState() { + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Failure, + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun notAllowedState() { + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.NotAllowed, + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun successStateWithNoSelection() { + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Success( + nextStepWithInsurance = null, + insuranceList = listOf( + TerminatableInsurance( + id = "1", + displayName = "Homeowner Insurance", + contractExposure = "Opulullegatan 19", + contractGroup = ContractGroup.HOUSE, + ), + TerminatableInsurance( + id = "2", + displayName = "Tenant Insurance", + contractExposure = "Bullegatan 23", + contractGroup = ContractGroup.RENTAL, + ), + ), + selectedInsurance = null, + isNavigationStepLoading = false, + navigationStepFailedToLoad = false, + ), + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun successStateWithSelection() { + val selectedInsurance = TerminatableInsurance( + id = "2", + displayName = "Tenant Insurance", + contractExposure = "Bullegatan 23", + contractGroup = ContractGroup.RENTAL, + ) + + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Success( + nextStepWithInsurance = null, + insuranceList = listOf( + TerminatableInsurance( + id = "1", + displayName = "Homeowner Insurance", + contractExposure = "Opulullegatan 19", + contractGroup = ContractGroup.HOUSE, + ), + selectedInsurance, + ), + selectedInsurance = selectedInsurance, + isNavigationStepLoading = false, + navigationStepFailedToLoad = false, + ), + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun successStateWithLoadingNextStep() { + val selectedInsurance = TerminatableInsurance( + id = "1", + displayName = "Homeowner Insurance", + contractExposure = "Opulullegatan 19", + contractGroup = ContractGroup.HOUSE, + ) + + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Success( + nextStepWithInsurance = null, + insuranceList = listOf(selectedInsurance), + selectedInsurance = selectedInsurance, + isNavigationStepLoading = true, + navigationStepFailedToLoad = false, + ), + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun successStateWithNavigationError() { + val selectedInsurance = TerminatableInsurance( + id = "1", + displayName = "Homeowner Insurance", + contractExposure = "Opulullegatan 19", + contractGroup = ContractGroup.HOUSE, + ) + + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Success( + nextStepWithInsurance = null, + insuranceList = listOf(selectedInsurance), + selectedInsurance = selectedInsurance, + isNavigationStepLoading = false, + navigationStepFailedToLoad = true, + ), + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Test + fun successStateWithMultipleInsurances() { + paparazzi.snapshot { + TestWrapper { + ChooseInsuranceToTerminateScreen( + uiState = ChooseInsuranceToTerminateStepUiState.Success( + nextStepWithInsurance = null, + insuranceList = listOf( + TerminatableInsurance( + id = "1", + displayName = "Homeowner Insurance", + contractExposure = "Opulullegatan 19", + contractGroup = ContractGroup.HOUSE, + ), + TerminatableInsurance( + id = "2", + displayName = "Tenant Insurance", + contractExposure = "Bullegatan 23", + contractGroup = ContractGroup.RENTAL, + ), + TerminatableInsurance( + id = "3", + displayName = "Car Insurance", + contractExposure = "Tesla Model 3, ABC123", + contractGroup = ContractGroup.CAR, + ), + TerminatableInsurance( + id = "4", + displayName = "Travel Insurance", + contractExposure = "Annual worldwide coverage", + contractGroup = ContractGroup.ACCIDENT, + ), + ), + selectedInsurance = null, + isNavigationStepLoading = false, + navigationStepFailedToLoad = false, + ), + navigateUp = {}, + reload = {}, + openChat = {}, + closeTerminationFlow = {}, + fetchTerminationStep = {}, + selectInsurance = {}, + ) + } + } + } + + @Composable + private fun TestWrapper(content: @Composable () -> Unit) { + HedvigTheme { + Surface(color = HedvigTheme.colorScheme.backgroundPrimary) { + content() + } + } + } +} diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_failureState.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_failureState.png new file mode 100644 index 0000000000..8dcdb62e89 Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_failureState.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_loadingState.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_loadingState.png new file mode 100644 index 0000000000..39a93d97d2 Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_loadingState.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_notAllowedState.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_notAllowedState.png new file mode 100644 index 0000000000..b41aa12e92 Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_notAllowedState.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithLoadingNextStep.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithLoadingNextStep.png new file mode 100644 index 0000000000..eec04fdcae Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithLoadingNextStep.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithMultipleInsurances.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithMultipleInsurances.png new file mode 100644 index 0000000000..5659609ad8 Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithMultipleInsurances.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithNavigationError.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithNavigationError.png new file mode 100644 index 0000000000..dd6787dcc5 Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithNavigationError.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithNoSelection.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithNoSelection.png new file mode 100644 index 0000000000..ee4839fd69 Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithNoSelection.png differ diff --git a/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithSelection.png b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithSelection.png new file mode 100644 index 0000000000..e15fd30f7e Binary files /dev/null and b/app/feature/feature-terminate-insurance/src/test/snapshots/images/com.hedvig.android.feature.terminateinsurance.step.choose_ChooseInsuranceToTerminateDestinationSnapshotTest_successStateWithSelection.png differ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7f37a4bcdb..af0e0548f4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -70,6 +70,7 @@ navigationRecentsUrlSharing = "1.0.0" okhttpBom = "5.1.0" okio = "3.16.0" paging = "3.3.6" +paparazzi = "2.0.0-SNAPSHOT" playReview = "2.0.2" playServicesBase = "18.7.2" retrofit = "3.0.0" @@ -262,6 +263,7 @@ kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } license = { id = "com.jaredsburrows.license", version.ref = "license" } lintGradlePlugin = { id = "com.android.lint", version.ref = "lintGradlePlugin" } +paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" } room = { id = "androidx.room", version.ref = "room" } serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } skie = { id = "co.touchlab.skie", version.ref = "skie" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 3bba8590de..5ec1277e07 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ pluginManagement { } } gradlePluginPortal() + maven("https://central.sonatype.com/repository/maven-snapshots/") } } @@ -25,6 +26,7 @@ dependencyResolutionManagement { } mavenCentral() maven("https://jitpack.io") + maven("https://central.sonatype.com/repository/maven-snapshots/") } }