Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/feature/feature-terminate-insurance/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("hedvig.android.library")
alias(libs.plugins.paparazzi)
id("hedvig.gradle.plugin")
}

Expand All @@ -10,7 +11,15 @@ hedvig {
}

android {
androidResources.enable = true

testOptions.unitTests.isReturnDefaultValues = true

testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal fun ChooseInsuranceToTerminateDestination(
}

@Composable
private fun ChooseInsuranceToTerminateScreen(
internal fun ChooseInsuranceToTerminateScreen(
uiState: ChooseInsuranceToTerminateStepUiState,
navigateUp: () -> Unit,
reload: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
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.
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.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pluginManagement {
}
}
gradlePluginPortal()
maven("https://central.sonatype.com/repository/maven-snapshots/")
}
}

Expand All @@ -25,6 +26,7 @@ dependencyResolutionManagement {
}
mavenCentral()
maven("https://jitpack.io")
maven("https://central.sonatype.com/repository/maven-snapshots/")
}
}

Expand Down
Loading