Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/addons docs in addon flow #2361

Merged
merged 3 commits into from
Dec 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ mutation UpsellAddonOffer($contractId: ID!) {
...MoneyFragment
}
quoteId
addonVariant {
...AddonVariantFragment
}
}
titleDisplayName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hedvig.android.feature.addon.purchase.data

import arrow.core.NonEmptyList
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.productvariant.InsuranceVariantDocument
import com.hedvig.android.data.productvariant.AddonVariant
import kotlinx.datetime.LocalDate
import kotlinx.serialization.Serializable

Expand All @@ -23,12 +23,6 @@ internal data class TravelAddonQuote(
val displayName: String,
val price: UiMoney,
val addonVariant: AddonVariant,
)

@Serializable
internal data class AddonVariant(
val documents: List<InsuranceVariantDocument>,
val termsVersion: String,
val displayDetails: List<Pair<String, String>>,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.apollographql.apollo.ApolloClient
import com.hedvig.android.apollo.safeExecute
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.productvariant.toAddonVariant
import com.hedvig.android.feature.addon.purchase.data.Addon.TravelAddonOffer
import com.hedvig.android.featureflags.FeatureManager
import com.hedvig.android.featureflags.flags.Feature
Expand Down Expand Up @@ -74,13 +75,10 @@ private fun NonEmptyList<UpsellAddonOfferMutation.Data.UpsellTravelAddonOffer.Of
addonId = it.addonId,
displayName = it.displayName,
price = UiMoney.fromMoneyFragment(it.premium),
addonVariant = AddonVariant(
documents = listOf(), // todo: Addons - populate when api changes!
termsVersion = "", // todo: Addons - populate when api changes!
displayDetails = it.displayItems.map { item ->
item.displayTitle to item.displayValue
},
),
displayDetails = it.displayItems.map { item ->
item.displayTitle to item.displayValue
},
addonVariant = it.addonVariant.toAddonVariant(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.lifecycle.compose.dropUnlessResumed
import arrow.core.nonEmptyListOf
import com.hedvig.android.core.uidata.UiCurrencyCode
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.productvariant.AddonVariant
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Large
import com.hedvig.android.design.system.hedvig.ChosenState
import com.hedvig.android.design.system.hedvig.ChosenState.Chosen
Expand Down Expand Up @@ -70,7 +71,6 @@ import com.hedvig.android.design.system.hedvig.icon.Close
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.design.system.hedvig.rememberHedvigBottomSheetState
import com.hedvig.android.feature.addon.purchase.data.Addon.TravelAddonOffer
import com.hedvig.android.feature.addon.purchase.data.AddonVariant
import com.hedvig.android.feature.addon.purchase.data.TravelAddonQuote
import com.hedvig.android.feature.addon.purchase.navigation.SummaryParameters
import hedvig.resources.R
Expand Down Expand Up @@ -554,10 +554,14 @@ private val fakeTravelAddonQuote1 = TravelAddonQuote(
quoteId = "id",
addonId = "addonId1",
displayName = "45 days",
displayDetails = listOf(),
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(),
displayDetails = listOf(),
perils = listOf(),
displayName = "45 days",
product = "",
insurableLimits = listOf(),
),
price = UiMoney(
49.0,
Expand All @@ -568,10 +572,14 @@ private val fakeTravelAddonQuote2 = TravelAddonQuote(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
displayDetails = listOf(),
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(),
displayDetails = listOf(),
perils = listOf(),
displayName = "60 days",
product = "",
insurableLimits = listOf(),
),
price = UiMoney(
60.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.hedvig.android.core.uidata.UiCurrencyCode
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.productvariant.InsuranceVariantDocument
import com.hedvig.android.data.productvariant.AddonVariant
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Large
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonStyle.Primary
import com.hedvig.android.design.system.hedvig.DialogDefaults
Expand All @@ -41,7 +41,6 @@ import com.hedvig.android.design.system.hedvig.NotificationDefaults
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDateTimeFormatterDefaults
import com.hedvig.android.design.system.hedvig.datepicker.getLocale
import com.hedvig.android.feature.addon.purchase.data.AddonVariant
import com.hedvig.android.feature.addon.purchase.data.CurrentTravelAddon
import com.hedvig.android.feature.addon.purchase.data.TravelAddonQuote
import com.hedvig.android.feature.addon.purchase.ui.summary.AddonSummaryState.Content
Expand Down Expand Up @@ -250,7 +249,7 @@ private fun SummaryCard(uiState: Content, modifier: Modifier = Modifier) {
}
}
},
displayItems = if (uiState.quote.addonVariant.displayDetails.isNotEmpty()) {
displayItems = if (uiState.quote.displayDetails.isNotEmpty()) {
{ DetailsWithStrikeThrough(uiState) }
} else {
null
Expand All @@ -266,7 +265,7 @@ private fun SummaryCard(uiState: Content, modifier: Modifier = Modifier) {

@Composable
private fun DetailsWithStrikeThrough(uiState: Content) {
uiState.quote.addonVariant.displayDetails.forEach { quoteItem ->
uiState.quote.displayDetails.forEach { quoteItem ->
val currentAddonValue = uiState.currentTravelAddon?.displayDetails?.firstOrNull { currentAddonItem ->
currentAddonItem.first == quoteItem.first
}?.second
Expand Down Expand Up @@ -339,19 +338,17 @@ private class ChooseInsuranceForAddonUiStateProvider :
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
displayDetails = listOf(
"Amount of insured people" to "You +1",
"Coverage" to "60 days",
),
addonVariant = AddonVariant(
termsVersion = "terms",
displayDetails = listOf(
"Amount of insured people" to "You +1",
"Coverage" to "60 days",
),
documents = listOf(
InsuranceVariantDocument(
"Terms and Conditions",
"url",
InsuranceVariantDocument.InsuranceDocumentType.TERMS_AND_CONDITIONS,
),
),
documents = listOf(),
perils = listOf(),
displayName = "45 days",
product = "",
insurableLimits = listOf(),
),
price = UiMoney(
60.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.core.common.test.isLeft
import com.hedvig.android.core.uidata.UiCurrencyCode
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.productvariant.AddonVariant
import com.hedvig.android.feature.addon.purchase.data.Addon.TravelAddonOffer
import com.hedvig.android.feature.addon.purchase.data.AddonVariant
import com.hedvig.android.feature.addon.purchase.data.CurrentTravelAddon
import com.hedvig.android.feature.addon.purchase.data.GetTravelAddonOfferUseCaseImpl
import com.hedvig.android.feature.addon.purchase.data.TravelAddonQuote
Expand All @@ -29,6 +29,7 @@ import kotlinx.coroutines.test.runTest
import kotlinx.datetime.LocalDate
import octopus.UpsellAddonOfferMutation
import octopus.type.CurrencyCode
import octopus.type.buildAddonVariant
import octopus.type.buildMoney
import octopus.type.buildUpsellTravelAddonCurrentAddon
import octopus.type.buildUpsellTravelAddonDisplayItem
Expand Down Expand Up @@ -127,15 +128,23 @@ class GetTravelAddonOfferUseCaseImplTest {
displayItems = buildList {
add(
buildUpsellTravelAddonDisplayItem {
displayTitle = mockWithoutUpgrade.addonOptions[0].addonVariant.displayDetails[0].first
displayValue = mockWithoutUpgrade.addonOptions[0].addonVariant.displayDetails[0].second
displayTitle = mockWithoutUpgrade.addonOptions[0].displayDetails[0].first
displayValue = mockWithoutUpgrade.addonOptions[0].displayDetails[0].second
},
)
}
premium = buildMoney {
amount = mockWithoutUpgrade.addonOptions[0].price.amount
currencyCode = CurrencyCode.SEK
}
addonVariant = buildAddonVariant {
termsVersion = ""
documents = listOf()
displayName = "45 days"
product = ""
perils = listOf()
insurableLimits = listOf()
}
},
)

Expand All @@ -147,15 +156,23 @@ class GetTravelAddonOfferUseCaseImplTest {
displayItems = buildList {
add(
buildUpsellTravelAddonDisplayItem {
displayTitle = mockWithoutUpgrade.addonOptions[1].addonVariant.displayDetails[0].first
displayValue = mockWithoutUpgrade.addonOptions[1].addonVariant.displayDetails[0].second
displayTitle = mockWithoutUpgrade.addonOptions[1].displayDetails[0].first
displayValue = mockWithoutUpgrade.addonOptions[1].displayDetails[0].second
},
)
}
premium = buildMoney {
amount = mockWithoutUpgrade.addonOptions[1].price.amount
currencyCode = CurrencyCode.SEK
}
addonVariant = buildAddonVariant {
termsVersion = ""
documents = listOf()
displayName = "60 days"
product = ""
perils = listOf()
insurableLimits = listOf()
}
},
)
}
Expand Down Expand Up @@ -200,15 +217,23 @@ class GetTravelAddonOfferUseCaseImplTest {
displayItems = buildList {
add(
buildUpsellTravelAddonDisplayItem {
displayTitle = mockWithUpgrade.addonOptions[0].addonVariant.displayDetails[0].first
displayValue = mockWithUpgrade.addonOptions[0].addonVariant.displayDetails[0].second
displayTitle = mockWithUpgrade.addonOptions[0].displayDetails[0].first
displayValue = mockWithUpgrade.addonOptions[0].displayDetails[0].second
},
)
}
premium = buildMoney {
amount = mockWithUpgrade.addonOptions[0].price.amount
currencyCode = CurrencyCode.SEK
}
addonVariant = buildAddonVariant {
termsVersion = ""
documents = listOf()
displayName = "45 days"
product = ""
perils = listOf()
insurableLimits = listOf()
}
},
)
}
Expand Down Expand Up @@ -285,10 +310,14 @@ private val mockWithoutUpgrade = TravelAddonOffer(
quoteId = "id",
addonId = "addonId1",
displayName = "45 days",
displayDetails = listOf("Coverage" to "45 days"),
addonVariant = AddonVariant(
termsVersion = "",
documents = listOf(),
displayDetails = listOf("Coverage" to "45 days"),
displayName = "45 days",
product = "",
perils = listOf(),
insurableLimits = listOf(),
),
price = UiMoney(
49.0,
Expand All @@ -299,10 +328,14 @@ private val mockWithoutUpgrade = TravelAddonOffer(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
displayDetails = listOf("Coverage" to "60 days"),
addonVariant = AddonVariant(
termsVersion = "",
documents = listOf(),
displayDetails = listOf("Coverage" to "60 days"),
displayName = "60 days",
product = "",
perils = listOf(),
insurableLimits = listOf(),
),
price = UiMoney(
60.0,
Expand All @@ -322,10 +355,14 @@ private val mockWithUpgrade = TravelAddonOffer(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
displayDetails = listOf("Coverage" to "60 days"),
addonVariant = AddonVariant(
termsVersion = "",
documents = listOf(),
displayDetails = listOf("Coverage" to "60 days"),
displayName = "45 days",
product = "",
perils = listOf(),
insurableLimits = listOf(),
),
price = UiMoney(
60.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import assertk.assertions.prop
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.core.uidata.UiCurrencyCode
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.productvariant.AddonVariant
import com.hedvig.android.data.productvariant.InsuranceVariantDocument
import com.hedvig.android.feature.addon.purchase.data.AddonVariant
import com.hedvig.android.feature.addon.purchase.data.CurrentTravelAddon
import com.hedvig.android.feature.addon.purchase.data.SubmitAddonPurchaseUseCase
import com.hedvig.android.feature.addon.purchase.data.TravelAddonQuote
Expand Down Expand Up @@ -102,12 +102,16 @@ private val newQuote = TravelAddonQuote(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
displayDetails = listOf(
"Amount of insured people" to "You +1",
"Coverage" to "60 days",
),
addonVariant = AddonVariant(
termsVersion = "terms",
displayDetails = listOf(
"Amount of insured people" to "You +1",
"Coverage" to "60 days",
),
displayName = "45 days",
product = "",
perils = listOf(),
insurableLimits = listOf(),
documents = listOf(
InsuranceVariantDocument(
"Terms and Conditions",
Expand All @@ -126,12 +130,16 @@ private val newQuote2 = TravelAddonQuote(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
displayDetails = listOf(
"Amount of insured people" to "You +1",
"Coverage" to "60 days",
),
addonVariant = AddonVariant(
termsVersion = "terms",
displayDetails = listOf(
"Amount of insured people" to "You +1",
"Coverage" to "60 days",
),
displayName = "60 days",
product = "",
perils = listOf(),
insurableLimits = listOf(),
documents = listOf(
InsuranceVariantDocument(
"Terms and Conditions",
Expand Down
Loading
Loading