Skip to content

Commit 9c577d3

Browse files
added tests for MessageActionsViewModel
1 parent f7a7127 commit 9c577d3

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
84C94D5E275A3AA9007FE2B9 /* ImageCDN_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D5D275A3AA9007FE2B9 /* ImageCDN_Tests.swift */; };
221221
84C94D60275A45D2007FE2B9 /* ViewFactory_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D5F275A45D2007FE2B9 /* ViewFactory_Tests.swift */; };
222222
84C94D62275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D61275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift */; };
223+
84C94D66275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */; };
223224
84EDBC37274FE5CD0057218D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84EDBC36274FE5CD0057218D /* Localizable.strings */; };
224225
/* End PBXBuildFile section */
225226

@@ -470,6 +471,7 @@
470471
84C94D5D275A3AA9007FE2B9 /* ImageCDN_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCDN_Tests.swift; sourceTree = "<group>"; };
471472
84C94D5F275A45D2007FE2B9 /* ViewFactory_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactory_Tests.swift; sourceTree = "<group>"; };
472473
84C94D61275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelNamer_Tests.swift; sourceTree = "<group>"; };
474+
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageActionsViewModel_Tests.swift; sourceTree = "<group>"; };
473475
84EDBC36274FE5CD0057218D /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
474476
/* End PBXFileReference section */
475477

@@ -979,6 +981,7 @@
979981
84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */,
980982
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
981983
84C94D57275A1B89007FE2B9 /* MessageTypeResolver_Tests.swift */,
984+
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */,
982985
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
983986
);
984987
path = ChatChannel;
@@ -1354,6 +1357,7 @@
13541357
84C94D1027578BF2007FE2B9 /* TestDataModel2.xcdatamodeld in Sources */,
13551358
84C94CE627578B92007FE2B9 /* CurrentChatUserController_Mock.swift in Sources */,
13561359
84C94D1527578BF3007FE2B9 /* TestDispatchQueue.swift in Sources */,
1360+
84C94D66275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift in Sources */,
13571361
84C94D0827578BF2007FE2B9 /* MockFunc.swift in Sources */,
13581362
84C94D1D2757929C007FE2B9 /* WebSocketClient_Mock.swift in Sources */,
13591363
84C94D3E27579BB0007FE2B9 /* StreamChatModel.xcdatamodeld in Sources */,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
import XCTest
10+
11+
class MessageActionsViewModel_Tests: XCTestCase {
12+
13+
private var chatClient: ChatClient = {
14+
let client = ChatClient.mock()
15+
client.currentUserId = .unique
16+
return client
17+
}()
18+
19+
private var streamChat: StreamChat?
20+
21+
override func setUp() {
22+
super.setUp()
23+
streamChat = StreamChat(chatClient: chatClient)
24+
}
25+
26+
func test_messageActionsViewModel_confirmationAlertShown() {
27+
// Given
28+
let actions = MessageAction.defaultActions(
29+
for: .mock(
30+
id: .unique,
31+
cid: .unique,
32+
text: "test",
33+
author: .mock(id: .unique)
34+
),
35+
chatClient: chatClient,
36+
onDismiss: {},
37+
onError: { _ in }
38+
)
39+
let viewModel = MessageActionsViewModel(messageActions: actions)
40+
let action = actions[0]
41+
42+
// When
43+
viewModel.alertAction = action
44+
45+
// Then
46+
XCTAssert(action.confirmationPopup != nil)
47+
XCTAssert(viewModel.alertShown == true)
48+
}
49+
50+
}

0 commit comments

Comments
 (0)