Skip to content

Commit b459ee6

Browse files
Added tests
1 parent 87aeadb commit b459ee6

File tree

7 files changed

+109
-1
lines changed

7 files changed

+109
-1
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
84B288D1274CEDD000DD090B /* GroupNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288D0274CEDD000DD090B /* GroupNameView.swift */; };
176176
84B288D3274D23AF00DD090B /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288D2274D23AF00DD090B /* LoginView.swift */; };
177177
84B288D5274D286500DD090B /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288D4274D286500DD090B /* LoginViewModel.swift */; };
178+
84C2042327917B6A0024D616 /* MessageListView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C2042227917B6A0024D616 /* MessageListView_Tests.swift */; };
178179
84C94C8027567D3F007FE2B9 /* ChatChannelListViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94C7F27567D3F007FE2B9 /* ChatChannelListViewModel_Tests.swift */; };
179180
84C94CCC27578B92007FE2B9 /* ChatClientUpdater_Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94CAA27578B92007FE2B9 /* ChatClientUpdater_Mock.swift */; };
180181
84C94CCD27578B92007FE2B9 /* ChannelUnreadCount_Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94CAC27578B92007FE2B9 /* ChannelUnreadCount_Mock.swift */; };
@@ -481,6 +482,7 @@
481482
84B288D0274CEDD000DD090B /* GroupNameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupNameView.swift; sourceTree = "<group>"; };
482483
84B288D2274D23AF00DD090B /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
483484
84B288D4274D286500DD090B /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
485+
84C2042227917B6A0024D616 /* MessageListView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListView_Tests.swift; sourceTree = "<group>"; };
484486
84C94C7E27567D3F007FE2B9 /* StreamChatSwiftUITests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "StreamChatSwiftUITests-Bridging-Header.h"; sourceTree = "<group>"; };
485487
84C94C7F27567D3F007FE2B9 /* ChatChannelListViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelListViewModel_Tests.swift; sourceTree = "<group>"; };
486488
84C94CAA27578B92007FE2B9 /* ChatClientUpdater_Mock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatClientUpdater_Mock.swift; sourceTree = "<group>"; };
@@ -1153,6 +1155,7 @@
11531155
children = (
11541156
8423C340277CB5C70092DCF1 /* Suggestions */,
11551157
84C94D482758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift */,
1158+
84C2042227917B6A0024D616 /* MessageListView_Tests.swift */,
11561159
84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */,
11571160
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
11581161
84C94D57275A1B89007FE2B9 /* MessageTypeResolver_Tests.swift */,
@@ -1603,6 +1606,7 @@
16031606
84C94D1027578BF2007FE2B9 /* TestDataModel2.xcdatamodeld in Sources */,
16041607
84C94CE627578B92007FE2B9 /* CurrentChatUserController_Mock.swift in Sources */,
16051608
84C94D1527578BF3007FE2B9 /* TestDispatchQueue.swift in Sources */,
1609+
84C2042327917B6A0024D616 /* MessageListView_Tests.swift in Sources */,
16061610
84C94D66275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift in Sources */,
16071611
84C94D0827578BF2007FE2B9 /* MockFunc.swift in Sources */,
16081612
84C94D1D2757929C007FE2B9 /* WebSocketClient_Mock.swift in Sources */,

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelTestHelpers.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class ChatChannelTestHelpers {
1313
messages: [ChatMessage] = [],
1414
lastActiveWatchers: [ChatUser] = []
1515
) -> ChatChannelController_Mock {
16-
let channel = ChatChannel.mockDMChannel(lastActiveWatchers: lastActiveWatchers)
16+
let config = ChannelConfig(commands: [Command(name: "giphy", description: "", set: "", args: "")])
17+
let channel = ChatChannel.mockDMChannel(config: config, lastActiveWatchers: lastActiveWatchers)
1718
let channelQuery = ChannelQuery(cid: channel.cid)
1819
let channelListQuery = ChannelListQuery(filter: .containMembers(userIds: [chatClient.currentUserId!]))
1920
let channelController = ChatChannelController_Mock(
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// Copyright © 2022 Stream.io Inc. All rights reserved.
3+
//
4+
5+
@testable import SnapshotTesting
6+
@testable import StreamChat
7+
@testable import StreamChatSwiftUI
8+
import XCTest
9+
10+
class MessageListView_Tests: XCTestCase {
11+
12+
private var chatClient: ChatClient = {
13+
let client = ChatClient.mock()
14+
client.currentUserId = .unique
15+
return client
16+
}()
17+
18+
private var streamChat: StreamChat?
19+
20+
override func setUp() {
21+
super.setUp()
22+
streamChat = StreamChat(chatClient: chatClient)
23+
}
24+
25+
func test_messageListView_withReactions() {
26+
// Given
27+
let channelConfig = ChannelConfig(reactionsEnabled: true)
28+
let messageListView = makeMessageListView(channelConfig: channelConfig)
29+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
30+
31+
// Then
32+
assertSnapshot(matching: messageListView, as: .image)
33+
}
34+
35+
func test_messageListView_noReactions() {
36+
// Given
37+
let channelConfig = ChannelConfig(reactionsEnabled: false)
38+
let messageListView = makeMessageListView(channelConfig: channelConfig)
39+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
40+
41+
// Then
42+
assertSnapshot(matching: messageListView, as: .image)
43+
}
44+
45+
// MARK: - private
46+
47+
private func makeMessageListView(channelConfig: ChannelConfig) -> MessageListView<DefaultViewFactory> {
48+
let reactions = [MessageReactionType(rawValue: "like"): 2]
49+
let channel = ChatChannel.mockDMChannel(config: channelConfig)
50+
let temp = [ChatMessage.mock(
51+
id: .unique,
52+
cid: channel.cid,
53+
text: "Test",
54+
author: .mock(id: .unique),
55+
reactionScores: reactions
56+
)]
57+
let messages = LazyCachedMapCollection(source: temp, map: { $0 })
58+
let messageListView = MessageListView(
59+
factory: DefaultViewFactory.shared,
60+
channel: channel,
61+
messages: messages,
62+
messagesGroupingInfo: [:],
63+
scrolledId: .constant(nil),
64+
showScrollToLatestButton: .constant(false),
65+
quotedMessage: .constant(nil),
66+
currentDateString: nil,
67+
isGroup: false,
68+
unreadCount: 0,
69+
listId: "listId",
70+
isMessageThread: false,
71+
onMessageAppear: { _ in },
72+
onScrollToBottom: {},
73+
onLongPress: { _ in }
74+
)
75+
76+
return messageListView
77+
}
78+
}

StreamChatSwiftUITests/Tests/ChatChannel/ReactionsOverlayView_Tests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@ class ReactionsOverlayView_Tests: XCTestCase {
5252
// Then
5353
assertSnapshot(matching: view, as: .image)
5454
}
55+
56+
func test_reactionsOverlayView_noReactions() {
57+
// Given
58+
let config = ChannelConfig(reactionsEnabled: false)
59+
let channel = ChatChannel.mockDMChannel(config: config)
60+
let view = VerticallyCenteredView {
61+
ReactionsOverlayView(
62+
factory: DefaultViewFactory.shared,
63+
channel: channel,
64+
currentSnapshot: UIImage(systemName: "checkmark")!,
65+
messageDisplayInfo: MessageDisplayInfo(
66+
message: .mock(id: .unique, cid: .unique, text: "test", author: .mock(id: .unique)),
67+
frame: CGRect(x: 20, y: 20, width: 200, height: 100),
68+
contentWidth: 200,
69+
isFirst: true
70+
),
71+
onBackgroundTap: {},
72+
onActionExecuted: { _ in }
73+
)
74+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
75+
}
76+
77+
// Then
78+
assertSnapshot(matching: view, as: .image)
79+
}
5580
}
5681

5782
struct VerticallyCenteredView<Content: View>: View {
Loading
Loading
Loading

0 commit comments

Comments
 (0)