Skip to content

Commit 968cd33

Browse files
added tests for typing suggestions
1 parent c7c932f commit 968cd33

File tree

4 files changed

+169
-1
lines changed

4 files changed

+169
-1
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
842383E427678A4D00888CFC /* QuotedMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842383E327678A4D00888CFC /* QuotedMessageView.swift */; };
2020
8423C33D277C94F30092DCF1 /* TwoStepMentionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C33C277C94F30092DCF1 /* TwoStepMentionCommand.swift */; };
2121
8423C33F277C9A5F0092DCF1 /* UnmuteCommandHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C33E277C9A5F0092DCF1 /* UnmuteCommandHandler.swift */; };
22+
8423C342277CBA280092DCF1 /* TypingSuggester_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8423C341277CBA280092DCF1 /* TypingSuggester_Tests.swift */; };
2223
842F0BB8276B3518002C400C /* QuotedMessageView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */; };
2324
84335014274BAB15007A1B81 /* ViewFactoryExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */; };
2425
84335016274BABF3007A1B81 /* NewChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335015274BABF3007A1B81 /* NewChatView.swift */; };
@@ -313,6 +314,7 @@
313314
842383E327678A4D00888CFC /* QuotedMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedMessageView.swift; sourceTree = "<group>"; };
314315
8423C33C277C94F30092DCF1 /* TwoStepMentionCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoStepMentionCommand.swift; sourceTree = "<group>"; };
315316
8423C33E277C9A5F0092DCF1 /* UnmuteCommandHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnmuteCommandHandler.swift; sourceTree = "<group>"; };
317+
8423C341277CBA280092DCF1 /* TypingSuggester_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypingSuggester_Tests.swift; sourceTree = "<group>"; };
316318
842E979C275E0AD000A52E7B /* StreamChatSwiftUI.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = StreamChatSwiftUI.xctestplan; sourceTree = "<group>"; };
317319
842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedMessageView_Tests.swift; sourceTree = "<group>"; };
318320
84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactoryExamples.swift; sourceTree = "<group>"; };
@@ -608,6 +610,14 @@
608610
path = InstantCommands;
609611
sourceTree = "<group>";
610612
};
613+
8423C340277CB5C70092DCF1 /* Suggestions */ = {
614+
isa = PBXGroup;
615+
children = (
616+
8423C341277CBA280092DCF1 /* TypingSuggester_Tests.swift */,
617+
);
618+
path = Suggestions;
619+
sourceTree = "<group>";
620+
};
611621
8465FBAB2746873A00AF091E = {
612622
isa = PBXGroup;
613623
children = (
@@ -1111,6 +1121,7 @@
11111121
84C94D472758BDB2007FE2B9 /* ChatChannel */ = {
11121122
isa = PBXGroup;
11131123
children = (
1124+
8423C340277CB5C70092DCF1 /* Suggestions */,
11141125
84C94D482758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift */,
11151126
84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */,
11161127
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
@@ -1558,6 +1569,7 @@
15581569
84C94CCE27578B92007FE2B9 /* ChatChannel_Mock.swift in Sources */,
15591570
84C94D3B27579BB0007FE2B9 /* AssertResult.swift in Sources */,
15601571
84C94CD027578B92007FE2B9 /* ChatMessage_Mock.swift in Sources */,
1572+
8423C342277CBA280092DCF1 /* TypingSuggester_Tests.swift in Sources */,
15611573
84C94D0627578BF2007FE2B9 /* UnwrapAsync.swift in Sources */,
15621574
84C94D0427578BF2007FE2B9 /* TestError.swift in Sources */,
15631575
84C94D0A27578BF2007FE2B9 /* TestDataModel.xcdatamodeld in Sources */,
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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 TypingSuggester_Tests: XCTestCase {
10+
11+
func test_typingSuggester_mentionWholeText() {
12+
// Given
13+
let options = TypingSuggestionOptions(symbol: "@")
14+
let typingSuggester = TypingSuggester(options: options)
15+
let string = "@Martin"
16+
let caretLocation = 7
17+
18+
// When
19+
let suggestion = typingSuggester.typingSuggestion(
20+
in: string,
21+
caretLocation: caretLocation
22+
)
23+
24+
// Then
25+
XCTAssert(suggestion?.text == "Martin")
26+
XCTAssert(suggestion?.locationRange == NSRange(location: 1, length: 6))
27+
}
28+
29+
func test_typingSuggester_mentionMiddleOfText() {
30+
// Given
31+
let options = TypingSuggestionOptions(symbol: "@")
32+
let typingSuggester = TypingSuggester(options: options)
33+
let string = "@Martin"
34+
let caretLocation = 5
35+
36+
// When
37+
let suggestion = typingSuggester.typingSuggestion(
38+
in: string,
39+
caretLocation: caretLocation
40+
)
41+
42+
// Then
43+
XCTAssert(suggestion?.text == "Mart")
44+
XCTAssert(suggestion?.locationRange == NSRange(location: 1, length: 4))
45+
}
46+
47+
func test_typingSuggester_mentionDifferentSymbol() {
48+
// Given
49+
let options = TypingSuggestionOptions(symbol: "$")
50+
let typingSuggester = TypingSuggester(options: options)
51+
let string = "$cash"
52+
let caretLocation = 3
53+
54+
// When
55+
let suggestion = typingSuggester.typingSuggestion(
56+
in: string,
57+
caretLocation: caretLocation
58+
)
59+
60+
// Then
61+
XCTAssert(suggestion?.text == "ca")
62+
XCTAssert(suggestion?.locationRange == NSRange(location: 1, length: 2))
63+
}
64+
65+
func test_typingSuggester_notFoundEmptySpace() {
66+
// Given
67+
let options = TypingSuggestionOptions(symbol: "@")
68+
let typingSuggester = TypingSuggester(options: options)
69+
let string = "@M art"
70+
let caretLocation = 3
71+
72+
// When
73+
let suggestion = typingSuggester.typingSuggestion(
74+
in: string,
75+
caretLocation: caretLocation
76+
)
77+
78+
// Then
79+
XCTAssert(suggestion == nil)
80+
}
81+
82+
func test_typingSuggester_notFoundNotOnStart() {
83+
// Given
84+
let options = TypingSuggestionOptions(symbol: "@")
85+
let typingSuggester = TypingSuggester(options: options)
86+
let string = "Hello@User"
87+
let caretLocation = 7
88+
89+
// When
90+
let suggestion = typingSuggester.typingSuggestion(
91+
in: string,
92+
caretLocation: caretLocation
93+
)
94+
95+
// Then
96+
XCTAssert(suggestion == nil)
97+
}
98+
99+
func test_typingSuggester_minimumNumberOfCharacters() {
100+
// Given
101+
let options = TypingSuggestionOptions(
102+
symbol: "@",
103+
minimumRequiredCharacters: 5
104+
)
105+
let typingSuggester = TypingSuggester(options: options)
106+
let string = "@Mar"
107+
let caretLocation = 4
108+
109+
// When
110+
let suggestion = typingSuggester.typingSuggestion(
111+
in: string,
112+
caretLocation: caretLocation
113+
)
114+
115+
// Then
116+
XCTAssert(suggestion == nil)
117+
}
118+
119+
func test_typingSuggester_notOnlyOnStartAllowed() {
120+
// Given
121+
let options = TypingSuggestionOptions(symbol: "@")
122+
let typingSuggester = TypingSuggester(options: options)
123+
let string = "Hey @Mar"
124+
let caretLocation = 8
125+
126+
// When
127+
let suggestion = typingSuggester.typingSuggestion(
128+
in: string,
129+
caretLocation: caretLocation
130+
)
131+
132+
// Then
133+
XCTAssert(suggestion?.text == "Mar")
134+
XCTAssert(suggestion?.locationRange == NSRange(location: 5, length: 3))
135+
}
136+
137+
func test_typingSuggester_onlyOnStartAllowed() {
138+
// Given
139+
let options = TypingSuggestionOptions(
140+
symbol: "@",
141+
shouldTriggerOnlyAtStart: true
142+
)
143+
let typingSuggester = TypingSuggester(options: options)
144+
let string = "Hey @Mar"
145+
let caretLocation = 8
146+
147+
// When
148+
let suggestion = typingSuggester.typingSuggestion(
149+
in: string,
150+
caretLocation: caretLocation
151+
)
152+
153+
// Then
154+
XCTAssert(suggestion == nil)
155+
}
156+
}
239 Bytes
Loading

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class ViewFactory_Tests: XCTestCase {
179179
)
180180

181181
// Then
182-
XCTAssert(view is GiphyAttachmentView)
182+
XCTAssert(view is GiphyAttachmentView<DefaultViewFactory>)
183183
}
184184

185185
func test_viewFactory_makeLinkAttachmentView() {

0 commit comments

Comments
 (0)