BIT-1938: Display toast after updating cipher collection or moving cipher to an organization (#1058)

This commit is contained in:
David Perez 2024-02-22 18:12:05 -06:00 committed by Álison Fernandes
parent c779482bf8
commit 86756a4698
2 changed files with 33 additions and 12 deletions

View file

@ -10,7 +10,6 @@ import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.repository.model.DataState
import com.x8bit.bitwarden.data.platform.repository.util.combineDataStates
import com.x8bit.bitwarden.data.platform.repository.util.map
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
import com.x8bit.bitwarden.data.vault.repository.model.ShareCipherResult
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
@ -165,6 +164,7 @@ class VaultMoveToOrganizationViewModel @Inject constructor(
is ShareCipherResult.Success -> {
sendEvent(VaultMoveToOrganizationEvent.NavigateBack)
sendEvent(VaultMoveToOrganizationEvent.ShowToast(action.successToast))
}
}
}
@ -285,23 +285,30 @@ class VaultMoveToOrganizationViewModel @Inject constructor(
}
viewModelScope.launch {
trySendAction(
VaultMoveToOrganizationAction.Internal.ShareCipherResultReceive(
if (state.onlyShowCollections) {
vaultRepository.updateCipherCollections(
cipherId = mutableStateFlow.value.vaultItemId,
VaultMoveToOrganizationAction.Internal.ShareCipherResultReceive(
shareCipherResult = vaultRepository.updateCipherCollections(
cipherId = state.vaultItemId,
cipherView = cipherView,
collectionIds = collectionIds,
),
successToast = R.string.item_updated.asText(),
)
} else {
vaultRepository.shareCipher(
cipherId = mutableStateFlow.value.vaultItemId,
VaultMoveToOrganizationAction.Internal.ShareCipherResultReceive(
shareCipherResult = vaultRepository.shareCipher(
cipherId = state.vaultItemId,
cipherView = cipherView.copy(
organizationId = contentState.selectedOrganizationId,
),
collectionIds = collectionIds,
),
successToast = R.string.moved_item_to_org.asText(
requireNotNull(contentState.cipherToMove).name,
contentState.selectedOrganization.name,
),
)
},
),
)
}
}
@ -491,6 +498,7 @@ sealed class VaultMoveToOrganizationAction {
*/
data class ShareCipherResultReceive(
val shareCipherResult: ShareCipherResult,
val successToast: Text,
) : Internal()
}
}

View file

@ -368,6 +368,15 @@ class VaultMoveToOrganizationViewModelTest : BaseViewModelTest() {
VaultMoveToOrganizationEvent.NavigateBack,
awaitItem(),
)
assertEquals(
VaultMoveToOrganizationEvent.ShowToast(
text = R.string.moved_item_to_org.asText(
"mockName-1",
"mockOrganizationName-1",
),
),
awaitItem(),
)
}
coVerify {
vaultRepository.shareCipher(
@ -403,6 +412,10 @@ class VaultMoveToOrganizationViewModelTest : BaseViewModelTest() {
VaultMoveToOrganizationEvent.NavigateBack,
awaitItem(),
)
assertEquals(
VaultMoveToOrganizationEvent.ShowToast(R.string.item_updated.asText()),
awaitItem(),
)
}
coVerify {
vaultRepository.updateCipherCollections(