mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Fixes 4620 : Editing categories of an existing picture: Reuse categories selection UI from the Upload Wizard (#4928)
* Entry to new UI * Getting existing categories * Hidden categories managed * Category edit updated * Category Edition implemented * Java docs added * Java docs added * Java docs added * Previous UI discarded * Test added * More test added * More test added * More test added * More test added * More java docs added * Minor changes
This commit is contained in:
parent
48343035d3
commit
11292ab514
32 changed files with 977 additions and 913 deletions
|
|
@ -294,8 +294,7 @@ class BookmarkListRootFragmentUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun `testBackPressed Case NonNull isVisible and backButton clicked`() {
|
||||
whenever(mediaDetails.isVisible).thenReturn(true)
|
||||
whenever(mediaDetails.backButtonClicked()).thenReturn(true)
|
||||
Assert.assertEquals(fragment.backPressed(), true)
|
||||
Assert.assertEquals(fragment.backPressed(), false)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -303,7 +302,6 @@ class BookmarkListRootFragmentUnitTest {
|
|||
fun `testBackPressed Case NonNull isVisible and backButton not clicked`() {
|
||||
Whitebox.setInternalState(fragment, "listFragment", mock(BookmarkPicturesFragment::class.java))
|
||||
whenever(mediaDetails.isVisible).thenReturn(true)
|
||||
whenever(mediaDetails.backButtonClicked()).thenReturn(false)
|
||||
whenever(mediaDetails.removedItems).thenReturn(ArrayList(0))
|
||||
Assert.assertEquals(fragment.backPressed(), false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import depictedItem
|
|||
import fr.free.nrw.commons.upload.GpsCategoryModel
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import media
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
|
|
@ -23,10 +24,16 @@ class CategoriesModelTest {
|
|||
@Mock
|
||||
internal lateinit var categoryClient: CategoryClient
|
||||
|
||||
@Mock
|
||||
internal lateinit var gpsCategoryModel: GpsCategoryModel
|
||||
|
||||
private lateinit var categoriesModel: CategoriesModel
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
categoriesModel = CategoriesModel(categoryClient, categoryDao, gpsCategoryModel)
|
||||
}
|
||||
|
||||
// Test Case for verifying that Categories search (MW api calls)
|
||||
|
|
@ -103,4 +110,106 @@ class CategoriesModelTest {
|
|||
verify(categoryClient).searchCategories(it, CategoriesModel.SEARCH_CATS_LIMIT)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetCategoriesByName(){
|
||||
categoriesModel.getCategoriesByName(listOf("Test"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test buildCategories when it returns non empty list`(){
|
||||
whenever(categoryClient.getCategoriesByName("Test",
|
||||
"Test", CategoriesModel.SEARCH_CATS_LIMIT
|
||||
)).thenReturn(Single.just(listOf(categoryItem())))
|
||||
categoriesModel.buildCategories("Test")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test buildCategories when it returns empty list`(){
|
||||
whenever(categoryClient.getCategoriesByName("Test",
|
||||
"Test", CategoriesModel.SEARCH_CATS_LIMIT
|
||||
)).thenReturn(Single.just(emptyList()))
|
||||
categoriesModel.buildCategories("Test")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetSelectedExistingCategories(){
|
||||
categoriesModel.getSelectedExistingCategories()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetSelectedExistingCategories(){
|
||||
categoriesModel.setSelectedExistingCategories(mutableListOf("Test"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is null and item is selected`(){
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"name",
|
||||
"des",
|
||||
"image",
|
||||
true
|
||||
), null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is null and item is not selected`(){
|
||||
categoriesModel.onCategoryItemClicked(categoryItem(), null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is selected and media contains category`(){
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"categories",
|
||||
"des",
|
||||
"image",
|
||||
true
|
||||
), media())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is selected and media does not contains category`(){
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"name",
|
||||
"des",
|
||||
"image",
|
||||
true
|
||||
), media())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is not selected and media contains category`(){
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"categories",
|
||||
"des",
|
||||
"image",
|
||||
false
|
||||
), media())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is not selected and media does not contains category`(){
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"name",
|
||||
"des",
|
||||
"image",
|
||||
false
|
||||
), media())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package fr.free.nrw.commons.category
|
||||
|
||||
import android.content.Context
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.actions.PageEditClient
|
||||
import fr.free.nrw.commons.notification.NotificationHelper
|
||||
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class CategoryEditHelperUnitTests {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var helper: CategoryEditHelper
|
||||
|
||||
@Mock
|
||||
private lateinit var notificationHelper: NotificationHelper
|
||||
|
||||
@Mock
|
||||
private lateinit var pageEditClient: PageEditClient
|
||||
|
||||
@Mock
|
||||
private lateinit var viewUtilWrapper: ViewUtilWrapper
|
||||
|
||||
@Mock
|
||||
private lateinit var media: Media
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
helper = CategoryEditHelper(notificationHelper, pageEditClient, viewUtilWrapper,
|
||||
"")
|
||||
Mockito.`when`(media.filename).thenReturn("File:Example.jpg")
|
||||
Mockito.`when`(pageEditClient.getCurrentWikiText(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(""))
|
||||
Mockito.`when`(
|
||||
pageEditClient.edit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString()
|
||||
)
|
||||
).thenReturn(Observable.just(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkNotNull() {
|
||||
Assert.assertNotNull(helper)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testMakeCategoryEdit() {
|
||||
helper.makeCategoryEdit(context, media, listOf("Test"), "[[Category:Test]]")
|
||||
Mockito.verify(viewUtilWrapper, Mockito.times(1)).showShortToast(
|
||||
context,
|
||||
context.getString(R.string.category_edit_helper_make_edit_toast)
|
||||
)
|
||||
Mockito.verify(pageEditClient, Mockito.times(1)).edit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
package fr.free.nrw.commons.category
|
||||
|
||||
import android.content.Context
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import fr.free.nrw.commons.nearby.Label
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
|
||||
class CategoryEditSearchRecyclerViewAdapterUnitTest {
|
||||
|
||||
private lateinit var adapter: CategoryEditSearchRecyclerViewAdapter
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var labels: ArrayList<Label>
|
||||
|
||||
@Mock
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
|
||||
@Mock
|
||||
private lateinit var categoryClient: CategoryClient
|
||||
|
||||
@Mock
|
||||
private lateinit var callback: CategoryEditSearchRecyclerViewAdapter.Callback
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
adapter =
|
||||
CategoryEditSearchRecyclerViewAdapter(
|
||||
context,
|
||||
labels,
|
||||
recyclerView,
|
||||
categoryClient,
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddToCategories() {
|
||||
val categories = mutableListOf<String>()
|
||||
Whitebox.setInternalState(adapter, "categories", categories)
|
||||
val testCategories = listOf("someString")
|
||||
adapter.addToCategories(testCategories)
|
||||
assertEquals(categories.size, testCategories.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemoveFromNewCategories() {
|
||||
val testCategory = "someString"
|
||||
val newCategories = mutableListOf(testCategory)
|
||||
val originalSize = newCategories.size
|
||||
Whitebox.setInternalState(adapter, "newCategories", newCategories)
|
||||
adapter.removeFromNewCategories(testCategory)
|
||||
assertEquals(newCategories.size, originalSize - 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddToNewCategories() {
|
||||
val testCategory = "someString"
|
||||
val newCategories = mutableListOf<String>()
|
||||
val originalSize = newCategories.size
|
||||
Whitebox.setInternalState(adapter, "newCategories", newCategories)
|
||||
adapter.addToNewCategories(testCategory)
|
||||
assertEquals(newCategories.size, originalSize + 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetCategories() {
|
||||
val categories = mutableListOf<String>()
|
||||
Whitebox.setInternalState(adapter, "categories", categories)
|
||||
assertEquals(adapter.categories, categories)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetNewCategories() {
|
||||
val newCategories = mutableListOf<String>()
|
||||
Whitebox.setInternalState(adapter, "newCategories", newCategories)
|
||||
assertEquals(adapter.newCategories, newCategories)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -259,7 +259,6 @@ class ExploreListRootFragmentUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun `testBackPressed_Case null != mediaDetails && mediaDetails_isVisible_backButtonNotClicked`() {
|
||||
`when`(mediaDetails.isVisible).thenReturn(true)
|
||||
`when`(mediaDetails.backButtonClicked()).thenReturn(true)
|
||||
Assert.assertEquals(fragment.backPressed(), true)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,6 @@ class WikidataItemDetailsActivityUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testOnBackPressedCaseReturn() {
|
||||
`when`(supportFragmentManager.backStackEntryCount).thenReturn(1)
|
||||
`when`(mediaDetailPagerFragment.backButtonClicked()).thenReturn(true)
|
||||
activity.onBackPressed()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,6 @@ class SearchActivityUnitTests {
|
|||
`when`(supportFragmentManager.backStackEntryCount).thenReturn(1)
|
||||
`when`(mediaDetails.isVisible).thenReturn(true)
|
||||
activity.refreshNominatedMedia(0)
|
||||
verify(mediaDetails).backButtonClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -215,9 +214,7 @@ class SearchActivityUnitTests {
|
|||
`when`(mFragments.supportFragmentManager).thenReturn(supportFragmentManager)
|
||||
`when`(supportFragmentManager.backStackEntryCount).thenReturn(1)
|
||||
`when`(mediaDetails.isVisible).thenReturn(true)
|
||||
`when`(mediaDetails.backButtonClicked()).thenReturn(true)
|
||||
activity.refreshNominatedMedia(0)
|
||||
verify(mediaDetails).backButtonClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -228,12 +225,10 @@ class SearchActivityUnitTests {
|
|||
Whitebox.setInternalState(activity, "mediaDetails", mediaDetails)
|
||||
`when`(mFragments.supportFragmentManager).thenReturn(supportFragmentManager)
|
||||
`when`(supportFragmentManager.backStackEntryCount).thenReturn(1)
|
||||
`when`(mediaDetails.backButtonClicked()).thenReturn(true)
|
||||
`when`(mediaDetails.isVisible).thenReturn(true)
|
||||
val method: Method = SearchActivity::class.java.getDeclaredMethod("onResume")
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(mediaDetails).backButtonClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ import com.facebook.drawee.backends.pipeline.Fresco
|
|||
import com.facebook.drawee.generic.GenericDraweeHierarchy
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.facebook.soloader.SoLoader
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.LocationPicker.LocationPickerActivity
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import fr.free.nrw.commons.category.CategoryEditSearchRecyclerViewAdapter
|
||||
import fr.free.nrw.commons.explore.SearchActivity
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
|
|
@ -97,9 +97,6 @@ class MediaDetailFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var locationManager: LocationServiceManager
|
||||
|
||||
@Mock
|
||||
private lateinit var categoryEditSearchRecyclerViewAdapter: CategoryEditSearchRecyclerViewAdapter
|
||||
|
||||
@Mock
|
||||
private lateinit var savedInstanceState: Bundle
|
||||
|
||||
|
|
@ -109,9 +106,6 @@ class MediaDetailFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var media: Media
|
||||
|
||||
@Mock
|
||||
private lateinit var categoryRecyclerView: RecyclerView
|
||||
|
||||
@Mock
|
||||
private lateinit var simpleDraweeView: SimpleDraweeView
|
||||
|
||||
|
|
@ -182,10 +176,8 @@ class MediaDetailFragmentUnitTests {
|
|||
scrollView = view.findViewById(R.id.mediaDetailScrollView)
|
||||
Whitebox.setInternalState(fragment, "scrollView", scrollView)
|
||||
|
||||
categoryRecyclerView = view.findViewById(R.id.rv_categories)
|
||||
progressBarDeletion = view.findViewById(R.id.progressBarDeletion)
|
||||
delete = view.findViewById(R.id.nominateDeletion)
|
||||
Whitebox.setInternalState(fragment, "categoryRecyclerView", categoryRecyclerView)
|
||||
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
Whitebox.setInternalState(fragment, "isDeleted", isDeleted)
|
||||
|
|
@ -212,21 +204,16 @@ class MediaDetailFragmentUnitTests {
|
|||
Whitebox.setInternalState(fragment, "delete", delete)
|
||||
Whitebox.setInternalState(fragment, "depictionContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "toDoLayout", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "dummyCategoryEditContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "authorLayout", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "showCaptionAndDescriptionContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "updateCategoriesButton", button)
|
||||
Whitebox.setInternalState(fragment, "editDescription", button)
|
||||
Whitebox.setInternalState(fragment, "depictEditButton", button)
|
||||
Whitebox.setInternalState(fragment, "categoryEditButton", button)
|
||||
Whitebox.setInternalState(fragment, "categoryContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "categorySearchView", searchView)
|
||||
Whitebox.setInternalState(fragment, "progressBarDeletion", progressBarDeletion)
|
||||
Whitebox.setInternalState(fragment, "progressBarEditCategory", progressBarDeletion)
|
||||
Whitebox.setInternalState(fragment, "mediaDiscussion", textView)
|
||||
Whitebox.setInternalState(fragment, "locationManager", locationManager)
|
||||
Whitebox.setInternalState(
|
||||
fragment,
|
||||
"categoryEditSearchRecyclerViewAdapter",
|
||||
categoryEditSearchRecyclerViewAdapter
|
||||
)
|
||||
|
||||
`when`(simpleDraweeView.hierarchy).thenReturn(genericDraweeHierarchy)
|
||||
val map = HashMap<String, String>()
|
||||
|
|
@ -606,16 +593,6 @@ class MediaDetailFragmentUnitTests {
|
|||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetupToDo() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"setupToDo"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnDiscussionLoaded() {
|
||||
|
|
@ -668,4 +645,46 @@ class MediaDetailFragmentUnitTests {
|
|||
fun testOnDeleteButtonClicked() {
|
||||
fragment.onDeleteButtonClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCategoryEditButtonClicked() {
|
||||
whenever(media.filename).thenReturn("File:Example.jpg")
|
||||
fragment.onCategoryEditButtonClicked()
|
||||
verify(media, times(1)).filename
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testDisplayMediaDetails() {
|
||||
whenever(media.filename).thenReturn("File:Example.jpg")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"displayMediaDetails"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
verify(media, times(4)).filename
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGotoCategoryEditor() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"gotoCategoryEditor",
|
||||
String::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "[[Category:Test]]")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnMediaRefreshed() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onMediaRefreshed",
|
||||
Media::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
}
|
||||
|
|
@ -8,10 +8,13 @@ import fr.free.nrw.commons.upload.categories.CategoriesContract
|
|||
import fr.free.nrw.commons.upload.categories.CategoriesPresenter
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.schedulers.TestScheduler
|
||||
import media
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import java.lang.reflect.Method
|
||||
|
||||
/**
|
||||
* The class contains unit test cases for CategoriesPresenter
|
||||
|
|
@ -39,6 +42,27 @@ class CategoriesPresenterTest {
|
|||
categoriesPresenter.onAttachView(view)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnAttachViewWithMedia() {
|
||||
categoriesPresenter.onAttachViewWithMedia(view, media())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onAttachViewWithMedia when media is not null`() {
|
||||
Whitebox.setInternalState(categoriesPresenter, "media", media())
|
||||
whenever(repository.getCategories(repository.selectedExistingCategories))
|
||||
.thenReturn(Observable.just(mutableListOf(categoryItem())))
|
||||
whenever(repository.searchAll("mock", emptyList(), repository.selectedDepictions))
|
||||
.thenReturn(Observable.just(mutableListOf(categoryItem())))
|
||||
val method: Method = CategoriesPresenter::class.java.getDeclaredMethod(
|
||||
"searchResults",
|
||||
String::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(categoriesPresenter, "mock") }
|
||||
|
||||
/**
|
||||
* unit test case for method CategoriesPresenter.searchForCategories
|
||||
*/
|
||||
|
|
@ -122,6 +146,16 @@ class CategoriesPresenterTest {
|
|||
fun onCategoryItemClickedTest() {
|
||||
val categoryItem = categoryItem()
|
||||
categoriesPresenter.onCategoryItemClicked(categoryItem)
|
||||
verify(repository).onCategoryClicked(categoryItem)
|
||||
verify(repository).onCategoryClicked(categoryItem, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClearPreviousSelection() {
|
||||
categoriesPresenter.clearPreviousSelection()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUpdateCategories() {
|
||||
categoriesPresenter.updateCategories(media(), "[[Category:Test]]")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.upload
|
|||
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.category.CategoriesModel
|
||||
import fr.free.nrw.commons.category.CategoryItem
|
||||
import fr.free.nrw.commons.contributions.Contribution
|
||||
|
|
@ -73,6 +74,9 @@ class UploadRepositoryUnitTest {
|
|||
@Mock
|
||||
private lateinit var imageCoordinates: ImageCoordinates
|
||||
|
||||
@Mock
|
||||
private lateinit var media: Media
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
|
@ -142,8 +146,8 @@ class UploadRepositoryUnitTest {
|
|||
|
||||
@Test
|
||||
fun testOnCategoryClicked() {
|
||||
repository.onCategoryClicked(categoryItem)
|
||||
verify(categoriesModel).onCategoryItemClicked(categoryItem)
|
||||
repository.onCategoryClicked(categoryItem, media)
|
||||
verify(categoriesModel).onCategoryItemClicked(categoryItem, media)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -339,4 +343,21 @@ class UploadRepositoryUnitTest {
|
|||
method.invoke(repository, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetSelectedExistingCategories() {
|
||||
assertEquals(repository.selectedExistingCategories,
|
||||
categoriesModel.getSelectedExistingCategories())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSetSelectedExistingCategories() {
|
||||
assertEquals(repository.setSelectedExistingCategories(listOf("Test")),
|
||||
categoriesModel.setSelectedExistingCategories(mutableListOf("Test")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetCategories() {
|
||||
assertEquals(repository.getCategories(listOf("Test")),
|
||||
categoriesModel.getCategoriesByName(mutableListOf("Test")))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
package fr.free.nrw.commons.upload.categories
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import android.text.Editable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
|
|
@ -12,6 +14,10 @@ import androidx.fragment.app.FragmentManager
|
|||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.nhaarman.mockitokotlin2.times
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestAppAdapter
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
|
|
@ -53,6 +59,9 @@ class UploadCategoriesFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var pbCategories: ProgressBar
|
||||
|
||||
@Mock
|
||||
private lateinit var progressDialog: ProgressDialog
|
||||
|
||||
@Mock
|
||||
private lateinit var tilContainerEtSearch: TextInputLayout
|
||||
|
||||
|
|
@ -74,6 +83,9 @@ class UploadCategoriesFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var editable: Editable
|
||||
|
||||
@Mock
|
||||
private lateinit var button: Button
|
||||
|
||||
@Mock
|
||||
private lateinit var adapter: UploadCategoryAdapter
|
||||
|
||||
|
|
@ -83,6 +95,10 @@ class UploadCategoriesFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var presenter: CategoriesContract.UserActionListener
|
||||
|
||||
@Mock
|
||||
private lateinit var media: Media
|
||||
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
|
@ -108,6 +124,10 @@ class UploadCategoriesFragmentUnitTests {
|
|||
Whitebox.setInternalState(fragment, "tvTitle", tvTitle)
|
||||
Whitebox.setInternalState(fragment, "tooltip", tooltip)
|
||||
Whitebox.setInternalState(fragment, "tvSubTitle", tvSubTitle)
|
||||
Whitebox.setInternalState(fragment, "btnNext", button)
|
||||
Whitebox.setInternalState(fragment, "btnPrevious", button)
|
||||
Whitebox.setInternalState(fragment, "progressDialog", progressDialog)
|
||||
Whitebox.setInternalState(fragment, "wikiText", "[[Category:Test]]")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -185,6 +205,51 @@ class UploadCategoriesFragmentUnitTests {
|
|||
fragment.showNoCategorySelected()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetExistingCategories() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.existingCategories
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFragmentContext() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.fragmentContext
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGoBackToPreviousScreen() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.goBackToPreviousScreen()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowProgressDialog() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showProgressDialog()
|
||||
verify(progressDialog, times(0)).show()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testDismissProgressDialog() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.dismissProgressDialog()
|
||||
verify(progressDialog, times(1)).dismiss()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test showNoCategorySelected when media is not null`() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
fragment.showNoCategorySelected()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnNextButtonClicked() {
|
||||
|
|
@ -192,6 +257,14 @@ class UploadCategoriesFragmentUnitTests {
|
|||
fragment.onNextButtonClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onNextButtonClicked when media is not null`() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
fragment.onNextButtonClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPreviousButtonClicked() {
|
||||
|
|
@ -256,4 +329,16 @@ class UploadCategoriesFragmentUnitTests {
|
|||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test init when media is not null`() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
val method: Method = UploadCategoriesFragment::class.java.getDeclaredMethod(
|
||||
"init"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue