Skip to content

Commit

Permalink
fix: remove trim of spaces when searching for messages inside a conve…
Browse files Browse the repository at this point in the history
…rsation (WPB-5834) (#2660)
  • Loading branch information
alexandreferris authored Feb 5, 2024
1 parent b629f32 commit a077325
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SearchConversationMessagesViewModel @Inject constructor(
)
if (textQueryChanged && searchQuery.text.isNotBlank()) {
viewModelScope.launch {
mutableSearchQueryFlow.emit(searchQuery.text.trim())
mutableSearchQueryFlow.emit(searchQuery.text)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,57 @@ class SearchConversationMessagesViewModelTest {
}
}

@Test
fun `given search term with space, when searching for messages, then search results are as expected`() = runTest {
// given
val searchTerm = "no "
val message1 = mockMessageWithText.copy(
messageContent = UIMessageContent.TextMessage(
messageBody = MessageBody(
UIText.DynamicString("not a normal text")
)
)
)
val message2 = mockMessageWithText.copy(
messageContent = UIMessageContent.TextMessage(
messageBody = MessageBody(
UIText.DynamicString("this message contains a no message")
)
)
)

val messages = listOf(
message1,
message2
)

val (arrangement, viewModel) = SearchConversationMessagesViewModelArrangement()
.withSuccessSearch(PagingData.from(messages))
.arrange()

// when
viewModel.searchQueryChanged(TextFieldValue(searchTerm))
advanceUntilIdle()

// then
assertEquals(
TextFieldValue(searchTerm),
viewModel.searchConversationMessagesState.searchQuery
)
coVerify(exactly = 0) {
arrangement.getSearchMessagesForConversation(
searchTerm,
arrangement.conversationId,
any()
)
}
viewModel.searchConversationMessagesState.searchResult.test {
awaitItem().map {
it shouldBeEqualTo message2
}
}
}

@Test
fun `given search term with empty space at start and at end, when searching for messages, then specific messages are returned`() =
runTest {
Expand Down

0 comments on commit a077325

Please sign in to comment.