@@ -167,4 +167,76 @@ class ChatChannelView_Tests: StreamChatTestCase {
167167 // Then
168168 assertSnapshot ( matching: view, as: . image( perceptualPrecision: precision) )
169169 }
170+
171+ // MARK: - Reactions Overlay Tests
172+
173+ func test_chatChannelView_doesNotCrash_whenCurrentSnapshotIsNil_andReactionsShownIsTrue( ) {
174+ // Given
175+ let controller = ChatChannelController_Mock . mock (
176+ channelQuery: . init( cid: . unique) ,
177+ channelListQuery: nil ,
178+ client: chatClient
179+ )
180+ let mockChannel = ChatChannel . mock ( cid: . unique, name: " Test channel " )
181+ let message = ChatMessage . mock (
182+ id: . unique,
183+ cid: mockChannel. cid,
184+ text: " Test message " ,
185+ author: . mock( id: . unique, name: " User " )
186+ )
187+ controller. simulateInitial ( channel: mockChannel, messages: [ message] , state: . remoteDataFetched)
188+
189+ let viewModel = ChatChannelViewModel ( channelController: controller)
190+
191+ // When
192+ viewModel. currentSnapshot = nil
193+ viewModel. reactionsShown = true
194+
195+ let view = ChatChannelView (
196+ viewFactory: DefaultViewFactory . shared,
197+ viewModel: viewModel,
198+ channelController: controller
199+ )
200+
201+ // Then - Should not crash when rendering
202+ let hostingController = UIHostingController ( rootView: view)
203+ XCTAssertNotNil ( hostingController. view)
204+ XCTAssertNil ( viewModel. currentSnapshot)
205+ XCTAssertTrue ( viewModel. reactionsShown)
206+ }
207+
208+ func test_chatChannelView_doesNotCrash_whenMessageDisplayInfoIsNil_andReactionsShownIsTrue( ) {
209+ // Given
210+ let controller = ChatChannelController_Mock . mock (
211+ channelQuery: . init( cid: . unique) ,
212+ channelListQuery: nil ,
213+ client: chatClient
214+ )
215+ let mockChannel = ChatChannel . mock ( cid: . unique, name: " Test channel " )
216+ let message = ChatMessage . mock (
217+ id: . unique,
218+ cid: mockChannel. cid,
219+ text: " Test message " ,
220+ author: . mock( id: . unique, name: " User " )
221+ )
222+ controller. simulateInitial ( channel: mockChannel, messages: [ message] , state: . remoteDataFetched)
223+
224+ let viewModel = ChatChannelViewModel ( channelController: controller)
225+
226+ // When
227+ viewModel. showReactionOverlay ( for: AnyView ( EmptyView ( ) ) )
228+ // messageDisplayInfo remains nil (not set)
229+
230+ let view = ChatChannelView (
231+ viewFactory: DefaultViewFactory . shared,
232+ viewModel: viewModel,
233+ channelController: controller
234+ )
235+
236+ // Then - Should not crash when rendering
237+ let hostingController = UIHostingController ( rootView: view)
238+ XCTAssertNotNil ( hostingController. view)
239+ XCTAssertNotNil ( viewModel. currentSnapshot)
240+ XCTAssertTrue ( viewModel. reactionsShown)
241+ }
170242}
0 commit comments