Rename VaultScreen to VaultSettingsScreen (#237)

This commit is contained in:
David Perez 2023-11-10 15:58:34 -06:00 committed by Álison Fernandes
parent 382c4a0172
commit 62d82b5304
7 changed files with 66 additions and 65 deletions

View file

@ -15,8 +15,8 @@ import com.x8bit.bitwarden.ui.platform.feature.settings.autofill.autoFillDestina
import com.x8bit.bitwarden.ui.platform.feature.settings.autofill.navigateToAutoFill
import com.x8bit.bitwarden.ui.platform.feature.settings.other.navigateToOther
import com.x8bit.bitwarden.ui.platform.feature.settings.other.otherDestination
import com.x8bit.bitwarden.ui.platform.feature.settings.vault.navigateToVault
import com.x8bit.bitwarden.ui.platform.feature.settings.vault.vaultDestination
import com.x8bit.bitwarden.ui.platform.feature.settings.vault.navigateToVaultSettings
import com.x8bit.bitwarden.ui.platform.feature.settings.vault.vaultSettingsDestination
import com.x8bit.bitwarden.ui.platform.theme.TransitionProviders
const val SETTINGS_GRAPH_ROUTE: String = "settings_graph"
@ -45,7 +45,7 @@ fun NavGraphBuilder.settingsGraph(
onNavigateToAppearance = { navController.navigateToAppearance() },
onNavigateToAutoFill = { navController.navigateToAutoFill() },
onNavigateToOther = { navController.navigateToOther() },
onNavigateToVault = { navController.navigateToVault() },
onNavigateToVault = { navController.navigateToVaultSettings() },
)
}
aboutDestination(onNavigateBack = { navController.popBackStack() })
@ -53,7 +53,7 @@ fun NavGraphBuilder.settingsGraph(
appearanceDestination(onNavigateBack = { navController.popBackStack() })
autoFillDestination(onNavigateBack = { navController.popBackStack() })
otherDestination(onNavigateBack = { navController.popBackStack() })
vaultDestination(onNavigateBack = { navController.popBackStack() })
vaultSettingsDestination(onNavigateBack = { navController.popBackStack() })
}
}

View file

