|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Stream License; |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.getstream.chat.android.compose.ui.chats |
| 18 | + |
| 19 | +import androidx.annotation.UiThread |
| 20 | +import androidx.compose.ui.semantics.ProgressBarRangeInfo |
| 21 | +import androidx.compose.ui.test.hasProgressBarRangeInfo |
| 22 | +import androidx.compose.ui.test.junit4.createComposeRule |
| 23 | +import androidx.compose.ui.test.onNodeWithText |
| 24 | +import io.getstream.chat.android.compose.ui.ComposeTest |
| 25 | +import io.getstream.chat.android.compose.ui.channels.SearchMode |
| 26 | +import io.getstream.chat.android.compose.ui.theme.ChatTheme |
| 27 | +import io.getstream.chat.android.models.ConnectionState |
| 28 | +import io.getstream.chat.android.models.InitializationState |
| 29 | +import io.getstream.chat.android.models.SearchMessagesResult |
| 30 | +import io.getstream.chat.android.randomUser |
| 31 | +import io.getstream.chat.android.test.TestCall |
| 32 | +import io.getstream.result.Result |
| 33 | +import kotlinx.coroutines.flow.MutableStateFlow |
| 34 | +import org.junit.Before |
| 35 | +import org.junit.Rule |
| 36 | +import org.junit.Test |
| 37 | +import org.junit.runner.RunWith |
| 38 | +import org.mockito.kotlin.any |
| 39 | +import org.mockito.kotlin.doReturn |
| 40 | +import org.mockito.kotlin.whenever |
| 41 | +import org.robolectric.RobolectricTestRunner |
| 42 | +import org.robolectric.annotation.Config |
| 43 | + |
| 44 | +@RunWith(RobolectricTestRunner::class) |
| 45 | +@Config(sdk = [33]) |
| 46 | +internal class ChatsScreenTest : ComposeTest { |
| 47 | + |
| 48 | + @get:Rule |
| 49 | + val composeTestRule = createComposeRule() |
| 50 | + |
| 51 | + @Before |
| 52 | + fun prepare() { |
| 53 | + val user = randomUser() |
| 54 | + whenever(mockChatClient.getCurrentUser()) doReturn user |
| 55 | + whenever(mockClientState.user) doReturn MutableStateFlow(user) |
| 56 | + whenever(mockClientState.connectionState) doReturn MutableStateFlow(ConnectionState.Connected) |
| 57 | + whenever(mockClientState.initializationState) doReturn MutableStateFlow(InitializationState.NOT_INITIALIZED) |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + @UiThread |
| 62 | + fun `with search mode none`() { |
| 63 | + composeTestRule.setContent { |
| 64 | + ChatTheme { |
| 65 | + ChatsScreen() |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + composeTestRule.onNodeWithText("Stream Chat").assertExists() |
| 70 | + composeTestRule.onNode(hasProgressBarRangeInfo(ProgressBarRangeInfo.Indeterminate)) |
| 71 | + .assertExists() |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @UiThread |
| 76 | + fun `with search mode messages`() { |
| 77 | + composeTestRule.setContent { |
| 78 | + ChatTheme { |
| 79 | + ChatsScreen(searchMode = SearchMode.Messages) |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + composeTestRule.onNodeWithText("Search").assertExists() |
| 84 | + composeTestRule.onNode(hasProgressBarRangeInfo(ProgressBarRangeInfo.Indeterminate)) |
| 85 | + .assertExists() |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + @UiThread |
| 90 | + fun `with list content mode mentions`() { |
| 91 | + whenever( |
| 92 | + mockChatClient.searchMessages( |
| 93 | + channelFilter = any(), |
| 94 | + messageFilter = any(), |
| 95 | + offset = any(), |
| 96 | + limit = any(), |
| 97 | + next = any(), |
| 98 | + sort = any(), |
| 99 | + ), |
| 100 | + ) doReturn TestCall(Result.Success(SearchMessagesResult(messages = emptyList(), next = null))) |
| 101 | + |
| 102 | + composeTestRule.setContent { |
| 103 | + ChatTheme { |
| 104 | + ChatsScreen(listContentMode = ChatListContentMode.Mentions) |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + composeTestRule.onNode(hasProgressBarRangeInfo(ProgressBarRangeInfo.Indeterminate)) |
| 109 | + .assertExists() |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + @UiThread |
| 114 | + fun `with list content mode threads`() { |
| 115 | + composeTestRule.setContent { |
| 116 | + ChatTheme { |
| 117 | + ChatsScreen(listContentMode = ChatListContentMode.Threads) |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + composeTestRule.onNode(hasProgressBarRangeInfo(ProgressBarRangeInfo.Indeterminate)) |
| 122 | + .assertExists() |
| 123 | + } |
| 124 | +} |
0 commit comments