diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListState.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListState.kt index 387b60e54ce..d672962a602 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListState.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListState.kt @@ -42,8 +42,7 @@ data class ConversationListState( val unreadMentionsCount: Long = 0, val hasEstablishedCall: Boolean = false, val shouldShowJoinAnywayDialog: Boolean = false, - val shouldShowCallingPermissionDialog: Boolean = false, - val isFromArchive: Boolean = false + val shouldShowCallingPermissionDialog: Boolean = false ) { fun findConversationById(conversationId: ConversationId): ConversationItem? = foldersWithConversations.values.flatten().firstOrNull { it.conversationId == conversationId } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModel.kt index 230513cd212..edf150704aa 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModel.kt @@ -20,7 +20,6 @@ package com.wire.android.ui.home.conversationslist -import androidx.annotation.VisibleForTesting import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -186,14 +185,12 @@ class ConversationListViewModel @Inject constructor( }, hasNoConversations = conversationsWithFolders.isEmpty(), foldersWithConversations = conversationsWithFolders, - // TODO: missing other lists and counters (for bottom tabs if we decide to bring them back) - searchQuery = searchQuery.text, - isFromArchive = searchQuery.fromArchive + searchQuery = searchQuery.text ) } .flowOn(dispatcher.io()) .collect { - conversationListState = it + conversationListState = it } } } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModelTest.kt index 62c27a73af0..6caa44b8846 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/conversationslist/ConversationListViewModelTest.kt @@ -37,7 +37,7 @@ import com.wire.android.ui.home.conversationslist.model.ConversationFolder import com.wire.android.ui.home.conversationslist.model.ConversationInfo import com.wire.android.ui.home.conversationslist.model.ConversationItem import com.wire.android.ui.home.conversationslist.model.Membership -import com.wire.android.ui.home.conversationslist.model.SearchQuery +import com.wire.android.util.orDefault import com.wire.android.util.ui.WireSessionImageLoader import com.wire.kalium.logic.data.conversation.MutedConversationStatus import com.wire.kalium.logic.data.id.ConversationId @@ -66,16 +66,13 @@ import io.mockk.impl.annotations.MockK import io.mockk.verify import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.android.awaitFrame import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.StandardTestDispatcher -import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.amshove.kluent.internal.assertEquals import org.amshove.kluent.shouldBeEqualTo -import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -133,12 +130,12 @@ class ConversationListViewModelTest { private val dispatcher = StandardTestDispatcher() - init { + init { MockKAnnotations.init(this, relaxUnitFun = true) Dispatchers.setMain(dispatcher) coEvery { observeEstablishedCalls.invoke() } returns emptyFlow() - coEvery { observeConversationListDetailsUseCase.invoke(any()) } returns flowOf( + coEvery { observeConversationListDetailsUseCase.invoke(false) } returns flowOf( listOf( TestConversationDetails.CONNECTION, TestConversationDetails.CONVERSATION_ONE_ONE, @@ -174,6 +171,7 @@ class ConversationListViewModelTest { val searchQueryText = "" // When + dispatcher.scheduler.advanceUntilIdle() conversationListViewModel.searchConversation(TextFieldValue(searchQueryText)) dispatcher.scheduler.advanceUntilIdle() @@ -182,26 +180,49 @@ class ConversationListViewModelTest { 3, conversationListViewModel.conversationListState.conversationSearchResult[ConversationFolder.Predefined.Conversations]?.size, ) - assertEquals( searchQueryText, conversationListViewModel.conversationListState.searchQuery) + assertEquals(searchQueryText, conversationListViewModel.conversationListState.searchQuery) } @Test fun `given non-empty search query, when collecting, then update state with filtered conversations`() = runTest { // Given - val searchQueryText = "testQuery" + val searchQueryText = TestConversationDetails.CONVERSATION_ONE_ONE.conversation.name.orDefault("test") // When + dispatcher.scheduler.advanceUntilIdle() conversationListViewModel.searchConversation(TextFieldValue(searchQueryText)) dispatcher.scheduler.advanceUntilIdle() // Then assertEquals( - 3, + 1, conversationListViewModel.conversationListState.conversationSearchResult[ConversationFolder.Predefined.Conversations]?.size, ) assertEquals(searchQueryText, conversationListViewModel.conversationListState.searchQuery) } + @Test + fun `given empty search query, when collecting archived conversations, then update state with only archived conversations`() = runTest { + // Given + coEvery { observeConversationListDetailsUseCase.invoke(true) } returns flowOf( + listOf( + TestConversationDetails.CONVERSATION_ONE_ONE, + TestConversationDetails.GROUP + ) + ) + // When + dispatcher.scheduler.advanceUntilIdle() + conversationListViewModel.updateConversationsSource(fromArchived = true) + dispatcher.scheduler.advanceUntilIdle() + + // Then + assertEquals( + 2, + conversationListViewModel.conversationListState.conversationSearchResult[ConversationFolder.WithoutHeader]?.size, + ) + coVerify(exactly = 1) { observeConversationListDetailsUseCase.invoke(true) } + } + @Test fun `given a valid conversation muting state, when calling muteConversation, then should call with call the UseCase`() = runTest { coEvery { updateConversationMutedStatus(any(), any(), any()) } returns ConversationUpdateStatusResult.Success