@ -6,28 +6,28 @@ import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.x8bit.bitwarden.ui.platform.theme.TransitionProviders
private const val VAULT_ROUTE = "settings_vault"
private const val VAULT_SETTINGS_ROUTE = "vault_settings"
/**
* Add settings destinations to the nav graph.
* Add vault settings destinations to the nav graph.
*/
fun NavGraphBuilder.vaultDestination(
fun NavGraphBuilder.vaultSettingsDestination(
onNavigateBack: () -> Unit,
) {
composable(
route = VAULT_ROUTE,
route = VAULT_SETTINGS_ROUTE,
enterTransition = TransitionProviders.Enter.pushLeft,
exitTransition = TransitionProviders.Exit.pushLeft,
popEnterTransition = TransitionProviders.Enter.pushLeft,
popExitTransition = TransitionProviders.Exit.pushRight,
) {
VaultScreen(onNavigateBack = onNavigateBack)
VaultSettingsScreen(onNavigateBack = onNavigateBack)
}
}
/**
* Navigate to the vault screen.
* Navigate to the vault settings screen.
*/
fun NavController.navigateToVault(navOptions: NavOptions? = null) {
navigate(VAULT_ROUTE, navOptions)
fun NavController.navigateToVaultSettings(navOptions: NavOptions? = null) {
navigate(VAULT_SETTINGS_ROUTE, navOptions)
}

View file

@ -25,13 +25,13 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun VaultScreen(
fun VaultSettingsScreen(
onNavigateBack: () -> Unit,
viewModel: VaultViewModel = hiltViewModel(),
viewModel: VaultSettingsViewModel = hiltViewModel(),
) {
EventsEffect(viewModel = viewModel) { event ->
when (event) {
VaultEvent.NavigateBack -> onNavigateBack.invoke()
VaultSettingsEvent.NavigateBack -> onNavigateBack.invoke()
}
}
@ -47,7 +47,7 @@ fun VaultScreen(
navigationIcon = painterResource(id = R.drawable.ic_back),
navigationIconContentDescription = stringResource(id = R.string.back),
onNavigationIconClick = remember(viewModel) {
{ viewModel.trySendAction(VaultAction.BackClick) }
{ viewModel.trySendAction(VaultSettingsAction.BackClick) }
},
)
},

View file

@ -0,0 +1,38 @@
package com.x8bit.bitwarden.ui.platform.feature.settings.vault
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
/**
* View model for the vault screen.
*/
@HiltViewModel
class VaultSettingsViewModel @Inject constructor() :
BaseViewModel<Unit, VaultSettingsEvent, VaultSettingsAction>(
initialState = Unit,
) {
override fun handleAction(action: VaultSettingsAction): Unit = when (action) {
VaultSettingsAction.BackClick -> sendEvent(VaultSettingsEvent.NavigateBack)
}
}
/**
* Models events for the vault screen.
*/
sealed class VaultSettingsEvent {
/**
* Navigate back.
*/
data object NavigateBack : VaultSettingsEvent()
}
/**
* Models actions for the vault screen.
*/
sealed class VaultSettingsAction {
/**
* User clicked back button.
*/
data object BackClick : VaultSettingsAction()
}

View file

@ -1,37 +0,0 @@
package com.x8bit.bitwarden.ui.platform.feature.settings.vault
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
/**
* View model for the vault screen.
*/
@HiltViewModel
class VaultViewModel @Inject constructor() : BaseViewModel<Unit, VaultEvent, VaultAction>(
initialState = Unit,
) {
override fun handleAction(action: VaultAction): Unit = when (action) {
VaultAction.BackClick -> sendEvent(VaultEvent.NavigateBack)
}
}
/**
* Models events for the vault screen.
*/
sealed class VaultEvent {
/**
* Navigate back.
*/
data object NavigateBack : VaultEvent()
}
/**
* Models actions for the vault screen.
*/
sealed class VaultAction {
/**
* User clicked back button.
*/
data object BackClick : VaultAction()
}

View file

@ -11,32 +11,32 @@ import kotlinx.coroutines.flow.flowOf
import org.junit.Assert.assertTrue
import org.junit.Test
class VaultScreenTest : BaseComposeTest() {
class VaultSettingsScreenTest : BaseComposeTest() {
@Test
fun `on back click should send BackClick`() {
val viewModel: VaultViewModel = mockk {
val viewModel: VaultSettingsViewModel = mockk {
every { eventFlow } returns emptyFlow()
every { trySendAction(VaultAction.BackClick) } returns Unit
every { trySendAction(VaultSettingsAction.BackClick) } returns Unit
}
composeTestRule.setContent {
VaultScreen(
VaultSettingsScreen(
viewModel = viewModel,
onNavigateBack = { },
)
}
composeTestRule.onNodeWithContentDescription("Back").performClick()
verify { viewModel.trySendAction(VaultAction.BackClick) }
verify { viewModel.trySendAction(VaultSettingsAction.BackClick) }
}
@Test
fun `on NavigateAbout should call onNavigateToVault`() {
var haveCalledNavigateBack = false
val viewModel = mockk<VaultViewModel> {
every { eventFlow } returns flowOf(VaultEvent.NavigateBack)
val viewModel = mockk<VaultSettingsViewModel> {
every { eventFlow } returns flowOf(VaultSettingsEvent.NavigateBack)
}
composeTestRule.setContent {
VaultScreen(
VaultSettingsScreen(
viewModel = viewModel,
onNavigateBack = { haveCalledNavigateBack = true },
)

View file

@ -6,14 +6,14 @@ import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class VaultViewModelTest : BaseViewModelTest() {
class VaultSettingsViewModelTest : BaseViewModelTest() {
@Test
fun `on BackClick should emit NavigateBack`() = runTest {
val viewModel = VaultViewModel()
val viewModel = VaultSettingsViewModel()
viewModel.eventFlow.test {
viewModel.trySendAction(VaultAction.BackClick)
assertEquals(VaultEvent.NavigateBack, awaitItem())
viewModel.trySendAction(VaultSettingsAction.BackClick)
assertEquals(VaultSettingsEvent.NavigateBack, awaitItem())
}
}
}