mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix 4615: Option for editing caption and description (#4672)
* DescriptionEditHelper implemented * Description extracted * Description editable * No description condition handled * Code cleanup * Added javadocs * toolbar added * API call done * Caption edit available * Progress dialog added * Log * Problem with ButterKnife * Caption is editable * Removed unused import * Manifest file reverted * Manifest file reverted * Manifest file reverted * View binding added * Post operation test added * Java docs added * Java docs added * MediaDetailFragment unit tests added * Test added
This commit is contained in:
parent
e910b1d14f
commit
0269894c64
20 changed files with 855 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertTrue
|
||||
|
|
@ -11,6 +12,7 @@ import org.mockito.Mock
|
|||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
||||
|
||||
/**
|
||||
* Test methods in media data extractor
|
||||
|
|
@ -49,4 +51,10 @@ class MediaDataExtractorTest {
|
|||
|
||||
//assertTrue(fetchMediaDetails is Media)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getWikiText() {
|
||||
`when`(mediaDataExtractor?.getCurrentWikiText(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just("Test"))
|
||||
}
|
||||
}
|
||||
|
|
@ -81,4 +81,15 @@ class PageEditClientTest {
|
|||
pageEditClient.prependEdit("test", "test", "test")
|
||||
verify(pageEditInterface).postPrependEdit(eq("test"), eq("test"), eq("test"), eq("test"))
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setCaptions
|
||||
*/
|
||||
@Test
|
||||
fun testSetCaptions() {
|
||||
Mockito.`when`(csrfTokenClient.tokenBlocking).thenReturn("test")
|
||||
pageEditClient.setCaptions("test", "test", "en", "test")
|
||||
verify(pageEditInterface).postCaptions(eq("test"), eq("test"), eq("en"),
|
||||
eq("test"), eq("test"))
|
||||
}
|
||||
}
|
||||
|
|
@ -199,6 +199,12 @@ class MediaClientTest {
|
|||
mediaClient.doesPageContainMedia("").test().assertValue(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getWikiText() {
|
||||
val wikiText = mock<MwQueryResponse>()
|
||||
whenever(mediaDetailInterface.getWikiText("File:Test.jpg")).thenReturn(Single.just(wikiText))
|
||||
}
|
||||
|
||||
private fun mockQuery(queryReceiver: MwQueryResult.() -> Unit): MwQueryResponse {
|
||||
val mwQueryResponse = mock<MwQueryResponse>()
|
||||
val mwQueryResult = mock<MwQueryResult>()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package fr.free.nrw.commons.media
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
|
|
@ -49,6 +51,9 @@ import kotlin.collections.HashMap
|
|||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class MediaDetailFragmentUnitTests {
|
||||
|
||||
|
||||
private val REQUEST_CODE = 1001
|
||||
private val REQUEST_CODE_EDIT_DESCRIPTION = 1002
|
||||
private lateinit var fragment: MediaDetailFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
|
|
@ -106,6 +111,9 @@ class MediaDetailFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var searchView: SearchView
|
||||
|
||||
@Mock
|
||||
private lateinit var intent: Intent
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
|
|
@ -140,6 +148,7 @@ class MediaDetailFragmentUnitTests {
|
|||
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
Whitebox.setInternalState(fragment, "progressBar", progressBar)
|
||||
Whitebox.setInternalState(fragment, "progressBarEditDescription", progressBar)
|
||||
Whitebox.setInternalState(fragment, "captionsListView", listView)
|
||||
Whitebox.setInternalState(fragment, "descriptionWebView", webView)
|
||||
Whitebox.setInternalState(fragment, "detailProvider", detailProvider)
|
||||
|
|
@ -159,6 +168,7 @@ class MediaDetailFragmentUnitTests {
|
|||
Whitebox.setInternalState(fragment, "dummyCategoryEditContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "showCaptionAndDescriptionContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "updateCategoriesButton", button)
|
||||
Whitebox.setInternalState(fragment, "editDescription", button)
|
||||
Whitebox.setInternalState(fragment, "categoryContainer", linearLayout)
|
||||
Whitebox.setInternalState(fragment, "categorySearchView", searchView)
|
||||
Whitebox.setInternalState(fragment, "mediaDiscussion", textView)
|
||||
|
|
@ -188,6 +198,24 @@ class MediaDetailFragmentUnitTests {
|
|||
fragment.onCreateView(layoutInflater, null, savedInstanceState)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnActivityResultLocationPickerActivity() {
|
||||
fragment.onActivityResult(REQUEST_CODE, Activity.RESULT_CANCELED, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `test OnActivity Result Cancelled LocationPickerActivity`() {
|
||||
fragment.onActivityResult(REQUEST_CODE, Activity.RESULT_CANCELED, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `test OnActivity Result Cancelled DescriptionEditActivity`() {
|
||||
fragment.onActivityResult(REQUEST_CODE, Activity.RESULT_OK, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSaveInstanceState() {
|
||||
|
|
@ -252,6 +280,17 @@ class MediaDetailFragmentUnitTests {
|
|||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetDescriptionList() {
|
||||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescriptionList"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetCaptions() {
|
||||
|
|
@ -301,6 +340,15 @@ class MediaDetailFragmentUnitTests {
|
|||
Assert.assertEquals(fragment.updateCategoryDisplay(listOf()), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testDescriptionEditClicked() {
|
||||
`when`(progressBar.visibility).thenReturn(View.VISIBLE)
|
||||
`when`(button.visibility).thenReturn(View.GONE)
|
||||
`when`(media.filename).thenReturn("")
|
||||
fragment.onDescriptionEditClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowCaptionAndDescriptionCaseVisible() {
|
||||
|
|
@ -397,6 +445,28 @@ class MediaDetailFragmentUnitTests {
|
|||
method.invoke(fragment, "mock")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testExtractCaptionDescription() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"extractCaptionDescription",
|
||||
String::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "mock")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetDescriptions() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescriptions",
|
||||
String::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "mock")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testPrettyCaptionCaseEmpty() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue