Skip to content

Commit

Permalink
StartPresenterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
panasetskaya committed Jan 10, 2025
1 parent e5d4c14 commit caad170
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,35 @@ class GetQuickLinksUseCaseTest {
}

@Test
fun `when response says cannot change tier should not contain ChangeTier quickAction`() =
runTest {
val featureManager = FakeFeatureManager2(fixedReturnForAll = true)
val getMemberActionsUseCase = FakeGetMemberActionsUseCase()
getMemberActionsUseCase.turbine.add(fakeMemberActionWithoutTier.right())
val useCase = GetQuickLinksUseCase(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
getMemberActionsUseCase = getMemberActionsUseCase,
)
val result = useCase.invoke()
val listNotEmpty = result.getOrNull()?.isNotEmpty() ?: false
assertk.assertThat(listNotEmpty).isTrue()
assertk
.assertThat(result)
.isRight()
.transform { list ->
list.filterIsInstance<MultiSelectExpandedLink>()
.none {
it.links.contains(
QuickAction.StandaloneQuickLink(
quickLinkDestination = QuickLinkDestination.OuterDestination.QuickLinkChangeTier,
titleRes = R.string.HC_QUICK_ACTIONS_UPGRADE_COVERAGE_TITLE,
hintTextRes = R.string.HC_QUICK_ACTIONS_UPGRADE_COVERAGE_SUBTITLE,
),
)
}
}
.isTrue()
}
fun `when response says cannot change tier should not contain ChangeTier quickAction`() = runTest {
val featureManager = FakeFeatureManager2(fixedReturnForAll = true)
val getMemberActionsUseCase = FakeGetMemberActionsUseCase()
getMemberActionsUseCase.turbine.add(fakeMemberActionWithoutTier.right())
val useCase = GetQuickLinksUseCase(
apolloClient = apolloClientWithGoodResponse,
featureManager = featureManager,
getMemberActionsUseCase = getMemberActionsUseCase,
)
val result = useCase.invoke()
val listNotEmpty = result.getOrNull()?.isNotEmpty() ?: false
assertk.assertThat(listNotEmpty).isTrue()
assertk
.assertThat(result)
.isRight()
.transform { list ->
list.filterIsInstance<MultiSelectExpandedLink>()
.none {
it.links.contains(
QuickAction.StandaloneQuickLink(
quickLinkDestination = QuickLinkDestination.OuterDestination.QuickLinkChangeTier,
titleRes = R.string.HC_QUICK_ACTIONS_UPGRADE_COVERAGE_TITLE,
hintTextRes = R.string.HC_QUICK_ACTIONS_UPGRADE_COVERAGE_SUBTITLE,
),
)
}
}
.isTrue()
}
}

private class FakeGetMemberActionsUseCase : GetMemberActionsUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private fun ContractDetailScreen(
CoverageTab(
state.insuranceContract.currentInsuranceAgreement.productVariant.insurableLimits,
state.insuranceContract.currentInsuranceAgreement.productVariant.perils,
state.insuranceContract.currentInsuranceAgreement.addons,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.hedvig.android.data.productvariant.AddonVariant
import com.hedvig.android.data.productvariant.InsurableLimit
import com.hedvig.android.data.productvariant.ProductVariantPeril
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Large
Expand All @@ -34,20 +35,24 @@ import com.hedvig.android.design.system.hedvig.HedvigPreview
import com.hedvig.android.design.system.hedvig.HedvigText
import com.hedvig.android.design.system.hedvig.HedvigTextButton
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.HighlightLabel
import com.hedvig.android.design.system.hedvig.HighlightLabelDefaults
import com.hedvig.android.design.system.hedvig.HorizontalItemsWithMaximumSpaceTaken
import com.hedvig.android.design.system.hedvig.Icon
import com.hedvig.android.design.system.hedvig.PerilData
import com.hedvig.android.design.system.hedvig.PerilDefaults.PerilSize.Small
import com.hedvig.android.design.system.hedvig.PerilList
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.icon.InfoFilled
import com.hedvig.android.design.system.hedvig.icon.InfoOutline
import com.hedvig.android.design.system.hedvig.rememberHedvigBottomSheetState
import com.hedvig.android.feature.insurances.data.Addon

@Composable
internal fun CoverageTab(
insurableLimits: List<InsurableLimit>,
perils: List<ProductVariantPeril>,
addons: List<Addon>?,
modifier: Modifier = Modifier,
) {
val bottomSheetState = rememberHedvigBottomSheetState<InsurableLimit>()
Expand Down Expand Up @@ -93,6 +98,33 @@ internal fun CoverageTab(
)
Spacer(Modifier.height(16.dp))
}
if (addons?.isNotEmpty() == true) {
addons.forEach { addon ->
Spacer(Modifier.height(16.dp))
HighlightLabel(
labelText = addon.addonVariant.displayName,
size = HighlightLabelDefaults.HighLightSize.Medium,
color = HighlightLabelDefaults.HighlightColor.Blue(
HighlightLabelDefaults.HighlightShade.LIGHT,
),
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(Modifier.height(16.dp))
PerilList(
perilItems = addon.addonVariant.perils.map {
PerilData(
title = it.title,
description = it.description,
covered = it.covered,
colorCode = it.colorCode,
)
},
size = Small,
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(Modifier.height(16.dp))
}
}
Spacer(Modifier.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)))
}
}
Expand Down Expand Up @@ -128,9 +160,9 @@ private fun ColumnScope.InsurableLimitSection(
)
Spacer(Modifier.width(8.dp))
Icon(
imageVector = HedvigIcons.InfoFilled,
imageVector = HedvigIcons.InfoOutline,
contentDescription = null,
modifier = Modifier.size(16.dp),
modifier = Modifier.size(24.dp),
tint = HedvigTheme.colorScheme.fillSecondary,
)
}
Expand Down Expand Up @@ -165,6 +197,7 @@ private fun PreviewCoverageTab() {
CoverageTab(
previewInsurableLimits,
previewPerils,
listOf(Addon(fakeAddonVariant)),
)
}
}
Expand All @@ -191,11 +224,29 @@ private val previewPerils: List<ProductVariantPeril> = List(4) { index ->
title = "Eldsvåda",
description = "description$index",
covered = listOf("Covered#$index"),
colorCode = "0xFFC45D4F",
colorCode = "#FFD0ECFB",
exceptions = listOf(),
)
}

private val fakeAddonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(),
perils = listOf(
ProductVariantPeril(
id = "peril",
title = "Eldsvåda",
description = "peril",
covered = listOf("peril"),
colorCode = "#FFD0ECFB",
exceptions = listOf(),
),
),
displayName = "Travel Insurance Plus",
product = "",
insurableLimits = listOf(),
)

private val previewInsurableLimits: List<InsurableLimit> = listOf(
InsurableLimit("Insured amount".repeat(2), "1 000 000 kr", ""),
InsurableLimit("Deductible", "1 500 kr", ""),
Expand Down

0 comments on commit caad170

Please sign in to comment.