mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Feature: Show where file is being used on Commons & Other wikis (#6006)
* add url to build config Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * add network call functions Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * return response asynchronously Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * inject page size in the request Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * rename from Commons..Response.kt to ..Response.kt Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * convert to .kt Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * ui setup working Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * fix merge conflict Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * cleanup Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * fix CI Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * use suspend function for network calls Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> * doc * doc * doc * doc * doc --------- Signed-off-by: parneet-guraya <gurayaparneet@gmail.com> Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
04a07ed655
commit
85d9aef2f3
13 changed files with 2587 additions and 1499 deletions
|
|
@ -17,7 +17,7 @@ import fr.free.nrw.commons.customselector.ui.selector.ImageLoader
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.junit.After
|
||||
|
|
@ -34,7 +34,6 @@ import org.robolectric.RobolectricTestRunner
|
|||
import org.robolectric.annotation.Config
|
||||
import java.lang.reflect.Field
|
||||
import java.util.TreeMap
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* Custom Selector image adapter test.
|
||||
|
|
@ -65,7 +64,7 @@ class ImageAdapterTest {
|
|||
private lateinit var selectedImageField: Field
|
||||
private var uri: Uri = Mockito.mock(Uri::class.java)
|
||||
private lateinit var image: Image
|
||||
private val testDispatcher = TestCoroutineDispatcher()
|
||||
private val testDispatcher = StandardTestDispatcher()
|
||||
|
||||
/**
|
||||
* Set up variables.
|
||||
|
|
@ -91,7 +90,6 @@ class ImageAdapterTest {
|
|||
@After
|
||||
fun tearDown() {
|
||||
Dispatchers.resetMain()
|
||||
testDispatcher.cleanupTestCoroutines()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@ import fr.free.nrw.commons.upload.FileUtilsWrapper
|
|||
import io.reactivex.Single
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
|
|
@ -45,7 +46,6 @@ import java.io.File
|
|||
import java.io.FileInputStream
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
/**
|
||||
* Image Loader Test.
|
||||
|
|
@ -92,7 +92,7 @@ class ImageLoaderTest {
|
|||
private lateinit var contentResolver: ContentResolver
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
private val testDispacher = TestCoroutineDispatcher()
|
||||
private val testDispacher = StandardTestDispatcher()
|
||||
|
||||
private lateinit var imageLoader: ImageLoader
|
||||
private var mapImageSHA1: HashMap<Uri, String> = HashMap()
|
||||
|
|
@ -153,7 +153,6 @@ class ImageLoaderTest {
|
|||
@ExperimentalCoroutinesApi
|
||||
fun tearDown() {
|
||||
Dispatchers.resetMain()
|
||||
testDispacher.cleanupTestCoroutines()
|
||||
mockedPickedFiles.close()
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +161,7 @@ class ImageLoaderTest {
|
|||
*/
|
||||
@Test
|
||||
fun testQueryAndSetViewUploadedStatusNull() =
|
||||
testDispacher.runBlockingTest {
|
||||
TestScope(testDispacher).runTest {
|
||||
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(null)
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
mapModifiedImageSHA1[image] = "testSha1"
|
||||
|
|
@ -182,7 +181,7 @@ class ImageLoaderTest {
|
|||
*/
|
||||
@Test
|
||||
fun testQueryAndSetViewUploadedStatusNotNull() =
|
||||
testDispacher.runBlockingTest {
|
||||
TestScope(testDispacher).runTest {
|
||||
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(uploadedStatus)
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
whenever(context.getSharedPreferences("custom_selector", 0))
|
||||
|
|
@ -195,7 +194,7 @@ class ImageLoaderTest {
|
|||
*/
|
||||
@Test
|
||||
fun testNextActionableImage() =
|
||||
testDispacher.runBlockingTest {
|
||||
TestScope(testDispacher).runTest {
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(0)
|
||||
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(0)
|
||||
|
|
@ -208,16 +207,40 @@ class ImageLoaderTest {
|
|||
whenever(PickedFiles.pickedExistingPicture(context, Uri.parse("test"))).thenReturn(
|
||||
uploadableFile,
|
||||
)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
imageLoader.nextActionableImage(
|
||||
listOf(image),
|
||||
testDispacher,
|
||||
testDispacher,
|
||||
0,
|
||||
emptyList()
|
||||
)
|
||||
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(1)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
imageLoader.nextActionableImage(
|
||||
listOf(image),
|
||||
testDispacher,
|
||||
testDispacher,
|
||||
0,
|
||||
emptyList()
|
||||
)
|
||||
|
||||
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(2)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
imageLoader.nextActionableImage(
|
||||
listOf(image),
|
||||
testDispacher,
|
||||
testDispacher,
|
||||
0,
|
||||
emptyList()
|
||||
)
|
||||
|
||||
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(2)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
imageLoader.nextActionableImage(
|
||||
listOf(image),
|
||||
testDispacher,
|
||||
testDispacher,
|
||||
0,
|
||||
emptyList()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -226,7 +249,7 @@ class ImageLoaderTest {
|
|||
@Test
|
||||
@ExperimentalCoroutinesApi
|
||||
fun testGetSha1() =
|
||||
testDispacher.runBlockingTest {
|
||||
TestScope(testDispacher).runTest {
|
||||
BDDMockito
|
||||
.given(PickedFiles.pickedExistingPicture(context, image.uri))
|
||||
.willReturn(UploadableFile(uri, File("ABC")))
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ class MediaDetailFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var mockSharedPreferencesEditor: SharedPreferences.Editor
|
||||
|
||||
private lateinit var binding: FragmentMediaDetailBinding
|
||||
private lateinit var _binding: FragmentMediaDetailBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
|
@ -185,12 +185,12 @@ class MediaDetailFragmentUnitTests {
|
|||
|
||||
layoutInflater = LayoutInflater.from(activity)
|
||||
|
||||
binding = FragmentMediaDetailBinding.inflate(layoutInflater)
|
||||
_binding = FragmentMediaDetailBinding.inflate(layoutInflater)
|
||||
|
||||
scrollView = binding.mediaDetailScrollView
|
||||
scrollView = _binding.mediaDetailScrollView
|
||||
|
||||
progressBarDeletion = binding.progressBarDeletion
|
||||
delete = binding.nominateDeletion
|
||||
progressBarDeletion = _binding.progressBarDeletion
|
||||
delete = _binding.nominateDeletion
|
||||
|
||||
Whitebox.setInternalState(fragment, "media", media)
|
||||
Whitebox.setInternalState(fragment, "isDeleted", isDeleted)
|
||||
|
|
@ -198,13 +198,13 @@ class MediaDetailFragmentUnitTests {
|
|||
Whitebox.setInternalState(fragment, "reasonListEnglishMappings", reasonListEnglishMappings)
|
||||
Whitebox.setInternalState(fragment, "reasonBuilder", reasonBuilder)
|
||||
Whitebox.setInternalState(fragment, "deleteHelper", deleteHelper)
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
Whitebox.setInternalState(fragment, "_binding", _binding)
|
||||
Whitebox.setInternalState(fragment, "detailProvider", detailProvider)
|
||||
Whitebox.setInternalState(binding, "mediaDetailImageView", simpleDraweeView)
|
||||
Whitebox.setInternalState(binding, "mediaDetailTitle", textView)
|
||||
Whitebox.setInternalState(binding, "mediaDetailDepictionContainer", linearLayout)
|
||||
Whitebox.setInternalState(binding, "dummyCaptionDescriptionContainer", linearLayout)
|
||||
Whitebox.setInternalState(binding, "depictionsEditButton", button)
|
||||
Whitebox.setInternalState(_binding, "mediaDetailImageView", simpleDraweeView)
|
||||
Whitebox.setInternalState(_binding, "mediaDetailTitle", textView)
|
||||
Whitebox.setInternalState(_binding, "mediaDetailDepictionContainer", linearLayout)
|
||||
Whitebox.setInternalState(_binding, "dummyCaptionDescriptionContainer", linearLayout)
|
||||
Whitebox.setInternalState(_binding, "depictionsEditButton", button)
|
||||
Whitebox.setInternalState(fragment, "locationManager", locationManager)
|
||||
|
||||
`when`(simpleDraweeView.hierarchy).thenReturn(genericDraweeHierarchy)
|
||||
|
|
@ -241,7 +241,7 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testLaunchZoomActivity() {
|
||||
`when`(media.imageUrl).thenReturn("")
|
||||
fragment.launchZoomActivity(binding.root)
|
||||
fragment.launchZoomActivity(_binding.root)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue