mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Ensure FAB is hidden for some Vault Screen states (#401)
This commit is contained in:
parent
1b7e01ea89
commit
5235310de5
3 changed files with 38 additions and 5 deletions
|
@ -265,7 +265,7 @@ private fun VaultScreenScaffold(
|
|||
},
|
||||
floatingActionButton = {
|
||||
AnimatedVisibility(
|
||||
visible = !accountMenuVisible,
|
||||
visible = state.viewState.hasFab && !accountMenuVisible,
|
||||
enter = scaleIn(),
|
||||
exit = scaleOut(),
|
||||
) {
|
||||
|
|
|
@ -304,17 +304,27 @@ data class VaultState(
|
|||
@Parcelize
|
||||
sealed class ViewState : Parcelable {
|
||||
|
||||
/**
|
||||
* Determines whether or not the Floating Action Button (FAB) should be shown for the
|
||||
* given state.
|
||||
*/
|
||||
abstract val hasFab: Boolean
|
||||
|
||||
/**
|
||||
* Loading state for the [VaultScreen], signifying that the content is being processed.
|
||||
*/
|
||||
@Parcelize
|
||||
data object Loading : ViewState()
|
||||
data object Loading : ViewState() {
|
||||
override val hasFab: Boolean get() = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a state where the [VaultScreen] has no items to display.
|
||||
*/
|
||||
@Parcelize
|
||||
data object NoItems : ViewState()
|
||||
data object NoItems : ViewState() {
|
||||
override val hasFab: Boolean get() = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a state where the [VaultScreen] is unable to display data due to an error
|
||||
|
@ -323,7 +333,9 @@ data class VaultState(
|
|||
@Parcelize
|
||||
data class Error(
|
||||
val message: Text,
|
||||
) : ViewState()
|
||||
) : ViewState() {
|
||||
override val hasFab: Boolean get() = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Content state for the [VaultScreen] showing the actual content or items.
|
||||
|
@ -349,7 +361,9 @@ data class VaultState(
|
|||
val noFolderItems: List<VaultItem>,
|
||||
val collectionItems: List<CollectionItem>,
|
||||
val trashItemsCount: Int,
|
||||
) : ViewState()
|
||||
) : ViewState() {
|
||||
override val hasFab: Boolean get() = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a folder item with a name and item count.
|
||||
|
|
|
@ -283,6 +283,25 @@ class VaultScreenTest : BaseComposeTest() {
|
|||
verify { viewModel.trySendAction(VaultAction.ExitConfirmationClick) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `floating action button should be shown or hidden according to the state`() {
|
||||
val fabDescription = "Add item"
|
||||
|
||||
mutableStateFlow.update { it.copy(viewState = VaultState.ViewState.Loading) }
|
||||
composeTestRule.onNodeWithContentDescription(fabDescription).assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = VaultState.ViewState.Error("Error".asText()))
|
||||
}
|
||||
composeTestRule.onNodeWithContentDescription(fabDescription).assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update { it.copy(viewState = VaultState.ViewState.NoItems) }
|
||||
composeTestRule.onNodeWithContentDescription(fabDescription).assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update { it.copy(viewState = DEFAULT_CONTENT_VIEW_STATE) }
|
||||
composeTestRule.onNodeWithContentDescription(fabDescription).assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `error dialog should be shown or hidden according to the state`() {
|
||||
val errorTitle = "Error title"
|
||||
|
|
Loading…
Add table
Reference in a new issue