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.createaccount.navigateToCreateAccount
|
||||||
import com.x8bit.bitwarden.ui.auth.feature.landing.LANDING_ROUTE
|
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.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.loginDestinations
|
||||||
import com.x8bit.bitwarden.ui.auth.feature.login.navigateToLogin
|
import com.x8bit.bitwarden.ui.auth.feature.login.navigateToLogin
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ fun NavGraphBuilder.authDestinations(navController: NavHostController) {
|
||||||
onNavigateToLogin = { emailAddress -> navController.navigateToLogin(emailAddress) },
|
onNavigateToLogin = { emailAddress -> navController.navigateToLogin(emailAddress) },
|
||||||
)
|
)
|
||||||
loginDestinations(
|
loginDestinations(
|
||||||
onNavigateToLanding = { navController.navigateToLanding() },
|
onNavigateBack = { navController.popBackStack() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ fun NavController.navigateToLogin(
|
||||||
* Add the Login screen to the nav graph.
|
* Add the Login screen to the nav graph.
|
||||||
*/
|
*/
|
||||||
fun NavGraphBuilder.loginDestinations(
|
fun NavGraphBuilder.loginDestinations(
|
||||||
onNavigateToLanding: () -> Unit,
|
onNavigateBack: () -> Unit,
|
||||||
) {
|
) {
|
||||||
composable(
|
composable(
|
||||||
route = LOGIN_ROUTE,
|
route = LOGIN_ROUTE,
|
||||||
|
@ -43,7 +43,7 @@ fun NavGraphBuilder.loginDestinations(
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
onNavigateToLanding = { onNavigateToLanding() },
|
onNavigateBack = onNavigateBack,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField
|
||||||
@Composable
|
@Composable
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
fun LoginScreen(
|
fun LoginScreen(
|
||||||
onNavigateToLanding: () -> Unit,
|
onNavigateBack: () -> Unit,
|
||||||
viewModel: LoginViewModel = hiltViewModel(),
|
viewModel: LoginViewModel = hiltViewModel(),
|
||||||
intentHandler: IntentHandler = IntentHandler(context = LocalContext.current),
|
intentHandler: IntentHandler = IntentHandler(context = LocalContext.current),
|
||||||
) {
|
) {
|
||||||
|
@ -40,7 +40,7 @@ fun LoginScreen(
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
EventsEffect(viewModel = viewModel) { event ->
|
EventsEffect(viewModel = viewModel) { event ->
|
||||||
when (event) {
|
when (event) {
|
||||||
LoginEvent.NavigateToLanding -> onNavigateToLanding()
|
LoginEvent.NavigateBack -> onNavigateBack()
|
||||||
is LoginEvent.NavigateToCaptcha -> intentHandler.startActivity(intent = event.intent)
|
is LoginEvent.NavigateToCaptcha -> intentHandler.startActivity(intent = event.intent)
|
||||||
is LoginEvent.ShowErrorDialog -> {
|
is LoginEvent.ShowErrorDialog -> {
|
||||||
// TODO Show proper error Dialog
|
// TODO Show proper error Dialog
|
||||||
|
|
|
@ -104,7 +104,7 @@ class LoginViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleNotYouButtonClicked() {
|
private fun handleNotYouButtonClicked() {
|
||||||
sendEvent(LoginEvent.NavigateToLanding)
|
sendEvent(LoginEvent.NavigateBack)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSingleSignOnClicked() {
|
private fun handleSingleSignOnClicked() {
|
||||||
|
@ -131,9 +131,9 @@ data class LoginState(
|
||||||
*/
|
*/
|
||||||
sealed class LoginEvent {
|
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.
|
* Navigates to the captcha verification screen.
|
||||||
|
|
|
@ -31,7 +31,7 @@ class LoginScreenTest : BaseComposeTest() {
|
||||||
}
|
}
|
||||||
composeTestRule.setContent {
|
composeTestRule.setContent {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
onNavigateToLanding = {},
|
onNavigateBack = {},
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class LoginScreenTest : BaseComposeTest() {
|
||||||
}
|
}
|
||||||
composeTestRule.setContent {
|
composeTestRule.setContent {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
onNavigateToLanding = {},
|
onNavigateBack = {},
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,10 @@ class LoginScreenTest : BaseComposeTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `NavigateToLanding should call onNavigateToLanding`() {
|
fun `NavigateBack should call onNavigateBack`() {
|
||||||
var onNavigateToLandingCalled = false
|
var onNavigateBackCalled = false
|
||||||
val viewModel = mockk<LoginViewModel>(relaxed = true) {
|
val viewModel = mockk<LoginViewModel>(relaxed = true) {
|
||||||
every { eventFlow } returns flowOf(LoginEvent.NavigateToLanding)
|
every { eventFlow } returns flowOf(LoginEvent.NavigateBack)
|
||||||
every { stateFlow } returns MutableStateFlow(
|
every { stateFlow } returns MutableStateFlow(
|
||||||
LoginState(
|
LoginState(
|
||||||
emailAddress = "",
|
emailAddress = "",
|
||||||
|
@ -81,11 +81,11 @@ class LoginScreenTest : BaseComposeTest() {
|
||||||
}
|
}
|
||||||
composeTestRule.setContent {
|
composeTestRule.setContent {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
onNavigateToLanding = { onNavigateToLandingCalled = true },
|
onNavigateBack = { onNavigateBackCalled = true },
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
assertTrue(onNavigateToLandingCalled)
|
assertTrue(onNavigateBackCalled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -106,7 +106,7 @@ class LoginScreenTest : BaseComposeTest() {
|
||||||
}
|
}
|
||||||
composeTestRule.setContent {
|
composeTestRule.setContent {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
onNavigateToLanding = {},
|
onNavigateBack = {},
|
||||||
intentHandler = intentHandler,
|
intentHandler = intentHandler,
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
)
|
)
|
||||||
|
|
|
@ -161,7 +161,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `NotYouButtonClick should emit NavigateToLanding`() = runTest {
|
fun `NotYouButtonClick should emit NavigateBack`() = runTest {
|
||||||
val viewModel = LoginViewModel(
|
val viewModel = LoginViewModel(
|
||||||
authRepository = mockk {
|
authRepository = mockk {
|
||||||
every { captchaTokenResultFlow } returns flowOf()
|
every { captchaTokenResultFlow } returns flowOf()
|
||||||
|
@ -171,7 +171,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||||
viewModel.eventFlow.test {
|
viewModel.eventFlow.test {
|
||||||
viewModel.actionChannel.trySend(LoginAction.NotYouButtonClick)
|
viewModel.actionChannel.trySend(LoginAction.NotYouButtonClick)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
LoginEvent.NavigateToLanding,
|
LoginEvent.NavigateBack,
|
||||||
awaitItem(),
|
awaitItem(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue