mirror of
https://github.com/bitwarden/android.git
synced 2026-05-30 16:43:22 -05:00
Add basic UI states to the SendScreen (#471)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.x8bit.bitwarden.ui.tools.feature.send
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.filterToOne
|
||||
import androidx.compose.ui.test.hasAnyAncestor
|
||||
import androidx.compose.ui.test.isDisplayed
|
||||
@@ -11,10 +12,13 @@ import androidx.compose.ui.test.performClick
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.util.isProgressBar
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
@@ -109,8 +113,34 @@ class SendScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fab should be displayed according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Loading)
|
||||
}
|
||||
composeTestRule.onNodeWithContentDescription("Add item").assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Empty)
|
||||
}
|
||||
composeTestRule.onNodeWithContentDescription("Add item").assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Error("Fail".asText()))
|
||||
}
|
||||
composeTestRule.onNodeWithContentDescription("Add item").assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Content)
|
||||
}
|
||||
composeTestRule.onNodeWithContentDescription("Add item").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on add item FAB click should send AddItemClick`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Empty)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Add item")
|
||||
.performClick()
|
||||
@@ -119,6 +149,9 @@ class SendScreenTest : BaseComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `on add item click should send AddItemClick`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Empty)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithText("Add a Send")
|
||||
.performClick()
|
||||
@@ -134,10 +167,57 @@ class SendScreenTest : BaseComposeTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on NavigateToNewSend should call onNavgiateToNewSend`() {
|
||||
fun `on NavigateToNewSend should call onNavigateToNewSend`() {
|
||||
mutableEventFlow.tryEmit(SendEvent.NavigateNewSend)
|
||||
assert(onNavigateToNewSendCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `progressbar should be displayed according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Loading)
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Empty)
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Error("Fail".asText()))
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Content)
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `error should be displayed according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Error("Fail".asText()))
|
||||
}
|
||||
composeTestRule.onNodeWithText("Fail").assertIsDisplayed()
|
||||
composeTestRule.onNodeWithText("Try again").assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on try again click should send send RefreshClick`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = SendState.ViewState.Error("Fail".asText()))
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText("Try again").performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(SendAction.RefreshClick)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE = SendState.Empty
|
||||
private val DEFAULT_STATE: SendState = SendState(
|
||||
viewState = SendState.ViewState.Loading,
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ class SendViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `initial state should be Empty`() {
|
||||
val viewModel = createViewModel()
|
||||
assertEquals(SendState.Empty, viewModel.stateFlow.value)
|
||||
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,6 +61,18 @@ class SendViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `RefreshClick should call sync`() {
|
||||
val viewModel = createViewModel()
|
||||
every { vaultRepo.sync() } just runs
|
||||
|
||||
viewModel.trySendAction(SendAction.RefreshClick)
|
||||
|
||||
verify {
|
||||
vaultRepo.sync()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SearchClick should emit ShowToast`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
@@ -92,3 +104,11 @@ class SendViewModelTest : BaseViewModelTest() {
|
||||
vaultRepo = vaultRepository,
|
||||
)
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE: SendState = SendState(
|
||||
viewState = SendState.ViewState.Loading,
|
||||
)
|
||||
|
||||
private val DEFAULT_ERROR_STATE: SendState = DEFAULT_STATE.copy(
|
||||
viewState = SendState.ViewState.Error("Fail".asText()),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user