@@ -205,6 +205,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
205
205
width: 2 * defaultScreenSize. width / 3 ,
206
206
scrolledId: . constant( nil )
207
207
)
208
+ . environmentObject ( MessageViewModel ( message: message, channel: nil ) )
208
209
. frame ( width: 200 )
209
210
. padding ( )
210
211
@@ -230,6 +231,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
230
231
isFirst: true ,
231
232
scrolledId: . constant( nil )
232
233
)
234
+ . environmentObject ( MessageViewModel ( message: message, channel: nil ) )
233
235
. frame ( width: 200 )
234
236
235
237
// Then
@@ -256,6 +258,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
256
258
isFirst: true ,
257
259
scrolledId: . constant( nil )
258
260
)
261
+ . environmentObject ( MessageViewModel ( message: message, channel: nil ) )
259
262
. frame ( width: 200 )
260
263
261
264
// Then
@@ -339,150 +342,11 @@ class MessageContainerView_Tests: StreamChatTestCase {
339
342
AssertSnapshot ( view, size: CGSize ( width: 375 , height: 200 ) )
340
343
}
341
344
342
- func test_handleGestureForMessage_whenMessageIsInteractable_shouldLongPress( ) {
343
- // Given
344
- let message = ChatMessage . mock (
345
- id: . unique,
346
- cid: . unique,
347
- text: " Hello " ,
348
- localState: nil ,
349
- isSentByCurrentUser: true
350
- )
351
-
352
- let exp = expectation ( description: " Long press triggered " )
353
- let view = MessageContainerView (
354
- factory: DefaultViewFactory . shared,
355
- channel: . mockDMChannel( ) ,
356
- message: message,
357
- width: defaultScreenSize. width,
358
- showsAllInfo: true ,
359
- isInThread: false ,
360
- isLast: false ,
361
- scrolledId: . constant( nil ) ,
362
- quotedMessage: . constant( nil )
363
- ) { _ in
364
- exp. fulfill ( )
365
- }
366
-
367
- view. handleGestureForMessage ( showsMessageActions: false , showsBottomContainer: false )
368
-
369
- waitForExpectations ( timeout: defaultTimeout) { error in
370
- XCTAssertNil ( error, " Long press was not triggered " )
371
- }
372
- }
373
-
374
- func test_handleGestureForMessage_whenMessageNotInteractable_shouldNotLongPress( ) {
375
- // Given
376
- let message = ChatMessage . mock (
377
- id: . unique,
378
- cid: . unique,
379
- text: " Hello " ,
380
- type: . ephemeral,
381
- localState: nil ,
382
- isSentByCurrentUser: true
383
- )
384
-
385
- let exp = expectation ( description: " Long press should not be triggered " )
386
- exp. isInverted = true
387
- let view = MessageContainerView (
388
- factory: DefaultViewFactory . shared,
389
- channel: . mockDMChannel( ) ,
390
- message: message,
391
- width: defaultScreenSize. width,
392
- showsAllInfo: true ,
393
- isInThread: false ,
394
- isLast: false ,
395
- scrolledId: . constant( nil ) ,
396
- quotedMessage: . constant( nil )
397
- ) { _ in
398
- exp. fulfill ( )
399
- }
400
-
401
- view. handleGestureForMessage ( showsMessageActions: false , showsBottomContainer: false )
402
-
403
- waitForExpectations ( timeout: 1 )
404
- }
405
-
406
- func test_isSwipeToReplyPossible_whenRepliesEnabled_whenMessageInteractable_shouldBeTrue( ) {
407
- let message = ChatMessage . mock (
408
- id: . unique,
409
- cid: . unique,
410
- text: " Hello " ,
411
- localState: nil ,
412
- isSentByCurrentUser: true
413
- )
414
-
415
- let view = MessageContainerView (
416
- factory: DefaultViewFactory . shared,
417
- channel: . mockDMChannel( config: . mock( repliesEnabled: true ) ) ,
418
- message: message,
419
- width: defaultScreenSize. width,
420
- showsAllInfo: true ,
421
- isInThread: false ,
422
- isLast: false ,
423
- scrolledId: . constant( nil ) ,
424
- quotedMessage: . constant( nil ) ,
425
- onLongPress: { _ in }
426
- )
427
-
428
- XCTAssertTrue ( view. isSwipeToReplyPossible)
429
- }
430
-
431
- func test_isSwipeToReplyPossible_whenRepliesDisabled_whenMessageInteractable_shouldBeFalse( ) {
432
- let message = ChatMessage . mock (
433
- id: . unique,
434
- cid: . unique,
435
- text: " Hello " ,
436
- localState: nil ,
437
- isSentByCurrentUser: true
438
- )
439
-
440
- let view = MessageContainerView (
441
- factory: DefaultViewFactory . shared,
442
- channel: . mockDMChannel( config: . mock( repliesEnabled: false ) ) ,
443
- message: message,
444
- width: defaultScreenSize. width,
445
- showsAllInfo: true ,
446
- isInThread: false ,
447
- isLast: false ,
448
- scrolledId: . constant( nil ) ,
449
- quotedMessage: . constant( nil ) ,
450
- onLongPress: { _ in }
451
- )
452
-
453
- XCTAssertFalse ( view. isSwipeToReplyPossible)
454
- }
455
-
456
- func test_isSwipeToReplyPossible_whenRepliesEnabled_whenMessageNotInteractable_shouldBeFalse( ) {
457
- let message = ChatMessage . mock (
458
- id: . unique,
459
- cid: . unique,
460
- text: " Hello " ,
461
- type: . ephemeral,
462
- localState: nil ,
463
- isSentByCurrentUser: true
464
- )
465
-
466
- let view = MessageContainerView (
467
- factory: DefaultViewFactory . shared,
468
- channel: . mockDMChannel( config: . mock( repliesEnabled: true ) ) ,
469
- message: message,
470
- width: defaultScreenSize. width,
471
- showsAllInfo: true ,
472
- isInThread: false ,
473
- isLast: false ,
474
- scrolledId: . constant( nil ) ,
475
- quotedMessage: . constant( nil ) ,
476
- onLongPress: { _ in }
477
- )
478
-
479
- XCTAssertFalse ( view. isSwipeToReplyPossible)
480
- }
481
-
482
345
// MARK: - private
483
346
484
347
func testMessageViewContainer( message: ChatMessage ) -> some View {
485
- MessageContainerView (
348
+ let channel = ChatChannel . mockDMChannel ( )
349
+ return MessageContainerView (
486
350
factory: DefaultViewFactory . shared,
487
351
channel: . mockDMChannel( ) ,
488
352
message: message,
@@ -494,6 +358,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
494
358
quotedMessage: . constant( nil ) ,
495
359
onLongPress: { _ in }
496
360
)
361
+ . environmentObject ( MessageViewModel ( message: message, channel: channel) )
497
362
. frame ( width: 375 , height: 200 )
498
363
}
499
364
}
0 commit comments