Skip to content

Commit

Permalink
Use email from arguments in Link sign up (#5067)
Browse files Browse the repository at this point in the history
  • Loading branch information
brnunes-stripe committed May 25, 2022
1 parent 715c7d0 commit 7dc3c10
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
20 changes: 14 additions & 6 deletions link/src/main/java/com/stripe/android/link/LinkActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ internal class LinkActivity : ComponentActivity() {
internal var viewModelFactory: ViewModelProvider.Factory =
LinkActivityViewModel.Factory(
applicationSupplier = { application },
starterArgsSupplier = { requireNotNull(starterArgs) }
starterArgsSupplier = { starterArgs }
)

private val viewModel: LinkActivityViewModel by viewModels { viewModelFactory }

@VisibleForTesting
lateinit var navController: NavHostController

private val starterArgs: LinkActivityContract.Args? by lazy {
LinkActivityContract.Args.fromIntent(intent)
private val starterArgs by lazy {
requireNotNull(LinkActivityContract.Args.fromIntent(intent))
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -77,6 +77,7 @@ internal class LinkActivity : ComponentActivity() {
)

NavHost(navController, LinkScreen.Loading.route) {

composable(LinkScreen.Loading.route) {
Box(
modifier = Modifier
Expand All @@ -87,6 +88,7 @@ internal class LinkActivity : ComponentActivity() {
CircularProgressIndicator()
}
}

composable(
LinkScreen.SignUp.route,
arguments = listOf(
Expand All @@ -100,6 +102,7 @@ internal class LinkActivity : ComponentActivity() {
backStackEntry.arguments?.getString(LinkScreen.SignUp.emailArg)
SignUpBody(viewModel.injector, email)
}

composable(LinkScreen.Verification.route) {
linkAccount?.let { account ->
VerificationBodyFullFlow(
Expand All @@ -108,6 +111,7 @@ internal class LinkActivity : ComponentActivity() {
)
}
}

composable(LinkScreen.Wallet.route) {
linkAccount?.let { account ->
WalletBody(
Expand All @@ -116,6 +120,7 @@ internal class LinkActivity : ComponentActivity() {
)
}
}

composable(LinkScreen.PaymentMethod.route) {
linkAccount?.let { account ->
PaymentMethodBody(
Expand All @@ -140,10 +145,13 @@ internal class LinkActivity : ComponentActivity() {
lifecycleScope.launch {
viewModel.navigator.navigateTo(
target = when (viewModel.linkAccountManager.accountStatus.first()) {
AccountStatus.Verified -> LinkScreen.Wallet
AccountStatus.Verified ->
LinkScreen.Wallet
AccountStatus.NeedsVerification,
AccountStatus.VerificationStarted -> LinkScreen.Verification
AccountStatus.SignedOut -> LinkScreen.SignUp()
AccountStatus.VerificationStarted ->
LinkScreen.Verification
AccountStatus.SignedOut ->
LinkScreen.SignUp(starterArgs.customerEmail)
},
clearBackStack = true
)
Expand Down
20 changes: 18 additions & 2 deletions link/src/test/java/com/stripe/android/link/LinkActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.robolectric.RobolectricTestRunner

@Ignore("Fix CircularProgressIndicator hanging tests")
// TODO:(brnunes-stripe) Enable these tests
@Ignore("CircularProgressIndicator hangs tests. Need to comment it out.")
@ExperimentalCoroutinesApi
@RunWith(RobolectricTestRunner::class)
class LinkActivityTest {
private val context = ApplicationProvider.getApplicationContext<Context>()
private val args = LinkActivityContract.Args(
StripeIntentFixtures.PI_SUCCEEDED,
true,
"Example, Inc."
"Example, Inc.",
"email@stripe.com"
)
private val intent = LinkActivityContract().createIntent(context, args)

Expand Down Expand Up @@ -70,6 +72,20 @@ class LinkActivityTest {
}
}

@Test
fun `When consumer email provided then it's auto-filled in SignUp screen`() {
whenever(linkAccountManager.accountStatus).thenReturn(flowOf(AccountStatus.SignedOut))

activityScenario().launch(intent).onActivity {
verify(navigator).navigateTo(
argWhere {
it.route == "SignUp?email=email%40stripe.com"
},
eq(true)
)
}
}

@Test
fun `When consumer is verified then it navigates to Wallet screen`() = runTest {
whenever(linkAccountManager.accountStatus).thenReturn(flowOf(AccountStatus.Verified))
Expand Down

0 comments on commit 7dc3c10

Please sign in to comment.