Show user current location (#4825)

This commit is contained in:
Devarsh Mavani 2022-02-16 19:43:23 +05:30 committed by GitHub
parent 27e3f20ba2
commit 755b216507
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 4 deletions

View file

@ -28,6 +28,7 @@ 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
import fr.free.nrw.commons.location.LocationServiceManager
import fr.free.nrw.commons.ui.widget.HtmlTextView
import org.junit.Assert
import org.junit.Before
@ -66,6 +67,9 @@ class MediaDetailFragmentUnitTests {
private lateinit var view: View
private lateinit var context: Context
@Mock
private lateinit var locationManager: LocationServiceManager
@Mock
private lateinit var categoryEditSearchRecyclerViewAdapter: CategoryEditSearchRecyclerViewAdapter
@ -180,6 +184,7 @@ class MediaDetailFragmentUnitTests {
Whitebox.setInternalState(fragment, "categoryContainer", linearLayout)
Whitebox.setInternalState(fragment, "categorySearchView", searchView)
Whitebox.setInternalState(fragment, "mediaDiscussion", textView)
Whitebox.setInternalState(fragment, "locationManager", locationManager)
Whitebox.setInternalState(
fragment,
"categoryEditSearchRecyclerViewAdapter",
@ -239,11 +244,13 @@ class MediaDetailFragmentUnitTests {
@Test
@Throws(Exception::class)
fun testOnUpdateCoordinatesClicked() {
fun testOnUpdateCoordinatesClickedCurrentLocationNull() {
`when`(media.coordinates).thenReturn(null)
`when`(locationManager.lastLocation).thenReturn(null)
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
fragment.onUpdateCoordinatesClicked()
Mockito.verify(media, Mockito.times(1)).coordinates
Mockito.verify(locationManager, Mockito.times(1)).lastLocation
val shadowActivity: ShadowActivity = shadowOf(activity)
val startedIntent = shadowActivity.nextStartedActivity
val shadowIntent: ShadowIntent = shadowOf(startedIntent)
@ -263,6 +270,21 @@ class MediaDetailFragmentUnitTests {
Assert.assertEquals(shadowIntent.intentClass, LocationPickerActivity::class.java)
}
@Test
@Throws(Exception::class)
fun testOnUpdateCoordinatesClickedCurrentLocationNotNull() {
`when`(media.coordinates).thenReturn(null)
`when`(locationManager.lastLocation).thenReturn(LatLng(-0.000001, -0.999999, 0f))
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
fragment.onUpdateCoordinatesClicked()
Mockito.verify(locationManager, Mockito.times(3)).lastLocation
val shadowActivity: ShadowActivity = shadowOf(activity)
val startedIntent = shadowActivity.nextStartedActivity
val shadowIntent: ShadowIntent = shadowOf(startedIntent)
Assert.assertEquals(shadowIntent.intentClass, LocationPickerActivity::class.java)
}
@Test
@Throws(Exception::class)
fun testOnResume() {