Skip to content

Commit

Permalink
Merge branch 'master' into brnunes/alipay
Browse files Browse the repository at this point in the history
  • Loading branch information
brnunes-stripe committed Sep 16, 2022
2 parents 9176f68 + b870ddd commit 5da0b57
Show file tree
Hide file tree
Showing 21 changed files with 225 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.stripe.android.link.LinkScreen
import com.stripe.android.link.R
import com.stripe.android.link.model.AccountStatus
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -21,7 +22,8 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Wallet.route,
email = " "
email = " ",
accountStatus = AccountStatus.SignedOut
)

assertThat(state.email).isNull()
Expand All @@ -32,14 +34,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Loading.route,
email = null
email = null,
accountStatus = AccountStatus.SignedOut
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = false,
email = null
email = null,
accountStatus = AccountStatus.SignedOut
)

assertThat(state).isEqualTo(expected)
Expand All @@ -50,14 +54,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Verification.route,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.VerificationStarted
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = false,
email = null
email = null,
accountStatus = AccountStatus.VerificationStarted
)

assertThat(state).isEqualTo(expected)
Expand All @@ -68,14 +74,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.VerificationDialog.route,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.VerificationStarted
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = false,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.VerificationStarted
)

assertThat(state).isEqualTo(expected)
Expand All @@ -86,14 +94,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Wallet.route,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = true,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
)

assertThat(state).isEqualTo(expected)
Expand All @@ -104,14 +114,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.PaymentMethod.route,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = true,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
)

assertThat(state).isEqualTo(expected)
Expand All @@ -122,14 +134,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = false,
currentRoute = LinkScreen.PaymentMethod.route,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_back,
showHeader = false,
showOverflowMenu = false,
email = null
email = null,
accountStatus = AccountStatus.Verified
)

assertThat(state).isEqualTo(expected)
Expand All @@ -140,14 +154,16 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = false,
currentRoute = LinkScreen.CardEdit.route,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_back,
showHeader = false,
showOverflowMenu = false,
email = null
email = null,
accountStatus = AccountStatus.Verified
)

assertThat(state).isEqualTo(expected)
Expand All @@ -158,14 +174,36 @@ internal class LinkAppBarStateTest {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.SignUp.route,
email = null
email = null,
accountStatus = AccountStatus.SignedOut
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = false,
email = null
email = null,
accountStatus = AccountStatus.SignedOut
)

assertThat(state).isEqualTo(expected)
}

@Test
fun signupScreenShowsCorrectAppBarStateWithEmail() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.SignUp.route,
email = "[email protected]",
accountStatus = AccountStatus.NeedsVerification
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = false,
email = null,
accountStatus = AccountStatus.NeedsVerification
)

