-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide Link header on certain screens (#5435)
* Hide Link header if not on root screen * Omit top padding if header is hidden * Update Link API * Make minor UX tweak * Hide header only on card add and update screens * Use LinkAppBarState and add tests
- Loading branch information
1 parent
d138617
commit d8f7323
Showing
9 changed files
with
333 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
link/src/androidTest/java/com/stripe/android/link/ui/LinkAppBarStateTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package com.stripe.android.link.ui | ||
|
||
import androidx.activity.ComponentActivity | ||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
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 org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class LinkAppBarStateTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createAndroidComposeRule<ComponentActivity>() | ||
|
||
@Test | ||
fun rejectsBlankEmailAddress() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = true, | ||
currentRoute = LinkScreen.Wallet.route, | ||
email = " " | ||
) | ||
|
||
assertThat(state.email).isNull() | ||
} | ||
|
||
@Test | ||
fun loadingScreenShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = true, | ||
currentRoute = LinkScreen.Loading.route, | ||
email = null | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_close, | ||
hideHeader = false, | ||
email = null | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun verificationScreenShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = true, | ||
currentRoute = LinkScreen.Verification.route, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_close, | ||
hideHeader = false, | ||
email = null | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun verificationDialogShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = true, | ||
currentRoute = LinkScreen.VerificationDialog.route, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_close, | ||
hideHeader = false, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun walletScreenShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = true, | ||
currentRoute = LinkScreen.Wallet.route, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_close, | ||
hideHeader = false, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun paymentMethodScreenShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = false, | ||
currentRoute = LinkScreen.PaymentMethod.route, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_back, | ||
hideHeader = true, | ||
email = null | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun cardEditScreenShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = false, | ||
currentRoute = LinkScreen.CardEdit.route, | ||
email = "someone@stripe.com" | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_back, | ||
hideHeader = true, | ||
email = null | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun signupScreenShowsCorrectAppBarState() { | ||
val state = buildLinkAppBarState( | ||
isRootScreen = true, | ||
currentRoute = LinkScreen.SignUp.route, | ||
email = null | ||
) | ||
|
||
val expected = LinkAppBarState( | ||
navigationIcon = R.drawable.ic_link_close, | ||
hideHeader = false, | ||
email = null | ||
) | ||
|
||
assertThat(state).isEqualTo(expected) | ||
} | ||
|
||
private fun buildLinkAppBarState( | ||
isRootScreen: Boolean, | ||
currentRoute: String?, | ||
email: String? | ||
): LinkAppBarState { | ||
var state: LinkAppBarState? = null | ||
|
||
composeTestRule.setContent { | ||
state = rememberLinkAppBarState(isRootScreen, currentRoute, email) | ||
} | ||
|
||
return state ?: throw AssertionError( | ||
"buildLinkAppBarState should not produce null result" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.