Skip to content

Commit 80769a2

Browse files
committed
Test: cover scroll-to-first-unread VM action and wired pill snapshot
Two coverage additions for the new unread-pill surface: - MessageListViewModelTest gains a case for disableUnreadLabelButton on a fixture with no active unread label, asserting state stays untouched. This exercises the VM's delegating method and the controller's early-return guard end-to-end. - MessageListTest gains a snapshot variant rendering MessageList with an active UnreadLabel and an inline UnreadSeparatorItemState. The snapshot exercises the wired pill through the public state-only MessageList, Messages.DefaultMessagesHelperContent, and the ChatComponentFactory.ScrollToFirstUnreadButton slot in inspection mode.
1 parent c5966ad commit 80769a2

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/ui/messages/MessageListTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ import io.getstream.chat.android.models.ChannelCapabilities
3232
import io.getstream.chat.android.previewdata.PreviewChannelUserRead
3333
import io.getstream.chat.android.previewdata.PreviewMessageData
3434
import io.getstream.chat.android.previewdata.PreviewUserData
35+
import io.getstream.chat.android.ui.common.feature.messages.list.MessageListController
3536
import io.getstream.chat.android.ui.common.state.messages.list.DateSeparatorItemState
3637
import io.getstream.chat.android.ui.common.state.messages.list.MessageItemState
3738
import io.getstream.chat.android.ui.common.state.messages.list.MessageListState
3839
import io.getstream.chat.android.ui.common.state.messages.list.MessagePosition
3940
import io.getstream.chat.android.ui.common.state.messages.list.SystemMessageItemState
41+
import io.getstream.chat.android.ui.common.state.messages.list.UnreadSeparatorItemState
4042
import org.junit.Rule
4143
import org.junit.Test
4244
import java.util.Calendar
@@ -150,6 +152,13 @@ internal class MessageListTest : PaparazziComposeTest {
150152
)
151153
}
152154
}
155+
156+
@Test
157+
fun `scroll to first unread pill`() {
158+
snapshotWithDarkMode {
159+
MessageList(messageListState = UnreadLabelMessageListState)
160+
}
161+
}
153162
}
154163

155164
private val Date1 = Calendar.getInstance().apply { set(2022, 1, 1, 1, 1) }.time
@@ -250,6 +259,15 @@ private val TwoMessagesListState = MessageListState(
250259
),
251260
)
252261

262+
private val UnreadLabelMessageListState = LoadedMessageListState.copy(
263+
messageItems = listOf(UnreadSeparatorItemState(unreadCount = 9)) + LoadedMessageListState.messageItems,
264+
unreadLabel = MessageListController.UnreadLabel(
265+
unreadCount = 9,
266+
lastReadMessageId = PreviewMessageData.message1.id,
267+
buttonVisibility = true,
268+
),
269+
)
270+
253271
@Composable
254272
private fun MessageList(
255273
messagesLazyListState: MessagesLazyListState = rememberMessagesLazyListState(),

stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/viewmodel/messages/MessageListViewModelTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ internal class MessageListViewModelTest {
147147
verify(audioPlayer).pause()
148148
}
149149

150+
@Test
151+
fun `When disableUnreadLabelButton is called without active unread label, state stays empty`() = runTest {
152+
val viewModel = Fixture()
153+
.givenCurrentUser()
154+
.givenChannelQuery()
155+
.givenChannelState()
156+
.get()
157+
158+
// No lastReadMessageId is configured by the fixture, so the calculator never produces an
159+
// unread label. Calling disableUnreadLabelButton must early-return on the controller side
160+
// and leave the unread state untouched.
161+
viewModel.disableUnreadLabelButton()
162+
163+
viewModel.currentMessagesState.value.unreadLabel `should be equal to` null
164+
}
165+
150166
private class Fixture(
151167
private val chatClient: ChatClient = mock(),
152168
private val channelId: String = CID,
Loading

0 commit comments

Comments
 (0)