@@ -2,13 +2,15 @@ package fr.free.nrw.commons.category
2
2
3
3
import categoryItem
4
4
import com.nhaarman.mockitokotlin2.mock
5
+ import com.nhaarman.mockitokotlin2.verify
5
6
import com.nhaarman.mockitokotlin2.whenever
6
7
import depictedItem
7
8
import fr.free.nrw.commons.upload.GpsCategoryModel
8
9
import io.reactivex.Single
9
10
import io.reactivex.subjects.BehaviorSubject
10
11
import org.junit.Before
11
12
import org.junit.Test
13
+ import org.mockito.ArgumentMatchers
12
14
import org.mockito.Mock
13
15
import org.mockito.MockitoAnnotations
14
16
@@ -27,38 +29,58 @@ class CategoriesModelTest {
27
29
MockitoAnnotations .initMocks(this )
28
30
}
29
31
30
- // Test Case for verifying that Categories search (MW api calls) are case-insensitive
32
+ // Test Case for verifying that Categories search (MW api calls)
31
33
@Test
32
34
fun searchAllFoundCaseTest () {
33
35
val categoriesModel = CategoriesModel (categoryClient, mock(), mock())
34
36
35
37
val expectedList = listOf (" Test" )
36
- whenever(categoryClient.searchCategoriesForPrefix(" tes" , 25 ))
38
+ whenever(
39
+ categoryClient.searchCategoriesForPrefix(
40
+ ArgumentMatchers .anyString(),
41
+ ArgumentMatchers .anyInt(),
42
+ ArgumentMatchers .anyInt()
43
+ )
44
+ )
37
45
.thenReturn(Single .just(expectedList))
38
46
39
47
// Checking if both return "Test"
40
48
val expectedItems = expectedList.map { CategoryItem (it, false ) }
41
- categoriesModel.searchAll(" tes" , emptyList(), emptyList())
49
+ var categoryTerm = " Test"
50
+ categoriesModel.searchAll(categoryTerm, emptyList(), emptyList())
42
51
.test()
43
52
.assertValues(expectedItems)
44
53
45
- categoriesModel.searchAll(" Tes" , emptyList(), emptyList())
54
+ verify(categoryClient).searchCategoriesForPrefix(
55
+ categoryTerm,
56
+ CategoriesModel .SEARCH_CATS_LIMIT
57
+ )
58
+
59
+ categoriesModel.searchAll(categoryTerm, emptyList(), emptyList())
46
60
.test()
47
61
.assertValues(expectedItems)
48
62
}
49
63
64
+
50
65
@Test
51
66
fun `searchAll with empty search terms creates results from gps, title search & recents` () {
52
67
val gpsCategoryModel: GpsCategoryModel = mock()
53
68
val depictedItem = depictedItem(commonsCategories = listOf (" depictionCategory" ))
54
69
55
70
whenever(gpsCategoryModel.categoriesFromLocation)
56
71
.thenReturn(BehaviorSubject .createDefault(listOf (" gpsCategory" )))
57
- whenever(categoryClient.searchCategories(" tes" , 25 ))
72
+ whenever(
73
+ categoryClient.searchCategories(
74
+ ArgumentMatchers .anyString(),
75
+ ArgumentMatchers .anyInt(),
76
+ ArgumentMatchers .anyInt()
77
+ )
78
+ )
58
79
.thenReturn(Single .just(listOf (" titleSearch" )))
59
80
whenever(categoryDao.recentCategories(25 )).thenReturn(listOf (" recentCategories" ))
81
+ val imageTitleList = listOf (" Test" )
60
82
CategoriesModel (categoryClient, categoryDao, gpsCategoryModel)
61
- .searchAll(" " , listOf ( " tes " ) , listOf (depictedItem))
83
+ .searchAll(" " , imageTitleList , listOf (depictedItem))
62
84
.test()
63
85
.assertValue(
64
86
listOf (
@@ -68,5 +90,8 @@ class CategoriesModelTest {
68
90
categoryItem(" recentCategories" )
69
91
)
70
92
)
93
+ imageTitleList.forEach {
94
+ verify(categoryClient).searchCategories(it, CategoriesModel .SEARCH_CATS_LIMIT )
95
+ }
71
96
}
72
97
}
0 commit comments