Skip to content

Commit 396ca68

Browse files
added tests for MessageComposerViewModel
1 parent 6f6c680 commit 396ca68

File tree

7 files changed

+494
-23
lines changed

7 files changed

+494
-23
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
84C94D442757C704007FE2B9 /* MoreChannelActionsViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D432757C704007FE2B9 /* MoreChannelActionsViewModel_Tests.swift */; };
210210
84C94D462757D1CA007FE2B9 /* ImageLoader_Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D452757D1CA007FE2B9 /* ImageLoader_Mock.swift */; };
211211
84C94D492758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D482758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift */; };
212+
84C94D4D2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */; };
213+
84C94D4F2758FE59007FE2B9 /* ChatChannelTestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */; };
212214
84EDBC37274FE5CD0057218D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84EDBC36274FE5CD0057218D /* Localizable.strings */; };
213215
/* End PBXBuildFile section */
214216

@@ -448,6 +450,8 @@
448450
84C94D432757C704007FE2B9 /* MoreChannelActionsViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreChannelActionsViewModel_Tests.swift; sourceTree = "<group>"; };
449451
84C94D452757D1CA007FE2B9 /* ImageLoader_Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLoader_Mock.swift; sourceTree = "<group>"; };
450452
84C94D482758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelViewModel_Tests.swift; sourceTree = "<group>"; };
453+
84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerViewModel_Tests.swift; sourceTree = "<group>"; };
454+
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelTestHelpers.swift; sourceTree = "<group>"; };
451455
84EDBC36274FE5CD0057218D /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
452456
/* End PBXFileReference section */
453457

@@ -952,6 +956,8 @@
952956
isa = PBXGroup;
953957
children = (
954958
84C94D482758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift */,
959+
84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */,
960+
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
955961
);
956962
path = ChatChannel;
957963
sourceTree = "<group>";
@@ -1250,6 +1256,7 @@
12501256
84C94CE127578B92007FE2B9 /* MessageAttachmentPayload.swift in Sources */,
12511257
84C94CE527578B92007FE2B9 /* ChatUserSearchController_Mock.swift in Sources */,
12521258
84C94D1427578BF3007FE2B9 /* TemporaryData.swift in Sources */,
1259+
84C94D4F2758FE59007FE2B9 /* ChatChannelTestHelpers.swift in Sources */,
12531260
84C94CCC27578B92007FE2B9 /* ChatClientUpdater_Mock.swift in Sources */,
12541261
84C94D0B27578BF2007FE2B9 /* QueueAwareDelegate.swift in Sources */,
12551262
84C94CE427578B92007FE2B9 /* ChatChannelController_Mock.swift in Sources */,
@@ -1261,6 +1268,7 @@
12611268
84C94D0927578BF2007FE2B9 /* TestManagedObject.swift in Sources */,
12621269
84C94D3A27579BB0007FE2B9 /* AssertJSONEqual.swift in Sources */,
12631270
84C94D3927579BB0007FE2B9 /* TestDataModel.xcdatamodeld in Sources */,
1271+
84C94D4D2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift in Sources */,
12641272
84C94CDB27578B92007FE2B9 /* NSManagedObject+ContextChange.swift in Sources */,
12651273
84C94D0C27578BF2007FE2B9 /* AssertJSONEqual.swift in Sources */,
12661274
84C94D492758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift in Sources */,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1310"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "8465FBB42746873A00AF091E"
18+
BuildableName = "StreamChatSwiftUI.framework"
19+
BlueprintName = "StreamChatSwiftUI"
20+
ReferencedContainer = "container:StreamChatSwiftUI.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
31+
<Testables>
32+
<TestableReference
33+
skipped = "NO">
34+
<BuildableReference
35+
BuildableIdentifier = "primary"
36+
BlueprintIdentifier = "8465FBBC2746873A00AF091E"
37+
BuildableName = "StreamChatSwiftUITests.xctest"
38+
BlueprintName = "StreamChatSwiftUITests"
39+
ReferencedContainer = "container:StreamChatSwiftUI.xcodeproj">
40+
</BuildableReference>
41+
</TestableReference>
42+
</Testables>
43+
</TestAction>
44+
<LaunchAction
45+
buildConfiguration = "Debug"
46+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48+
launchStyle = "0"
49+
useCustomWorkingDirectory = "NO"
50+
ignoresPersistentStateOnLaunch = "NO"
51+
debugDocumentVersioning = "YES"
52+
debugServiceExtension = "internal"
53+
allowLocationSimulation = "YES">
54+
</LaunchAction>
55+
<ProfileAction
56+
buildConfiguration = "Release"
57+
shouldUseLaunchSchemeArgsEnv = "YES"
58+
savedToolIdentifier = ""
59+
useCustomWorkingDirectory = "NO"
60+
debugDocumentVersioning = "YES">
61+
<MacroExpansion>
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "8465FBB42746873A00AF091E"
65+
BuildableName = "StreamChatSwiftUI.framework"
66+
BlueprintName = "StreamChatSwiftUI"
67+
ReferencedContainer = "container:StreamChatSwiftUI.xcodeproj">
68+
</BuildableReference>
69+
</MacroExpansion>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

