Skip to content

Commit

Permalink
Remove old awareness component for experiment variant (#1456)
Browse files Browse the repository at this point in the history
Co-authored-by: Isabel Martin <arkariang@gmail.com>
  • Loading branch information
hadia and Arkariang committed Nov 16, 2021
1 parent 8e5830d commit 69792b4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Expand Up @@ -622,6 +622,13 @@ class PledgeFragment :
.subscribe {
showRiskMessageDialog()
}

this.viewModel.outputs.changePledgeSectionAccountabilityFragmentVisiablity()
.compose(observeForUI())
.compose(bindToLifecycle())
.subscribe {
binding?.pledgeSectionAccountability?.root?.isGone = it
}
}

private fun showRiskMessageDialog() {
Expand Down
Expand Up @@ -320,6 +320,8 @@ interface PledgeFragmentViewModel {
fun pledgeAmountHeader(): Observable<CharSequence>

fun changeCheckoutRiskMessageBottomSheetStatus(): Observable<Boolean>

fun changePledgeSectionAccountabilityFragmentVisiablity(): Observable<Boolean>
}

class ViewModel(@NonNull val environment: Environment) : FragmentViewModel<PledgeFragment>(environment), Inputs, Outputs {
Expand Down Expand Up @@ -349,6 +351,7 @@ interface PledgeFragmentViewModel {
private val additionalPledgeAmountIsGone = BehaviorSubject.create<Boolean>()
private val baseUrlForTerms = BehaviorSubject.create<String>()
private val changeCheckoutRiskMessageBottomSheetStatus = BehaviorSubject.create<Boolean>()
private val changePledgeSectionAccountabilityFragmentVisiablity = BehaviorSubject.create<Boolean>()
private val cardsAndProject = BehaviorSubject.create<Pair<List<StoredCard>, Project>>()
private val continueButtonIsEnabled = BehaviorSubject.create<Boolean>()
private val continueButtonIsGone = BehaviorSubject.create<Boolean>()
Expand Down Expand Up @@ -1177,6 +1180,15 @@ interface PledgeFragmentViewModel {
this.changeCheckoutRiskMessageBottomSheetStatus.onNext(false)
}

experimentData
.map { this.optimizely.variant(OptimizelyExperiment.Key.NATIVE_RISK_MESSAGING, it) != OptimizelyExperiment.Variant.CONTROL }
.compose(combineLatestPair(pledgeReason))
.filter { it.second == PledgeReason.PLEDGE }
.compose(bindToLifecycle())
.subscribe {
changePledgeSectionAccountabilityFragmentVisiablity.onNext(it.first)
}

this.pledgeButtonClicked
.compose(combineLatestPair(experimentData))
.filter { this.optimizely.variant(OptimizelyExperiment.Key.NATIVE_RISK_MESSAGING, it.second) == OptimizelyExperiment.Variant.CONTROL }
Expand Down Expand Up @@ -1933,5 +1945,9 @@ interface PledgeFragmentViewModel {
@NonNull
override fun changeCheckoutRiskMessageBottomSheetStatus(): Observable<Boolean> = this
.changeCheckoutRiskMessageBottomSheetStatus

@NonNull
override fun changePledgeSectionAccountabilityFragmentVisiablity(): Observable<Boolean> =
this.changePledgeSectionAccountabilityFragmentVisiablity
}
}
Expand Up @@ -126,6 +126,7 @@ class PledgeFragmentViewModelTest : KSRobolectricTestCase() {
private val bonusSummaryIsGone = TestSubscriber<Boolean>()
private val shippingRule = TestSubscriber<ShippingRule>()
private val changeCheckoutRiskMessageBottomSheetStatus = TestSubscriber<Boolean>()
private val changePledgeSectionAccountabilityFragmentVisiablity = TestSubscriber<Boolean>()

private fun setUpEnvironment(
environment: Environment,
Expand Down Expand Up @@ -199,6 +200,7 @@ class PledgeFragmentViewModelTest : KSRobolectricTestCase() {
this.vm.outputs.bonusSummaryIsGone().subscribe(this.bonusSummaryIsGone)
this.vm.outputs.shippingRule().subscribe(this.shippingRule)
this.vm.outputs.changeCheckoutRiskMessageBottomSheetStatus().subscribe(this.changeCheckoutRiskMessageBottomSheetStatus)
this.vm.outputs.changePledgeSectionAccountabilityFragmentVisiablity().subscribe(this.changePledgeSectionAccountabilityFragmentVisiablity)

val projectData = project.backing()?.let {
return@let ProjectData.builder()
Expand Down Expand Up @@ -1488,6 +1490,7 @@ class PledgeFragmentViewModelTest : KSRobolectricTestCase() {

this.changeCheckoutRiskMessageBottomSheetStatus.assertValueCount(2)
this.changeCheckoutRiskMessageBottomSheetStatus.assertValues(true, false)
this.changePledgeSectionAccountabilityFragmentVisiablity.assertValues(true)
}

@Test
Expand All @@ -1501,6 +1504,7 @@ class PledgeFragmentViewModelTest : KSRobolectricTestCase() {
this.vm.inputs.pledgeButtonClicked()

this.changeCheckoutRiskMessageBottomSheetStatus.assertNoValues()
this.changePledgeSectionAccountabilityFragmentVisiablity.assertValues(false)
}

@Test
Expand Down

0 comments on commit 69792b4

Please sign in to comment.