@@ -98,6 +98,40 @@ class MessageListView_Tests: StreamChatTestCase {
9898 assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
9999 }
100100
101+ // MARK: - Init with ChatChannelViewModel snapshot tests
102+
103+ func test_messageListView_viewModelInit_withReactions( ) {
104+ // Given
105+ let channel = ChatChannel . mockDMChannel ( config: . init( reactionsEnabled: true ) )
106+ let view = makeMessageListViewWithViewModel ( channel: channel, messages: [ . mock( id: . unique, cid: channel. cid, text: " Hello " , author: . mock( id: . unique) , reactionScores: [ MessageReactionType ( rawValue: " like " ) : 1 ] ) ] )
107+ . applyDefaultSize ( )
108+
109+ // Then
110+ assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
111+ }
112+
113+ func test_messageListView_viewModelInit_noReactions( ) {
114+ // Given
115+ let channel = ChatChannel . mockDMChannel ( config: . init( reactionsEnabled: false ) )
116+ let view = makeMessageListViewWithViewModel ( channel: channel, messages: [ . mock( id: . unique, cid: channel. cid, text: " Hello " , author: . mock( id: . unique) ) ] )
117+ . applyDefaultSize ( )
118+
119+ // Then
120+ assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
121+ }
122+
123+ func test_messageListView_viewModelInit_unreadIndicator( ) {
124+ // Given
125+ var channel = ChatChannel . mockDMChannel ( )
126+ // Set unread count on the channel
127+ channel = ChatChannel . mockDMChannel ( unreadCount: . mock( messages: 2 ) )
128+ let view = makeMessageListViewWithViewModel ( channel: channel, messages: [ . mock( id: . unique, cid: channel. cid, text: " Unread 1 " , author: . mock( id: . unique) ) ] )
129+ . applyDefaultSize ( )
130+
131+ // Then
132+ assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
133+ }
134+
101135 // MARK: - private
102136
103137 func makeMessageListView(
@@ -138,4 +172,26 @@ class MessageListView_Tests: StreamChatTestCase {
138172
139173 return messageListView
140174 }
175+
176+ private func makeMessageListViewWithViewModel(
177+ channel: ChatChannel ,
178+ messages: [ ChatMessage ]
179+ ) -> MessageListView < DefaultViewFactory > {
180+ // Create a mock channel controller seeded with channel and messages
181+ let controller = ChatChannelTestHelpers . makeChannelController (
182+ chatClient: chatClient,
183+ chatChannel: channel,
184+ messages: messages
185+ )
186+
187+ // Build the view model
188+ let viewModel = ChatChannelViewModel ( channelController: controller)
189+
190+ // Return the view using the new initializer
191+ return MessageListView (
192+ factory: DefaultViewFactory . shared,
193+ channel: channel,
194+ viewModel: viewModel
195+ )
196+ }
141197}
0 commit comments