mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Bugfix/categories search (#3913)
* Fixes #3734 * Donot ignore case while searching categories * Fixed test-cases to ensure search terms are passed as it is to the CategoryClient * Used a First_Char_Caps title list term just to ensure test case tests as intended * Fixed searchAll with empty term test case
This commit is contained in:
parent
7f90361ffd
commit
4109d23023
2 changed files with 34 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.category
|
|||
|
||||
import categoryItem
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import depictedItem
|
||||
import fr.free.nrw.commons.upload.GpsCategoryModel
|
||||
|
|
@ -9,6 +10,7 @@ import io.reactivex.Single
|
|||
import io.reactivex.subjects.BehaviorSubject
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
|
|
@ -27,26 +29,39 @@ class CategoriesModelTest {
|
|||
MockitoAnnotations.initMocks(this)
|
||||
}
|
||||
|
||||
// Test Case for verifying that Categories search (MW api calls) are case-insensitive
|
||||
// Test Case for verifying that Categories search (MW api calls)
|
||||
@Test
|
||||
fun searchAllFoundCaseTest() {
|
||||
val categoriesModel = CategoriesModel(categoryClient, mock(), mock())
|
||||
|
||||
val expectedList = listOf("Test")
|
||||
whenever(categoryClient.searchCategoriesForPrefix("tes", 25))
|
||||
whenever(
|
||||
categoryClient.searchCategoriesForPrefix(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyInt(),
|
||||
ArgumentMatchers.anyInt()
|
||||
)
|
||||
)
|
||||
.thenReturn(Single.just(expectedList))
|
||||
|
||||
// Checking if both return "Test"
|
||||
val expectedItems = expectedList.map { CategoryItem(it, false) }
|
||||
categoriesModel.searchAll("tes", emptyList(), emptyList())
|
||||
var categoryTerm = "Test"
|
||||
categoriesModel.searchAll(categoryTerm, emptyList(), emptyList())
|
||||
.test()
|
||||
.assertValues(expectedItems)
|
||||
|
||||
categoriesModel.searchAll("Tes", emptyList(), emptyList())
|
||||
verify(categoryClient).searchCategoriesForPrefix(
|
||||
categoryTerm,
|
||||
CategoriesModel.SEARCH_CATS_LIMIT
|
||||
)
|
||||
|
||||
categoriesModel.searchAll(categoryTerm, emptyList(), emptyList())
|
||||
.test()
|
||||
.assertValues(expectedItems)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `searchAll with empty search terms creates results from gps, title search & recents`() {
|
||||
val gpsCategoryModel: GpsCategoryModel = mock()
|
||||
|
|
@ -54,11 +69,18 @@ class CategoriesModelTest {
|
|||
|
||||
whenever(gpsCategoryModel.categoriesFromLocation)
|
||||
.thenReturn(BehaviorSubject.createDefault(listOf("gpsCategory")))
|
||||
whenever(categoryClient.searchCategories("tes", 25))
|
||||
whenever(
|
||||
categoryClient.searchCategories(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyInt(),
|
||||
ArgumentMatchers.anyInt()
|
||||
)
|
||||
)
|
||||
.thenReturn(Single.just(listOf("titleSearch")))
|
||||
whenever(categoryDao.recentCategories(25)).thenReturn(listOf("recentCategories"))
|
||||
val imageTitleList = listOf("Test")
|
||||
CategoriesModel(categoryClient, categoryDao, gpsCategoryModel)
|
||||
.searchAll("", listOf("tes"), listOf(depictedItem))
|
||||
.searchAll("", imageTitleList, listOf(depictedItem))
|
||||
.test()
|
||||
.assertValue(
|
||||
listOf(
|
||||
|
|
@ -68,5 +90,8 @@ class CategoriesModelTest {
|
|||
categoryItem("recentCategories")
|
||||
)
|
||||
)
|
||||
imageTitleList.forEach {
|
||||
verify(categoryClient).searchCategories(it, CategoriesModel.SEARCH_CATS_LIMIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue