diff --git a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt index 3ca54b27483..485ca4f0dbc 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt @@ -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 @@ -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) } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt index 121b98ed3a6..932c0a2a126 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt @@ -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) + } + } }