Skip to content

Commit 6ff423b

Browse files
added tests for mute commands
1 parent 81cdf3e commit 6ff423b

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
8423C344277CC5020092DCF1 /* CommandsHandler_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C343277CC5020092DCF1 /* CommandsHandler_Tests.swift */; };
2424
8423C346277D9BFF0092DCF1 /* TestCommandsConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C345277D9BFF0092DCF1 /* TestCommandsConfig.swift */; };
2525
8423C348277DBBDA0092DCF1 /* InstantCommandsHandler_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C347277DBBDA0092DCF1 /* InstantCommandsHandler_Tests.swift */; };
26+
8423C34C277DDD250092DCF1 /* MuteCommandHandler_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C34B277DDD250092DCF1 /* MuteCommandHandler_Tests.swift */; };
2627
842F0BB8276B3518002C400C /* QuotedMessageView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */; };
2728
84335014274BAB15007A1B81 /* ViewFactoryExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */; };
2829
84335016274BABF3007A1B81 /* NewChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335015274BABF3007A1B81 /* NewChatView.swift */; };
@@ -321,6 +322,7 @@
321322
8423C343277CC5020092DCF1 /* CommandsHandler_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandsHandler_Tests.swift; sourceTree = "<group>"; };
322323
8423C345277D9BFF0092DCF1 /* TestCommandsConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCommandsConfig.swift; sourceTree = "<group>"; };
323324
8423C347277DBBDA0092DCF1 /* InstantCommandsHandler_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstantCommandsHandler_Tests.swift; sourceTree = "<group>"; };
325+
8423C34B277DDD250092DCF1 /* MuteCommandHandler_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuteCommandHandler_Tests.swift; sourceTree = "<group>"; };
324326
842E979C275E0AD000A52E7B /* StreamChatSwiftUI.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = StreamChatSwiftUI.xctestplan; sourceTree = "<group>"; };
325327
842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedMessageView_Tests.swift; sourceTree = "<group>"; };
326328
84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactoryExamples.swift; sourceTree = "<group>"; };
@@ -622,6 +624,7 @@
622624
8423C341277CBA280092DCF1 /* TypingSuggester_Tests.swift */,
623625
8423C343277CC5020092DCF1 /* CommandsHandler_Tests.swift */,
624626
8423C347277DBBDA0092DCF1 /* InstantCommandsHandler_Tests.swift */,
627+
8423C34B277DDD250092DCF1 /* MuteCommandHandler_Tests.swift */,
625628
8423C345277D9BFF0092DCF1 /* TestCommandsConfig.swift */,
626629
);
627630
path = Suggestions;
@@ -1543,6 +1546,7 @@
15431546
84C94D2227579359007FE2B9 /* AnyEndpoint.swift in Sources */,
15441547
84C94D5C275A2E9F007FE2B9 /* StreamChatUtilsMocks.swift in Sources */,
15451548
84C94D1227578BF2007FE2B9 /* JSONEncoder+Extensions.swift in Sources */,
1549+
8423C34C277DDD250092DCF1 /* MuteCommandHandler_Tests.swift in Sources */,
15461550
84C94D24275794D3007FE2B9 /* InternetConnectionMock.swift in Sources */,
15471551
84C94CDD27578B92007FE2B9 /* MemberPayload.swift in Sources */,
15481552
84C94D1127578BF2007FE2B9 /* ChannelId.swift in Sources */,
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
3+
//
4+
5+
@testable import StreamChat
6+
@testable import StreamChatSwiftUI
7+
import XCTest
8+
9+
class MuteCommandHandler_Tests: XCTestCase {
10+
11+
private var chatClient: ChatClient = {
12+
let client = ChatClient.mock()
13+
client.currentUserId = .unique
14+
return client
15+
}()
16+
17+
private var streamChat: StreamChat?
18+
19+
override func setUp() {
20+
super.setUp()
21+
streamChat = StreamChat(chatClient: chatClient)
22+
}
23+
24+
func test_muteCommandHandler_selectingUserToMute() {
25+
// Given
26+
let symbol = "/mute"
27+
let muteCommandHandler = makeMuteCommandHandler()
28+
let command = ComposerCommand(
29+
id: symbol,
30+
typingSuggestion: TypingSuggestion(
31+
text: "@",
32+
locationRange: NSRange(location: 1, length: 0)
33+
), displayInfo: nil
34+
)
35+
36+
// When
37+
muteCommandHandler.handleCommand(
38+
for: .constant(symbol),
39+
selectedRangeLocation: .constant(0),
40+
command: .constant(command),
41+
extraData: [
42+
"chatUser": TestCommandsConfig.mockUsers[0]
43+
]
44+
)
45+
let canBeExecuted = muteCommandHandler.canBeExecuted(composerCommand: command)
46+
47+
// Then
48+
let user = muteCommandHandler.selectedUser
49+
XCTAssert(user == TestCommandsConfig.mockUsers[0])
50+
XCTAssert(canBeExecuted == true)
51+
}
52+
53+
func test_muteCommandHandler_showSuggestions() {
54+
// Given
55+
let muteCommandHandler = makeMuteCommandHandler()
56+
let command = ComposerCommand(
57+
id: "/mute",
58+
typingSuggestion: TypingSuggestion(
59+
text: "@",
60+
locationRange: NSRange(location: 1, length: 0)
61+
), displayInfo: nil
62+
)
63+
let expectation = expectation(description: "suggestions")
64+
65+
// When
66+
_ = muteCommandHandler.showSuggestions(for: command).sink { _ in
67+
log.debug("finished showing suggestions")
68+
} receiveValue: { suggestionInfo in
69+
// Then
70+
let users = suggestionInfo.value as! [ChatUser]
71+
XCTAssert(users.count == 3)
72+
expectation.fulfill()
73+
}
74+
75+
waitForExpectations(timeout: 5, handler: nil)
76+
}
77+
78+
func test_unmuteCommandHandler_selectingUserToUnmute() {
79+
// Given
80+
let symbol = "/unmute"
81+
let channelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)
82+
let unmuteCommandHandler = UnmuteCommandHandler(
83+
channelController: channelController,
84+
commandSymbol: symbol
85+
)
86+
let command = ComposerCommand(
87+
id: symbol,
88+
typingSuggestion: TypingSuggestion(
89+
text: "@",
90+
locationRange: NSRange(location: 1, length: 0)
91+
), displayInfo: nil
92+
)
93+
94+
// When
95+
unmuteCommandHandler.handleCommand(
96+
for: .constant(symbol),
97+
selectedRangeLocation: .constant(0),
98+
command: .constant(command),
99+
extraData: [
100+
"chatUser": TestCommandsConfig.mockUsers[0]
101+
]
102+
)
103+
let canBeExecuted = unmuteCommandHandler.canBeExecuted(composerCommand: command)
104+
105+
// Then
106+
let user = unmuteCommandHandler.selectedUser
107+
XCTAssert(user == TestCommandsConfig.mockUsers[0])
108+
XCTAssert(canBeExecuted == true)
109+
}
110+
111+
// MARK: - private
112+
113+
private func makeMuteCommandHandler(symbol: String = "/mute") -> MuteCommandHandler {
114+
let channelController = ChatChannelTestHelpers.makeChannelController(
115+
chatClient: chatClient,
116+
lastActiveWatchers: TestCommandsConfig.mockUsers
117+
)
118+
let muteCommandHandler = MuteCommandHandler(
119+
channelController: channelController,
120+
commandSymbol: symbol
121+
)
122+
return muteCommandHandler
123+
}
124+
}

0 commit comments

Comments
 (0)