Adding Navigation to the verification code screen and skeleton UI (#697)

This commit is contained in:
Oleg Semenenko authored and Álison Fernandes committed 2024-06-20 17:08:07 +01:00
1 parent 1a53178137
commit cd1d326d45
8 files changed
+296 -3

No files matched your search

@@ -60,6 +60,7 @@ class VaultScreenTest : BaseComposeTest() {
private var onNavigateToVaultEditItemId: String? = null
private var onNavigateToVaultItemListingType: VaultItemListingType? = null
private var onDimBottomNavBarRequestCalled = false
private var onNavigateToVerificationCodeScreen = false
private val intentManager = mockk<IntentManager>(relaxed = true)
private val mutableEventFlow = bufferedMutableSharedFlow<VaultEvent>()
@@ -79,6 +80,7 @@ class VaultScreenTest : BaseComposeTest() {
onNavigateToVaultEditItemScreen = { onNavigateToVaultEditItemId = it },
onNavigateToVaultItemListingScreen = { onNavigateToVaultItemListingType = it },
onDimBottomNavBarRequest = { onDimBottomNavBarRequestCalled = true },
onNavigateToVerificationCodeScreen = { onNavigateToVerificationCodeScreen = true },
intentManager = intentManager,
)
}
@@ -533,6 +535,30 @@ class VaultScreenTest : BaseComposeTest() {
verify { viewModel.trySendAction(VaultAction.TryAgainClick) }
}
@Test
fun `verification code click should call VerificationCodesClick `() {
mutableStateFlow.update {
it.copy(
viewState = DEFAULT_CONTENT_VIEW_STATE.copy(
totpItemsCount = 3,
),
isPremium = true,
)
}
composeTestRule
.onNodeWithText("Verification codes")
.performClick()
verify { viewModel.trySendAction(VaultAction.VerificationCodesClick) }
}
@Test
fun `NavigateToVerificationCodeScreen event should call onNavigateToVerificationCodeScreen`() {
mutableEventFlow.tryEmit(VaultEvent.NavigateToVerificationCodeScreen)
assertTrue(onNavigateToVerificationCodeScreen)
}
@Test
fun `search icon click should send SearchIconClick action`() {
mutableStateFlow.update { it.copy(viewState = VaultState.ViewState.NoItems) }
@@ -0,0 +1,41 @@
package com.x8bit.bitwarden.ui.vault.feature.verificationcode
import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class VerificationCodeViewModelTest : BaseViewModelTest() {
@Test
fun `on BackClick should emit NavigateBack`() = runTest {
val viewModel = createViewModel()
viewModel.eventFlow.test {
viewModel.trySendAction(VerificationCodeAction.BackClick)
assertEquals(VerificationCodeEvent.NavigateBack, awaitItem())
}
}
@Test
fun `on ItemClick should emit ItemClick`() = runTest {
val viewModel = createViewModel()
val testId = "testId"
viewModel.eventFlow.test {
viewModel.trySendAction(VerificationCodeAction.ItemClick(testId))
assertEquals(VerificationCodeEvent.NavigateToVaultItem(testId), awaitItem())
}
}
private fun createViewModel(
state: VerificationCodeState? = DEFAULT_STATE,
): VerificationCodeViewModel = VerificationCodeViewModel(
savedStateHandle = SavedStateHandle().apply { set("state", state) },
)
}
private val DEFAULT_STATE: VerificationCodeState = VerificationCodeState(
VerificationCodeState.ViewState.Empty,
)