mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 07:11:51 +03:00
Explicitly navigate back from login screen when clicking Not You (#87)
This commit is contained in:
parent
bac5e4e030
commit
4f20dc611c
6 changed files with 18 additions and 19 deletions
|
@ -9,7 +9,6 @@ import com.x8bit.bitwarden.ui.auth.feature.createaccount.createAccountDestinatio
|
|||
import com.x8bit.bitwarden.ui.auth.feature.createaccount.navigateToCreateAccount
|
||||
import com.x8bit.bitwarden.ui.auth.feature.landing.LANDING_ROUTE
|
||||
import com.x8bit.bitwarden.ui.auth.feature.landing.landingDestinations
|
||||
import com.x8bit.bitwarden.ui.auth.feature.landing.navigateToLanding
|
||||
import com.x8bit.bitwarden.ui.auth.feature.login.loginDestinations
|
||||
import com.x8bit.bitwarden.ui.auth.feature.login.navigateToLogin
|
||||
|
||||
|
@ -29,7 +28,7 @@ fun NavGraphBuilder.authDestinations(navController: NavHostController) {
|
|||
onNavigateToLogin = { emailAddress -> navController.navigateToLogin(emailAddress) },
|
||||
)
|
||||
loginDestinations(
|
||||
onNavigateToLanding = { navController.navigateToLanding() },
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ fun NavController.navigateToLogin(
|
|||
* Add the Login screen to the nav graph.
|
||||
*/
|
||||
fun NavGraphBuilder.loginDestinations(
|
||||
onNavigateToLanding: () -> Unit,
|
||||
onNavigateBack: () -> Unit,
|
||||
) {
|
||||
composable(
|
||||
route = LOGIN_ROUTE,
|
||||
|
@ -43,7 +43,7 @@ fun NavGraphBuilder.loginDestinations(
|
|||
),
|
||||
) {
|
||||
LoginScreen(
|
||||
onNavigateToLanding = { onNavigateToLanding() },
|
||||
onNavigateBack = onNavigateBack,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField
|
|||
@Composable
|
||||
@Suppress("LongMethod")
|
||||
fun LoginScreen(
|
||||
onNavigateToLanding: () -> Unit,
|
||||
onNavigateBack: () -> Unit,
|
||||
viewModel: LoginViewModel = hiltViewModel(),
|
||||
intentHandler: IntentHandler = IntentHandler(context = LocalContext.current),
|
||||
) {
|
||||
|
@ -40,7 +40,7 @@ fun LoginScreen(
|
|||
val context = LocalContext.current
|
||||
EventsEffect(viewModel = viewModel) { event ->
|
||||
when (event) {
|
||||
LoginEvent.NavigateToLanding -> onNavigateToLanding()
|
||||
LoginEvent.NavigateBack -> onNavigateBack()
|
||||
is LoginEvent.NavigateToCaptcha -> intentHandler.startActivity(intent = event.intent)
|
||||
is LoginEvent.ShowErrorDialog -> {
|
||||
// TODO Show proper error Dialog
|
||||
|
|
|
@ -104,7 +104,7 @@ class LoginViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleNotYouButtonClicked() {
|
||||
sendEvent(LoginEvent.NavigateToLanding)
|
||||
sendEvent(LoginEvent.NavigateBack)
|
||||
}
|
||||
|
||||
private fun handleSingleSignOnClicked() {
|
||||
|
@ -131,9 +131,9 @@ data class LoginState(
|
|||
*/
|
||||
sealed class LoginEvent {
|
||||
/**
|
||||
* Navigates to the Landing screen.
|
||||
* Navigates back to the previous screen.
|
||||
*/
|
||||
data object NavigateToLanding : LoginEvent()
|
||||
data object NavigateBack : LoginEvent()
|
||||
|
||||
/**
|
||||
* Navigates to the captcha verification screen.
|
||||
|
|
|
@ -31,7 +31,7 @@ class LoginScreenTest : BaseComposeTest() {
|
|||
}
|
||||
composeTestRule.setContent {
|
||||
LoginScreen(
|
||||
onNavigateToLanding = {},
|
||||
onNavigateBack = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class LoginScreenTest : BaseComposeTest() {
|
|||
}
|
||||
composeTestRule.setContent {
|
||||
LoginScreen(
|
||||
onNavigateToLanding = {},
|
||||
onNavigateBack = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ class LoginScreenTest : BaseComposeTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToLanding should call onNavigateToLanding`() {
|
||||
var onNavigateToLandingCalled = false
|
||||
fun `NavigateBack should call onNavigateBack`() {
|
||||
var onNavigateBackCalled = false
|
||||
val viewModel = mockk<LoginViewModel>(relaxed = true) {
|
||||
every { eventFlow } returns flowOf(LoginEvent.NavigateToLanding)
|
||||
every { eventFlow } returns flowOf(LoginEvent.NavigateBack)
|
||||
every { stateFlow } returns MutableStateFlow(
|
||||
LoginState(
|
||||
emailAddress = "",
|
||||
|
@ -81,11 +81,11 @@ class LoginScreenTest : BaseComposeTest() {
|
|||
}
|
||||
composeTestRule.setContent {
|
||||
LoginScreen(
|
||||
onNavigateToLanding = { onNavigateToLandingCalled = true },
|
||||
onNavigateBack = { onNavigateBackCalled = true },
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
assertTrue(onNavigateToLandingCalled)
|
||||
assertTrue(onNavigateBackCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -106,7 +106,7 @@ class LoginScreenTest : BaseComposeTest() {
|
|||
}
|
||||
composeTestRule.setContent {
|
||||
LoginScreen(
|
||||
onNavigateToLanding = {},
|
||||
onNavigateBack = {},
|
||||
intentHandler = intentHandler,
|
||||
viewModel = viewModel,
|
||||
)
|
||||
|
|
|
@ -161,7 +161,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `NotYouButtonClick should emit NavigateToLanding`() = runTest {
|
||||
fun `NotYouButtonClick should emit NavigateBack`() = runTest {
|
||||
val viewModel = LoginViewModel(
|
||||
authRepository = mockk {
|
||||
every { captchaTokenResultFlow } returns flowOf()
|
||||
|
@ -171,7 +171,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
|||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(LoginAction.NotYouButtonClick)
|
||||
assertEquals(
|
||||
LoginEvent.NavigateToLanding,
|
||||
LoginEvent.NavigateBack,
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue