mirror of
https://github.com/bitwarden/android.git
synced 2025-02-16 20:09:59 +03:00
Back button on TrustedDeviceScreen should logout (#1162)
This commit is contained in:
parent
0f581e6e21
commit
186ef16974
6 changed files with 10 additions and 32 deletions
|
@ -111,9 +111,7 @@ fun NavGraphBuilder.authGraph(navController: NavHostController) {
|
|||
masterPasswordHintDestination(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
trustedDeviceDestination(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
trustedDeviceDestination()
|
||||
twoFactorLoginDestination(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
|
|
|
@ -26,18 +26,14 @@ data class TrustedDeviceArgs(val emailAddress: String) {
|
|||
/**
|
||||
* Add the Trusted Device Screen to the nav graph.
|
||||
*/
|
||||
fun NavGraphBuilder.trustedDeviceDestination(
|
||||
onNavigateBack: () -> Unit,
|
||||
) {
|
||||
fun NavGraphBuilder.trustedDeviceDestination() {
|
||||
composableWithSlideTransitions(
|
||||
route = TRUSTED_DEVICE_ROUTE,
|
||||
arguments = listOf(
|
||||
navArgument(EMAIL_ADDRESS) { type = NavType.StringType },
|
||||
),
|
||||
) {
|
||||
TrustedDeviceScreen(
|
||||
onNavigateBack = onNavigateBack,
|
||||
)
|
||||
TrustedDeviceScreen()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ import com.x8bit.bitwarden.ui.platform.components.toggle.BitwardenSwitch
|
|||
@Composable
|
||||
fun TrustedDeviceScreen(
|
||||
viewModel: TrustedDeviceViewModel = hiltViewModel(),
|
||||
onNavigateBack: () -> Unit,
|
||||
) {
|
||||
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
|
||||
val handlers = remember(viewModel) { TrustedDeviceHandlers.create(viewModel = viewModel) }
|
||||
|
@ -55,7 +54,6 @@ fun TrustedDeviceScreen(
|
|||
val context = LocalContext.current
|
||||
EventsEffect(viewModel = viewModel) { event ->
|
||||
when (event) {
|
||||
TrustedDeviceEvent.NavigateBack -> onNavigateBack()
|
||||
is TrustedDeviceEvent.ShowToast -> {
|
||||
Toast
|
||||
.makeText(context, event.message(context.resources), Toast.LENGTH_SHORT)
|
||||
|
|
|
@ -49,7 +49,7 @@ class TrustedDeviceViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleBackClick() {
|
||||
sendEvent(TrustedDeviceEvent.NavigateBack)
|
||||
authRepository.logout()
|
||||
}
|
||||
|
||||
private fun handleRememberToggle(action: TrustedDeviceAction.RememberToggle) {
|
||||
|
@ -95,11 +95,6 @@ data class TrustedDeviceState(
|
|||
* Models events for the Trusted Device screen.
|
||||
*/
|
||||
sealed class TrustedDeviceEvent {
|
||||
/**
|
||||
* Navigates back.
|
||||
*/
|
||||
data object NavigateBack : TrustedDeviceEvent()
|
||||
|
||||
/**
|
||||
* Displays the [message] as a toast.
|
||||
*/
|
||||
|
|
|
@ -16,12 +16,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.update
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
|
||||
class TrustedDeviceScreenTest : BaseComposeTest() {
|
||||
|
||||
private var onNavigateBackCalled: Boolean = false
|
||||
|
||||
private val mutableEventFlow = bufferedMutableSharedFlow<TrustedDeviceEvent>()
|
||||
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
|
||||
val viewModel = mockk<TrustedDeviceViewModel>(relaxed = true) {
|
||||
|
@ -34,17 +31,10 @@ class TrustedDeviceScreenTest : BaseComposeTest() {
|
|||
composeTestRule.setContent {
|
||||
TrustedDeviceScreen(
|
||||
viewModel = viewModel,
|
||||
onNavigateBack = { onNavigateBackCalled = true },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on NavigateBack should call onNavigateBack`() {
|
||||
mutableEventFlow.tryEmit(TrustedDeviceEvent.NavigateBack)
|
||||
assertTrue(onNavigateBackCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on back click should send BackClick`() {
|
||||
composeTestRule.onNodeWithContentDescription("Close").performClick()
|
||||
|
|
|
@ -24,12 +24,13 @@ class TrustedDeviceViewModelTest : BaseViewModelTest() {
|
|||
private val environmentRepo: FakeEnvironmentRepository = FakeEnvironmentRepository()
|
||||
|
||||
@Test
|
||||
fun `on BackClick emits NavigateBack`() = runTest {
|
||||
fun `on BackClick should logout`() {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(TrustedDeviceAction.BackClick)
|
||||
assertEquals(TrustedDeviceEvent.NavigateBack, awaitItem())
|
||||
viewModel.trySendAction(TrustedDeviceAction.BackClick)
|
||||
|
||||
verify(exactly = 1) {
|
||||
authRepository.logout()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +88,7 @@ class TrustedDeviceViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `on NotYouClick emits ShowToast`() {
|
||||
fun `on NotYouClick should logout`() {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
viewModel.trySendAction(TrustedDeviceAction.NotYouClick)
|
||||
|
|
Loading…
Add table
Reference in a new issue