Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk committed Aug 28, 2023
1 parent 81db76a commit a762b4d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wire.android.ui.home.newconversation.common.CreateGroupState
import com.wire.android.ui.home.newconversation.model.Contact
import com.wire.android.util.ui.WireSessionImageLoader
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
Expand Down Expand Up @@ -213,6 +214,18 @@ internal class NewConversationViewModelArrangement {
coEvery { searchKnownUsers(any()) } returns flowOf(SearchUsersResult.Failure.InvalidRequest)
}

fun withFailureGetAllKnownUsersResponse() = apply {
coEvery { getAllKnownUsers() } returns flowOf(GetAllContactsResult.Failure(StorageFailure.DataNotFound))
}

fun withEmptySuccessGetAllKnownUsersResponse() = apply {
coEvery { getAllKnownUsers() } returns flowOf(GetAllContactsResult.Success(emptyList()))
}

fun withSuccessGetAllKnownUsersResponse() = apply {
coEvery { getAllKnownUsers() } returns flowOf(GetAllContactsResult.Success(listOf(FEDERATED_KNOWN_USER)))
}

fun withFailurePublicSearchResponse() = apply {
coEvery { searchPublicUsers(any()) } returns flowOf(SearchUsersResult.Failure.InvalidRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,46 @@ class NewConversationViewModelTest {
)
}
}

@Test
fun `given user has no contacts and getting contacts succeeded, then initialContacts has value of EmptyResult`() {
runTest {
// Given
val (_, viewModel) = NewConversationViewModelArrangement()
.withIsSelfTeamMember(true)
.withEmptySuccessGetAllKnownUsersResponse()
.arrange()
advanceUntilIdle()
// Then
assert(viewModel.state.initialContacts is SearchResultState.EmptyResult)
}
}

@Test
fun `given user has some contacts and getting contacts succeeded, then initialContacts has value of Success`() {
runTest {
// Given
val (_, viewModel) = NewConversationViewModelArrangement()
.withIsSelfTeamMember(true)
.withSuccessGetAllKnownUsersResponse()
.arrange()
advanceUntilIdle()
// Then
assert(viewModel.state.initialContacts is SearchResultState.Success)
}
}

@Test
fun `given user has some contacts and getting contacts failed, then initialContacts has value of Failure`() {
runTest {
// Given
val (_, viewModel) = NewConversationViewModelArrangement()
.withIsSelfTeamMember(true)
.withFailureGetAllKnownUsersResponse()
.arrange()
advanceUntilIdle()
// Then
assert(viewModel.state.initialContacts is SearchResultState.Failure)
}
}
}

0 comments on commit a762b4d

Please sign in to comment.