Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search tests #7558

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.matrix.android.sdk.session.search

import org.amshove.kluent.shouldBeEqualTo
import org.junit.Assert.assertTrue
import org.junit.FixMethodOrder
import org.junit.Test
Expand Down Expand Up @@ -43,7 +44,7 @@ class SearchMessagesTest : InstrumentedTest {
cryptoTestData.firstSession
.searchService()
.search(
searchTerm = "lore",
searchTerm = "lorem",
limit = 10,
includeProfile = true,
afterLimit = 0,
Expand All @@ -61,7 +62,7 @@ class SearchMessagesTest : InstrumentedTest {
cryptoTestData.firstSession
.searchService()
.search(
searchTerm = "lore",
searchTerm = "lorem",
roomId = cryptoTestData.roomId,
limit = 10,
includeProfile = true,
Expand All @@ -73,7 +74,28 @@ class SearchMessagesTest : InstrumentedTest {
}
}

private fun doTest(block: suspend (CryptoTestData) -> SearchResult) = runCryptoTest(context()) { cryptoTestHelper, commonTestHelper ->
@Test
fun sendTextMessageAndSearchPartOfItIncompleteWord() {
doTest(expectedNumberOfResult = 0) { cryptoTestData ->
cryptoTestData.firstSession
.searchService()
.search(
searchTerm = "lore", /* incomplete word */
roomId = cryptoTestData.roomId,
limit = 10,
includeProfile = true,
afterLimit = 0,
beforeLimit = 10,
orderByRecent = true,
nextBatch = null
)
}
}

private fun doTest(
expectedNumberOfResult: Int = 2,
block: suspend (CryptoTestData) -> SearchResult,
) = runCryptoTest(context()) { cryptoTestHelper, commonTestHelper ->
val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceInARoom(false)
val aliceSession = cryptoTestData.firstSession
val aliceRoomId = cryptoTestData.roomId
Expand All @@ -87,7 +109,7 @@ class SearchMessagesTest : InstrumentedTest {

val data = block.invoke(cryptoTestData)

assertTrue(data.results?.size == 2)
data.results?.size shouldBeEqualTo expectedNumberOfResult
assertTrue(
data.results
?.all {
Expand Down