Fixes #4704: Remove 'Please Wait' dialog and do task in background (#5570)

* Initial changes to the flow, merged conflicts

* Major changes to flow and logic

* Final major changes to the flow and merged conflicts

* Minor changes to thumbnail flow and merge conflicts

* Fixed ImageProcessingServiceTest

* Removed unnecessary file

* Some code cleanup and fixed UploadRepositoryUnitTest

* Minor javadoc changes and null checks

* Fixed UMDFragmentUnitTest

* Fixed and added new tests in UploadMediaPresenterTest

* Optimised code for no connection cases and minor code cleanup

* Minor bug fix

* Fixed minor bug

* Fixed a failing unit test

* Removed values-yue-hant

* Update UploadRepository.java

---------

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
Shashwat Kedia 2024-03-27 13:03:28 +05:30 committed by GitHub
parent 16960a369a
commit 42641644cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 588 additions and 266 deletions

View file

@ -128,7 +128,7 @@ class ImageProcessingServiceTest {
fun validateImageForFileNameExistsWithCheckTitleOn() {
`when`(mediaClient?.checkPageExistsUsingTitle(ArgumentMatchers.anyString()))
.thenReturn(Single.just(true))
val validateImage = imageProcessingService!!.validateImage(uploadItem, location)
val validateImage = imageProcessingService!!.validateCaption(uploadItem)
assertEquals(ImageUtils.FILE_NAME_EXISTS, validateImage.blockingGet())
}
}

View file

@ -69,6 +69,9 @@ class UploadMediaPresenterTest {
@Mock
private lateinit var jsonKvStore: JsonKvStore
@Mock
lateinit var mockActivity: UploadActivity
/**
* initial setup unit test environment
*/
@ -79,8 +82,9 @@ class UploadMediaPresenterTest {
testObservableUploadItem = Observable.just(uploadItem)
testSingleImageResult = Single.just(1)
testScheduler = TestScheduler()
uploadMediaPresenter = UploadMediaPresenter(repository,
jsonKvStore,testScheduler, testScheduler)
uploadMediaPresenter = UploadMediaPresenter(
repository, jsonKvStore, testScheduler, testScheduler
)
uploadMediaPresenter.onAttachView(view)
mockedCountry = mockStatic(Coordinates2Country::class.java)
}
@ -111,14 +115,13 @@ class UploadMediaPresenterTest {
ArgumentMatchers.any(UploadItem::class.java),
ArgumentMatchers.any(Place::class.java)
)
verify(view).showProgress(false)
}
/**
* unit test for method UploadMediaPresenter.verifyImageQuality (For else case)
* unit test for method UploadMediaPresenter.getImageQuality (For else case)
*/
@Test
fun verifyImageQualityTest() {
fun getImageQualityTest() {
whenever(repository.uploads).thenReturn(listOf(uploadItem))
whenever(repository.getImageQuality(uploadItem, location))
.thenReturn(testSingleImageResult)
@ -127,17 +130,16 @@ class UploadMediaPresenterTest {
.thenReturn(imageCoordinates)
whenever(uploadItem.gpsCoords.decimalCoords)
.thenReturn("imageCoordinates")
uploadMediaPresenter.verifyImageQuality(0, location)
uploadMediaPresenter.getImageQuality(0, location, mockActivity)
verify(view).showProgress(true)
testScheduler.triggerActions()
verify(view).showProgress(false)
}
/**
* unit test for method UploadMediaPresenter.verifyImageQuality (For if case)
* unit test for method UploadMediaPresenter.getImageQuality (For if case)
*/
@Test
fun `verify ImageQuality Test while coordinates equals to null`() {
fun `get ImageQuality Test while coordinates equals to null`() {
whenever(repository.uploads).thenReturn(listOf(uploadItem))
whenever(repository.getImageQuality(uploadItem, location))
.thenReturn(testSingleImageResult)
@ -146,30 +148,35 @@ class UploadMediaPresenterTest {
.thenReturn(imageCoordinates)
whenever(uploadItem.gpsCoords.decimalCoords)
.thenReturn(null)
uploadMediaPresenter.verifyImageQuality(0, location)
uploadMediaPresenter.getImageQuality(0, location, mockActivity)
testScheduler.triggerActions()
}
/**
* unit test for method UploadMediaPresenter.handleImageResult
* Test for empty file name when the user presses the NEXT button
*/
@Test
fun handleImageResult() {
//Positive case test
uploadMediaPresenter.handleImageResult(IMAGE_KEEP, uploadItem)
verify(view).onImageValidationSuccess()
//Duplicate file name
uploadMediaPresenter.handleImageResult(FILE_NAME_EXISTS, uploadItem)
verify(view).showDuplicatePicturePopup(uploadItem)
//Empty Caption test
uploadMediaPresenter.handleImageResult(EMPTY_CAPTION, uploadItem)
fun emptyFileNameTest() {
uploadMediaPresenter.handleCaptionResult(EMPTY_CAPTION, uploadItem);
verify(view).showMessage(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())
}
// Bad Picture Test
uploadMediaPresenter.handleImageResult(-7, uploadItem)
verify(view)?.showBadImagePopup(ArgumentMatchers.anyInt(), ArgumentMatchers.eq(uploadItem))
/**
* Test for duplicate file name when the user presses the NEXT button
*/
@Test
fun duplicateFileNameTest() {
uploadMediaPresenter.handleCaptionResult(FILE_NAME_EXISTS, uploadItem)
verify(view).showDuplicatePicturePopup(uploadItem)
}
/**
* Test for correct file name when the user presses the NEXT button
*/
@Test
fun correctFileNameTest() {
uploadMediaPresenter.handleCaptionResult(IMAGE_OK, uploadItem)
verify(view).onImageValidationSuccess()
}
@Test
@ -218,34 +225,6 @@ class UploadMediaPresenterTest {
verify(view).updateMediaDetails(ArgumentMatchers.any())
}
/**
* Test bad image invalid location
*/
@Test
fun handleBadImageBaseTestInvalidLocation() {
uploadMediaPresenter.handleBadImage(8, uploadItem)
verify(view).showBadImagePopup(8, uploadItem)
}
/**
* Test bad image empty title
*/
@Test
fun handleBadImageBaseTestEmptyTitle() {
uploadMediaPresenter.handleBadImage(-3, uploadItem)
verify(view).showMessage(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())
}
/**
* Teste show file already exists
*/
@Test
fun handleBadImageBaseTestFileNameExists() {
uploadMediaPresenter.handleBadImage(64, uploadItem)
verify(view).showDuplicatePicturePopup(uploadItem)
}
/**
* Test show SimilarImageFragment
*/
@ -259,7 +238,8 @@ class UploadMediaPresenterTest {
@Test
fun setCorrectCountryCodeForReceivedImage() {
val germanyAsPlace = Place(null,null, null, null, LatLng(50.1, 10.2, 1.0f), null, null, null, true)
val germanyAsPlace =
Place(null, null, null, null, LatLng(50.1, 10.2, 1.0f), null, null, null, true)
germanyAsPlace.isMonument = true
whenever(
@ -269,7 +249,8 @@ class UploadMediaPresenterTest {
)
).thenReturn("Germany")
val item: Observable<UploadItem> = Observable.just(UploadItem(Uri.EMPTY, null, null, germanyAsPlace, 0, null, null, null))
val item: Observable<UploadItem> =
Observable.just(UploadItem(Uri.EMPTY, null, null, germanyAsPlace, 0, null, null, null))
whenever(
repository.preProcessImage(
@ -291,7 +272,5 @@ class UploadMediaPresenterTest {
)
assertEquals("Exptected contry code", "de", captor.value.countryCode);
verify(view).showProgress(false)
}
}

View file

@ -191,6 +191,15 @@ class UploadRepositoryUnitTest {
)
}
@Test
fun testGetCaptionQuality() {
assertEquals(
repository.getCaptionQuality(uploadItem),
uploadModel.getCaptionQuality(uploadItem)
)
}
@Test
fun testDeletePicture() {
assertEquals(repository.deletePicture(""), uploadModel.deletePicture(""))

View file

@ -321,18 +321,12 @@ class UploadMediaDetailFragmentUnitTest {
fragment.showDuplicatePicturePopup(uploadItem)
}
@Test
@Throws(Exception::class)
fun testShowBadImagePopup() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.showBadImagePopup(8, uploadItem)
}
@Test
@Throws(Exception::class)
fun testShowConnectionErrorPopup() {
fun testShowConnectionErrorPopupForCaptionCheck() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.showConnectionErrorPopup()
fragment.showConnectionErrorPopupForCaptionCheck()
}
@Test
@ -364,7 +358,7 @@ class UploadMediaDetailFragmentUnitTest {
`when`(latLng.longitude).thenReturn(0.0)
`when`(uploadItem.gpsCoords).thenReturn(imageCoordinates)
fragment.onActivityResult(1211, Activity.RESULT_OK, intent)
Mockito.verify(presenter, Mockito.times(0)).verifyImageQuality(0, location)
Mockito.verify(presenter, Mockito.times(0)).getImageQuality(0, location, activity)
}
@Test
@ -388,7 +382,7 @@ class UploadMediaDetailFragmentUnitTest {
`when`(latLng.longitude).thenReturn(0.0)
`when`(uploadItem.gpsCoords).thenReturn(imageCoordinates)
fragment.onActivityResult(1211, Activity.RESULT_OK, intent)
Mockito.verify(presenter, Mockito.times(1)).verifyImageQuality(0, null)
Mockito.verify(presenter, Mockito.times(1)).displayLocDialog(0, null)
}
@Test
@ -398,17 +392,6 @@ class UploadMediaDetailFragmentUnitTest {
fragment.updateMediaDetails(null)
}
@Test
@Throws(Exception::class)
fun testDeleteThisPicture() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = UploadMediaDetailFragment::class.java.getDeclaredMethod(
"deleteThisPicture"
)
method.isAccessible = true
method.invoke(fragment)
}
@Test
@Throws(Exception::class)
fun testOnDestroyView() {