StreamChatSwiftUI.xcodeproj/xcuserdata/martinmitrevski.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@
2828
<key>isShown</key>
2929
<false/>
3030
<key>orderHint</key>
31-
<integer>2</integer>
31+
<integer>1</integer>
3232
</dict>
3333
<key>StreamChatSwiftUI.xcscheme_^#shared#^_</key>
3434
<dict>
3535
<key>orderHint</key>
36-
<integer>1</integer>
36+
<integer>2</integer>
3737
</dict>
3838
</dict>
3939
<key>SuppressBuildableAutocreation</key>
4040
<dict>
41+
<key>8465FBB42746873A00AF091E</key>
42+
<dict>
43+
<key>primary</key>
44+
<true/>
45+
</dict>
46+
<key>8465FBBC2746873A00AF091E</key>
47+
<dict>
48+
<key>primary</key>
49+
<true/>
50+
</dict>
4151
<key>8465FCBB27468B6900AF091E</key>
4252
<dict>
4353
<key>primary</key>

StreamChatSwiftUITests/Infrastructure/Shared/CustomAssertions/AssertAsync.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ struct AssertAsync {
336336
}
337337
}
338338

339-
@_functionBuilder
339+
@resultBuilder
340340
enum AssertionBuilder {
341341
static func buildBlock(_ assertion: Assertion) -> Assertion {
342342
assertion
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import XCTest
6+
@testable import StreamChatSwiftUI
7+
@testable import StreamChat
8+
9+
class ChatChannelTestHelpers {
10+
11+
static func makeChannelController(
12+
chatClient: ChatClient,
13+
messages: [ChatMessage] = []
14+
) -> ChatChannelController_Mock {
15+
let channel = ChatChannel.mockDMChannel()
16+
let channelQuery = ChannelQuery(cid: channel.cid)
17+
let channelListQuery = ChannelListQuery(filter: .containMembers(userIds: [chatClient.currentUserId!]))
18+
let channelController = ChatChannelController_Mock(
19+
channelQuery: channelQuery,
20+
channelListQuery: channelListQuery,
21+
client: chatClient
22+
)
23+
var channelMessages = messages
24+
if channelMessages.isEmpty {
25+
let message = ChatMessage.mock(
26+
id: .unique,
27+
cid: channel.cid,
28+
text: "Test message",
29+
author: ChatUser.mock(id: chatClient.currentUserId!)
30+
)
31+
channelMessages = [message]
32+
}
33+
34+
channelController.simulateInitial(channel: channel, messages: channelMessages, state: .initialized)
35+
return channelController
36+
}
37+
38+
}

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewModel_Tests.swift

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,10 @@ class ChatChannelViewModel_Tests: XCTestCase {
165165
private func makeChannelController(
166166
messages: [ChatMessage] = []
167167
) -> ChatChannelController_Mock {
168-
let channel = ChatChannel.mockDMChannel()
169-
let channelQuery = ChannelQuery(cid: channel.cid)
170-
let channelListQuery = ChannelListQuery(filter: .containMembers(userIds: [chatClient.currentUserId!]))
171-
let channelController = ChatChannelController_Mock(
172-
channelQuery: channelQuery,
173-
channelListQuery: channelListQuery,
174-
client: chatClient
168+
return ChatChannelTestHelpers.makeChannelController(
169+
chatClient: chatClient,
170+
messages: messages
175171
)
176-
var channelMessages = messages
177-
if channelMessages.isEmpty {
178-
let message = ChatMessage.mock(
179-
id: .unique,
180-
cid: channel.cid,
181-
text: "Test message",
182-
author: ChatUser.mock(id: chatClient.currentUserId!)
183-
)
184-
channelMessages = [message]
185-
}
186-
187-
channelController.simulateInitial(channel: channel, messages: channelMessages, state: .initialized)
188-
return channelController
189172
}
190173

191174
}

0 commit comments

Comments
 (0)