Skip to content

Commit 7f6a3f9

Browse files
Added tests
1 parent 5f963fd commit 7f6a3f9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerView_Tests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,50 @@ class MessageComposerView_Tests: StreamChatTestCase {
121121
// Then
122122
assertSnapshot(matching: view, as: .image)
123123
}
124+
125+
func test_composerInputView_rangeSelection() {
126+
// Given
127+
let view = ComposerTextInputView(
128+
text: .constant("This is a sample text"),
129+
height: .constant(38),
130+
selectedRangeLocation: .constant(3),
131+
placeholder: "Send a message",
132+
editable: true
133+
)
134+
let inputView = InputTextView(
135+
frame: .init(x: 16, y: 16, width: defaultScreenSize.width - 32, height: 50)
136+
)
137+
138+
// When
139+
inputView.selectedRange.location = 3
140+
let coordinator = ComposerTextInputView.Coordinator(textInput: view, maxMessageLength: nil)
141+
coordinator.textViewDidChangeSelection(inputView)
142+
143+
// Then
144+
XCTAssert(coordinator.textInput.selectedRangeLocation == 3)
145+
}
146+
147+
func test_composerInputView_textSelection() {
148+
// Given
149+
let view = ComposerTextInputView(
150+
text: .constant("New text"),
151+
height: .constant(38),
152+
selectedRangeLocation: .constant(3),
153+
placeholder: "Send a message",
154+
editable: true
155+
)
156+
let inputView = InputTextView(
157+
frame: .init(x: 16, y: 16, width: defaultScreenSize.width - 32, height: 50)
158+
)
159+
160+
// When
161+
inputView.text = "New text"
162+
inputView.selectedRange.location = 3
163+
let coordinator = ComposerTextInputView.Coordinator(textInput: view, maxMessageLength: nil)
164+
coordinator.textViewDidChange(inputView)
165+
166+
// Then
167+
XCTAssert(coordinator.textInput.selectedRangeLocation == 3)
168+
XCTAssert(coordinator.textInput.text == "New text")
169+
}
124170
}

0 commit comments

Comments
 (0)