mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 20:07:59 -06:00
Add VaultTakeover tests
Create comprehensive unit tests for VaultTakeover feature: VaultTakeoverViewModelTest: - Test ContinueClicked sends NavigateToVault event - Test DeclineAndLeaveClicked sends NavigateToLeaveOrganization event - Test HelpLinkClicked sends LaunchUri event with help URL VaultTakeoverScreenTest: - Test title displays with organization name - Test description text is displayed correctly - Test Continue button sends ContinueClicked action - Test Decline and leave button sends DeclineAndLeaveClicked action - Test Help link sends HelpLinkClicked action - Test navigation events trigger callbacks Tests follow established patterns using BitwardenComposeTest and BaseViewModelTest. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
67bea18a84
commit
2f81483db3
@ -0,0 +1,101 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.vaulttakeover
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.platform.base.BitwardenComposeTest
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
|
||||
class VaultTakeoverScreenTest : BitwardenComposeTest() {
|
||||
private var onNavigateToVaultCalled = false
|
||||
private var onNavigateToLeaveOrganizationCalled = false
|
||||
|
||||
private val mutableEventFlow = bufferedMutableSharedFlow<VaultTakeoverEvent>()
|
||||
|
||||
private val mutableStateFlow = MutableStateFlow(
|
||||
VaultTakeoverState(
|
||||
organizationName = "Test Organization",
|
||||
),
|
||||
)
|
||||
|
||||
private val viewModel = mockk<VaultTakeoverViewModel>(relaxed = true) {
|
||||
every { eventFlow } returns mutableEventFlow
|
||||
every { stateFlow } returns mutableStateFlow
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
setContent {
|
||||
VaultTakeoverScreen(
|
||||
viewModel = viewModel,
|
||||
onNavigateToVault = { onNavigateToVaultCalled = true },
|
||||
onNavigateToLeaveOrganization = { onNavigateToLeaveOrganizationCalled = true },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `title should display with organization name`() {
|
||||
composeTestRule
|
||||
.onNodeWithText("Transfer items to Test Organization")
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `description text should be displayed`() {
|
||||
composeTestRule
|
||||
.onNodeWithText(
|
||||
"Test Organization is requiring all items to be owned by the " +
|
||||
"organization for security and compliance. Click accept to transfer " +
|
||||
"ownership of your items.",
|
||||
substring = true,
|
||||
)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Continue button click should send ContinueClicked action`() {
|
||||
composeTestRule.onNodeWithText("Continue").performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(VaultTakeoverAction.ContinueClicked)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Decline and leave button click should send DeclineAndLeaveClicked action`() {
|
||||
composeTestRule.onNodeWithText("Decline and leave").performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(VaultTakeoverAction.DeclineAndLeaveClicked)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Why am I seeing this link click should send HelpLinkClicked action`() {
|
||||
composeTestRule.onNodeWithText("Why am I seeing this?").performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(VaultTakeoverAction.HelpLinkClicked)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToVault event should trigger navigation callback`() {
|
||||
mutableEventFlow.tryEmit(VaultTakeoverEvent.NavigateToVault)
|
||||
assertTrue(onNavigateToVaultCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToLeaveOrganization event should trigger navigation callback`() {
|
||||
mutableEventFlow.tryEmit(VaultTakeoverEvent.NavigateToLeaveOrganization)
|
||||
assertTrue(onNavigateToLeaveOrganizationCalled)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.vaulttakeover
|
||||
|
||||
import app.cash.turbine.test
|
||||
import com.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class VaultTakeoverViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `ContinueClicked sends NavigateToVault event`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(VaultTakeoverAction.ContinueClicked)
|
||||
assertEquals(VaultTakeoverEvent.NavigateToVault, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `DeclineAndLeaveClicked sends NavigateToLeaveOrganization event`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(VaultTakeoverAction.DeclineAndLeaveClicked)
|
||||
assertEquals(VaultTakeoverEvent.NavigateToLeaveOrganization, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `HelpLinkClicked sends LaunchUri event with help URL`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(VaultTakeoverAction.HelpLinkClicked)
|
||||
val event = awaitItem()
|
||||
assert(event is VaultTakeoverEvent.LaunchUri)
|
||||
assertEquals("TODO_HELP_URL", (event as VaultTakeoverEvent.LaunchUri).uri)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createViewModel(): VaultTakeoverViewModel =
|
||||
VaultTakeoverViewModel()
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user