-
Notifications
You must be signed in to change notification settings - Fork 662
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
Update FakeFormActivityLauncher and FakeManageActivityLauncher to use turbines #9957
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,39 @@ package com.stripe.android.paymentelement.embedded | |
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContract | ||
import androidx.core.app.ActivityOptionsCompat | ||
import app.cash.turbine.ReceiveTurbine | ||
import app.cash.turbine.Turbine | ||
|
||
internal class FakeFormActivityLauncher : ActivityResultLauncher<FormContract.Args>() { | ||
var didLaunch = false | ||
private set | ||
var launchArgs: FormContract.Args? = null | ||
private set | ||
var didUnregister = false | ||
private set | ||
private val _launchStateTurbine = Turbine<LaunchState>() | ||
val launchTurbine: ReceiveTurbine<LaunchState> = _launchStateTurbine | ||
private val _unregisterTurbine = Turbine<Boolean>() | ||
val unregisterTurbine: ReceiveTurbine<Boolean> = _unregisterTurbine | ||
|
||
override fun launch(input: FormContract.Args?, options: ActivityOptionsCompat?) { | ||
didLaunch = true | ||
launchArgs = input | ||
_launchStateTurbine.add( | ||
LaunchState( | ||
didLaunch = true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove this from the launch state. It'll only be emitted if the launch was called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should still be possible! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
launchArgs = input | ||
) | ||
) | ||
} | ||
|
||
override fun unregister() { | ||
didUnregister = true | ||
_unregisterTurbine.add(true) | ||
} | ||
|
||
override fun getContract(): ActivityResultContract<FormContract.Args, FormResult> { | ||
return FormContract | ||
} | ||
|
||
fun validate() { | ||
launchTurbine.ensureAllEventsConsumed() | ||
unregisterTurbine.ensureAllEventsConsumed() | ||
} | ||
|
||
data class LaunchState( | ||
val didLaunch: Boolean, | ||
val launchArgs: FormContract.Args? | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,39 @@ package com.stripe.android.paymentelement.embedded.manage | |
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContract | ||
import androidx.core.app.ActivityOptionsCompat | ||
import app.cash.turbine.ReceiveTurbine | ||
import app.cash.turbine.Turbine | ||
|
||
internal class FakeManageActivityLauncher : ActivityResultLauncher<ManageContract.Args>() { | ||
var didLaunch = false | ||
private set | ||
var launchArgs: ManageContract.Args? = null | ||
private set | ||
var didUnregister = false | ||
private set | ||
private val _launchStateTurbine = Turbine<LaunchState>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's probably a not terrible way to make these generic, and not need 2 of basically the same implementations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to pair on it if you want! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added generic FakeEmbeddedActivityLauncher |
||
val launchTurbine: ReceiveTurbine<LaunchState> = _launchStateTurbine | ||
private val _unregisterTurbine = Turbine<Boolean>() | ||
val unregisterTurbine: ReceiveTurbine<Boolean> = _unregisterTurbine | ||
|
||
override fun launch(input: ManageContract.Args?, options: ActivityOptionsCompat?) { | ||
didLaunch = true | ||
launchArgs = input | ||
_launchStateTurbine.add( | ||
LaunchState( | ||
didLaunch = true, | ||
launchArgs = input | ||
) | ||
) | ||
} | ||
|
||
override fun unregister() { | ||
didUnregister = true | ||
_unregisterTurbine.add(true) | ||
} | ||
|
||
override fun getContract(): ActivityResultContract<ManageContract.Args, ManageResult> { | ||
return ManageContract | ||
} | ||
|
||
fun validate() { | ||
launchTurbine.ensureAllEventsConsumed() | ||
unregisterTurbine.ensureAllEventsConsumed() | ||
} | ||
|
||
data class LaunchState( | ||
val didLaunch: Boolean, | ||
val launchArgs: ManageContract.Args? | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably even just replace this with
Unit
instead ofBoolean
. We don't really care about the value. Just that a value was emitted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to Unit