assertThat(state).isEqualTo(expected)
Expand All @@ -174,12 +212,13 @@ internal class LinkAppBarStateTest {
private fun buildLinkAppBarState(
isRootScreen: Boolean,
currentRoute: String?,
email: String?
email: String?,
accountStatus: AccountStatus?
): LinkAppBarState {
var state: LinkAppBarState? = null

composeTestRule.setContent {
state = rememberLinkAppBarState(isRootScreen, currentRoute, email)
state = rememberLinkAppBarState(isRootScreen, currentRoute, email, accountStatus)
}

return state ?: throw AssertionError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.stripe.android.link.R
import com.stripe.android.link.model.AccountStatus
import com.stripe.android.link.theme.DefaultLinkTheme
import org.junit.Rule
import org.junit.Test
Expand All @@ -19,7 +20,7 @@ internal class LinkAppBarTest {
val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Test
fun email_is_shown_when_provided() {
fun verified_email_is_shown_when_provided() {
val email = "[email protected]"
setContent(email)

Expand Down Expand Up @@ -48,6 +49,7 @@ internal class LinkAppBarTest {

private fun setContent(
email: String? = null,
accountStatus: AccountStatus? = null,
onBackPress: () -> Unit = {},
onLogout: () -> Unit = {},
showBottomSheetContent: (BottomSheetContent?) -> Unit = {}
Expand All @@ -58,7 +60,8 @@ internal class LinkAppBarTest {
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = true,
email = email
email = email,
accountStatus = accountStatus
),
onBackPressed = onBackPress,
onLogout = onLogout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ internal class VerificationScreenTest {
assertThat(otpValue?.value).isEqualTo("")
}

@Test
fun focus_on_first_otp_field_at_start() {
setContent()
onOtpField(0).assertIsFocused()
}

@Test
fun when_error_message_is_not_null_then_it_is_visible() {
val errorMessage = "Error message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ internal class WalletScreenTest {
.assertCountEquals(5)
}

@Test
fun when_no_selected_payment_method_then_wallet_is_expanded() {
var selectedItem: ConsumerPaymentDetails.PaymentDetails? = null
setContent(
selectedItem = null,
isExpanded = false,
onItemSelected = {
selectedItem = it
}
)

assertExpanded()
assertThat(selectedItem).isNull()
onPrimaryButton().assertIsNotEnabled()
}

@Test
fun add_new_payment_method_click_triggers_action() {
var count = 0
Expand Down
9 changes: 6 additions & 3 deletions link/src/main/java/com/stripe/android/link/LinkActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.ViewTreeObserver
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.annotation.VisibleForTesting
Expand Down Expand Up @@ -115,17 +116,19 @@ internal class LinkActivity : ComponentActivity() {
Column(Modifier.fillMaxWidth()) {
val linkAccount by viewModel.linkAccount.collectAsState(null)
val isOnRootScreen by isRootScreenFlow().collectAsState(true)

val backStackEntry by navController.currentBackStackEntryAsState()
val appBarState = rememberLinkAppBarState(
isRootScreen = isOnRootScreen,
currentRoute = backStackEntry?.destination?.route,
email = linkAccount?.email
email = linkAccount?.email,
accountStatus = linkAccount?.accountStatus
)

BackHandler(onBack = viewModel::onBackPressed)

LinkAppBar(
state = appBarState,
onBackPressed = viewModel::onBackPressed,
onBackPressed = onBackPressedDispatcher::onBackPressed,
onLogout = viewModel::logout,
showBottomSheetContent = {
if (it == null) {
Expand Down
13 changes: 9 additions & 4 deletions link/src/main/java/com/stripe/android/link/ui/LinkAppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.stripe.android.link.R
import com.stripe.android.link.model.AccountStatus
import com.stripe.android.link.theme.AppBarHeight
import com.stripe.android.link.theme.DefaultLinkTheme
import com.stripe.android.link.theme.linkColors
Expand Down Expand Up @@ -131,7 +132,8 @@ private fun LinkAppBarPreview() {
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = true,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
),
onBackPressed = {},
onLogout = {},
Expand All @@ -151,7 +153,8 @@ private fun LinkAppBar_NoEmail() {
navigationIcon = R.drawable.ic_link_close,
showHeader = true,
showOverflowMenu = true,
email = null
email = null,
accountStatus = AccountStatus.SignedOut
),
onBackPressed = {},
onLogout = {},
Expand All @@ -171,7 +174,8 @@ private fun LinkAppBar_ChildScreen() {
navigationIcon = R.drawable.ic_link_back,
showHeader = false,
showOverflowMenu = false,
email = "[email protected]"
email = "[email protected]",
accountStatus = AccountStatus.Verified
),
onBackPressed = {},
onLogout = {},
Expand All @@ -191,7 +195,8 @@ private fun LinkAppBar_ChildScreen_NoEmail() {
navigationIcon = R.drawable.ic_link_back,
showHeader = false,
showOverflowMenu = false,
email = null
email = null,
accountStatus = AccountStatus.SignedOut
),
onBackPressed = {},
onLogout = {},
Expand Down
12 changes: 8 additions & 4 deletions link/src/main/java/com/stripe/android/link/ui/LinkAppBarState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.stripe.android.link.LinkScreen
import com.stripe.android.link.R
import com.stripe.android.link.model.AccountStatus

internal data class LinkAppBarState(
@DrawableRes val navigationIcon: Int,
val showHeader: Boolean,
val showOverflowMenu: Boolean,
val email: String?
val email: String?,
val accountStatus: AccountStatus?
)

@Composable
internal fun rememberLinkAppBarState(
isRootScreen: Boolean,
currentRoute: String?,
email: String?
email: String?,
accountStatus: AccountStatus?
): LinkAppBarState {
return remember(currentRoute, email) {
val showHeader = when (currentRoute) {
Expand All @@ -36,7 +39,7 @@ internal fun rememberLinkAppBarState(

// If there's an email address, we want to allow the user to log
// out of the existing account.
val showOverflowMenu = isRootScreen && email != null
val showOverflowMenu = isRootScreen && email != null && accountStatus == AccountStatus.Verified

LinkAppBarState(
navigationIcon = if (isRootScreen) {
Expand All @@ -46,7 +49,8 @@ internal fun rememberLinkAppBarState(
},
showHeader = showHeader,
showOverflowMenu = showOverflowMenu,
email = email?.takeUnless { it.isBlank() || hideEmail }
email = email?.takeUnless { it.isBlank() || hideEmail },
accountStatus = accountStatus
)
}
}
Loading

0 comments on commit 5da0b57

Please sign in to comment.