Skip to content

Commit ab0e511

Browse files
committed
Fix MessageContainerView_Tests
1 parent 4d56529 commit ab0e511

File tree

2 files changed

+8
-143
lines changed

2 files changed

+8
-143
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import StreamChat
77
import SwiftUI
88

99
public struct MessageContainerView<Factory: ViewFactory>: View {
10-
@EnvironmentObject private var channelViewModel: ChatChannelViewModel
11-
@EnvironmentObject private var messageViewModel: MessageViewModel
10+
@EnvironmentObject var channelViewModel: ChatChannelViewModel
11+
@EnvironmentObject var messageViewModel: MessageViewModel
1212
@Environment(\.channelTranslationLanguage) var translationLanguage
1313

1414
@Injected(\.fonts) private var fonts

StreamChatSwiftUITests/Tests/ChatChannel/MessageContainerView_Tests.swift

Lines changed: 6 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
205205
width: 2 * defaultScreenSize.width / 3,
206206
scrolledId: .constant(nil)
207207
)
208+
.environmentObject(MessageViewModel(message: message, channel: nil))
208209
.frame(width: 200)
209210
.padding()
210211

@@ -230,6 +231,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
230231
isFirst: true,
231232
scrolledId: .constant(nil)
232233
)
234+
.environmentObject(MessageViewModel(message: message, channel: nil))
233235
.frame(width: 200)
234236

235237
// Then
@@ -256,6 +258,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
256258
isFirst: true,
257259
scrolledId: .constant(nil)
258260
)
261+
.environmentObject(MessageViewModel(message: message, channel: nil))
259262
.frame(width: 200)
260263

261264
// Then
@@ -339,150 +342,11 @@ class MessageContainerView_Tests: StreamChatTestCase {
339342
AssertSnapshot(view, size: CGSize(width: 375, height: 200))
340343
}
341344

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-
482345
// MARK: - private
483346

484347
func testMessageViewContainer(message: ChatMessage) -> some View {
485-
MessageContainerView(
348+
let channel = ChatChannel.mockDMChannel()
349+
return MessageContainerView(
486350
factory: DefaultViewFactory.shared,
487351
channel: .mockDMChannel(),
488352
message: message,
@@ -494,6 +358,7 @@ class MessageContainerView_Tests: StreamChatTestCase {
494358
quotedMessage: .constant(nil),
495359
onLongPress: { _ in }
496360
)
361+
.environmentObject(MessageViewModel(message: message, channel: channel))
497362
.frame(width: 375, height: 200)
498363
}
499364
}

0 commit comments

Comments
 (0)