Skip to content

Commit

Permalink
Merge pull request #2384 from HedvigInsurance/feature/stay-on-addon-c…
Browse files Browse the repository at this point in the history
…hoice-to-allow-reviewing-the-perils-before-summary

Always show addon choice screen to allow reviewing the perils before summary
  • Loading branch information
StylianosGakis authored Jan 23, 2025
2 parents f10fada + d88bc72 commit 7e0728c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private fun DropdownSelector(
bounded = true,
radius = 1000.dp,
),
enabled = isEnabled,
onClick = onClick,
),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ internal data class SummaryParameters(
val quote: TravelAddonQuote,
val activationDate: LocalDate,
val currentTravelAddon: CurrentTravelAddon?,
val popCustomizeDestination: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,7 @@ fun NavGraphBuilder.addonPurchaseNavGraph(
navController.typedPopBackStack<AddonPurchaseGraphDestination>(inclusive = true)
},
navigateToSummary = { summaryParameters: SummaryParameters ->
if (summaryParameters.popCustomizeDestination) {
navigator.navigateUnsafe(Summary(summaryParameters)) {
typedPopUpTo<CustomizeAddon> {
inclusive = true
}
}
} else {
navigator.navigateUnsafe(Summary(summaryParameters))
}
navController.navigate(Summary(summaryParameters))
},
onNavigateToTravelInsurancePlusExplanation = { perilDataList: List<PerilData> ->
navigator.navigateUnsafe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,16 @@ private fun CustomizeTravelAddonScreen(
navigateToSummary(state.summaryParamsToNavigateFurther)
}
}
if (state.summaryParamsToNavigateFurther == null) {
CustomizeTravelAddonScreenContent(
uiState = state,
navigateUp = navigateUp,
submitToSummary = submitToSummary,
onChooseSelectedOption = onChooseSelectedOption,
onChooseOptionInDialog = onChooseOptionInDialog,
onSetOptionBackToPreviouslyChosen = onSetOptionBackToPreviouslyChosen,
onNavigateToTravelInsurancePlusExplanation = onNavigateToTravelInsurancePlusExplanation,
popAddonFlow = popAddonFlow,
)
}
CustomizeTravelAddonScreenContent(
uiState = state,
navigateUp = navigateUp,
submitToSummary = submitToSummary,
onChooseSelectedOption = onChooseSelectedOption,
onChooseOptionInDialog = onChooseOptionInDialog,
onSetOptionBackToPreviouslyChosen = onSetOptionBackToPreviouslyChosen,
onNavigateToTravelInsurancePlusExplanation = onNavigateToTravelInsurancePlusExplanation,
popAddonFlow = popAddonFlow,
)
}
}
}
Expand Down Expand Up @@ -317,8 +315,8 @@ private fun CustomizeTravelAddonCard(
}
DropdownWithDialog(
dialogProperties = DialogProperties(usePlatformDefaultWidth = false),
// Locked option if there is nothing else to chose from
isEnabled = uiState.travelAddonOffer.addonOptions.size > 1,
// we shouldn't get to this destination if this list size <=1 at all tbh
style = Label(
label = stringResource(R.string.ADDON_FLOW_SELECT_DAYS_PLACEHOLDER),
items = addonSimpleItems,
Expand Down Expand Up @@ -531,6 +529,7 @@ internal class CustomizeTravelAddonPreviewProvider :
travelAddonOffer = fakeTravelAddon,
currentlyChosenOption = fakeTravelAddonQuote1,
currentlyChosenOptionInDialog = fakeTravelAddonQuote1,
summaryParamsToNavigateFurther = null,
),
CustomizeTravelAddonState.Failure("Ooops"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,12 @@ internal class CustomizeTravelAddonPresenter(
currentState = CustomizeTravelAddonState.Failure(error.message)
},
ifRight = { offer ->
val summaryParams = if (offer.addonOptions.size == 1) {
SummaryParameters(
offer.title,
offer.addonOptions[0],
offer.activationDate,
currentTravelAddon = offer.currentTravelAddon,
popCustomizeDestination = true,
)
} else {
null
}
selectedOptionInDialog = offer.addonOptions[0]
currentState = CustomizeTravelAddonState.Success(
travelAddonOffer = offer,
currentlyChosenOption = offer.addonOptions[0],
currentlyChosenOptionInDialog = selectedOptionInDialog,
summaryParamsToNavigateFurther = summaryParams,
summaryParamsToNavigateFurther = null,
)
},
)
Expand All @@ -132,7 +121,7 @@ internal sealed interface CustomizeTravelAddonState {
val travelAddonOffer: TravelAddonOffer,
val currentlyChosenOption: TravelAddonQuote,
val currentlyChosenOptionInDialog: TravelAddonQuote?,
val summaryParamsToNavigateFurther: SummaryParameters? = null,
val summaryParamsToNavigateFurther: SummaryParameters?,
) : CustomizeTravelAddonState

data class Failure(val errorMessage: String? = null) : CustomizeTravelAddonState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,18 @@ private val testSummaryParametersWithCurrentAddon = SummaryParameters(
quote = newQuote,
activationDate = LocalDate(2024, 12, 30),
currentTravelAddon = currentAddon,
popCustomizeDestination = true,
)

private val testSummaryParametersWithMoreExpensiveCurrentAddon = SummaryParameters(
offerDisplayName = "fakeTravelOfferOnlyOneOption.title",
quote = newQuote2,
activationDate = LocalDate(2024, 12, 30),
currentTravelAddon = moreExpensiveCurrentAddon,
popCustomizeDestination = true,
)

private val testSummaryParametersNoCurrentAddon = SummaryParameters(
offerDisplayName = "fakeTravelOfferOnlyOneOption.title",
quote = newQuote,
activationDate = LocalDate(2024, 12, 30),
currentTravelAddon = null,
popCustomizeDestination = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import arrow.core.nonEmptyListOf
import arrow.core.right
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import assertk.assertions.prop
import com.hedvig.android.core.common.ErrorMessage
Expand All @@ -20,7 +18,6 @@ import com.hedvig.android.data.productvariant.InsuranceVariantDocument
import com.hedvig.android.feature.addon.purchase.data.Addon.TravelAddonOffer
import com.hedvig.android.feature.addon.purchase.data.GetTravelAddonOfferUseCase
import com.hedvig.android.feature.addon.purchase.data.TravelAddonQuote
import com.hedvig.android.feature.addon.purchase.navigation.SummaryParameters
import com.hedvig.android.feature.addon.purchase.ui.customize.CustomizeTravelAddonEvent
import com.hedvig.android.feature.addon.purchase.ui.customize.CustomizeTravelAddonPresenter
import com.hedvig.android.feature.addon.purchase.ui.customize.CustomizeTravelAddonState
Expand Down Expand Up @@ -64,6 +61,7 @@ class CustomizeTravelAddonPresenterTest {
travelAddonOffer = fakeTravelOfferTwoOptions,
currentlyChosenOption = fakeTravelAddonQuote1,
currentlyChosenOptionInDialog = fakeTravelAddonQuote1,
summaryParamsToNavigateFurther = null,
),
) {
skipItems(1)
Expand All @@ -72,35 +70,6 @@ class CustomizeTravelAddonPresenterTest {
}
}

@Test
fun `if receive good response but only one addon redirect to next screen and pop this destination`() = runTest {
val useCase = FakeGetTravelAddonOfferUseCase()
val presenter = CustomizeTravelAddonPresenter(
getTravelAddonOfferUseCase = useCase,
insuranceId = insuranceId,
)
presenter.test(
CustomizeTravelAddonState.Loading,
) {
skipItems(1)
useCase.turbine.add(fakeTravelOfferOnlyOneOption.right())
val state = awaitItem()
assertThat(state).isInstanceOf(CustomizeTravelAddonState.Success::class)
.apply {
prop(CustomizeTravelAddonState.Success::summaryParamsToNavigateFurther)
.isEqualTo(
SummaryParameters(
offerDisplayName = fakeTravelOfferOnlyOneOption.title,
quote = fakeTravelOfferOnlyOneOption.addonOptions[0],
activationDate = fakeTravelOfferOnlyOneOption.activationDate,
currentTravelAddon = fakeTravelOfferOnlyOneOption.currentTravelAddon,
popCustomizeDestination = true,
),
)
}
}
}

@Test
fun `if receive good response return correct data, pre-choose first addon and do not navigate further`() = runTest {
val useCase = FakeGetTravelAddonOfferUseCase()
Expand Down Expand Up @@ -176,36 +145,6 @@ class CustomizeTravelAddonPresenterTest {
assertThat(awaitItem()).isInstanceOf(CustomizeTravelAddonState.Success::class)
}
}

@Test
fun `on submit navigate further with currently chosen option and do not pop this destination`() = runTest {
val useCase = FakeGetTravelAddonOfferUseCase()
val presenter = CustomizeTravelAddonPresenter(
getTravelAddonOfferUseCase = useCase,
insuranceId = insuranceId,
)
presenter.test(
CustomizeTravelAddonState.Loading,
) {
useCase.turbine.add(fakeTravelOfferTwoOptions.right())
skipItems(2)
sendEvent(CustomizeTravelAddonEvent.ChooseOptionInDialog(fakeTravelOfferTwoOptions.addonOptions[1]))
sendEvent(CustomizeTravelAddonEvent.ChooseSelectedOption)
skipItems(2)
sendEvent(CustomizeTravelAddonEvent.SubmitSelected)
assertThat(awaitItem()).isInstanceOf(CustomizeTravelAddonState.Success::class)
.apply {
prop(CustomizeTravelAddonState.Success::summaryParamsToNavigateFurther)
.isNotNull().apply {
prop(SummaryParameters::popCustomizeDestination).isFalse()
prop(SummaryParameters::quote).isEqualTo(fakeTravelOfferTwoOptions.addonOptions[1])
prop(SummaryParameters::currentTravelAddon).isEqualTo(fakeTravelOfferTwoOptions.currentTravelAddon)
prop(SummaryParameters::activationDate).isEqualTo(fakeTravelOfferTwoOptions.activationDate)
prop(SummaryParameters::offerDisplayName).isEqualTo(fakeTravelOfferTwoOptions.title)
}
}
}
}
}

private class FakeGetTravelAddonOfferUseCase() : GetTravelAddonOfferUseCase {
Expand Down

0 comments on commit 7e0728c

Please sign in to comment.