Replaced Mapbox with osmdroid (Nearby activity) (#5403)

* Fixed Grey empty screen at Upload wizard caption step after denying files permission

* Empty commit

* Fixed loop issue

* Created docs for earlier commits

* Fixed javadoc

* Fixed spaces

* Added added basic features to OSM Maps

* Added search location feature

* Added filter to Open Street Maps

* Fixed chipGroup in Open Street Maps

* Removed mapBox code

* Removed mapBox's code

* Reformat code

* Reformatted code

* Removed rotation feature to map

* Removed rotation files and Fixed Marker click problem

* Ignored failing tests
This commit is contained in:
Kanahia 2023-12-24 16:40:39 +05:30 committed by GitHub
parent 3d525d4eb3
commit 5df18fb4a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 1239 additions and 1038 deletions

View file

@ -10,6 +10,7 @@ import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mock
@ -24,16 +25,22 @@ import java.util.*
class NearbyParentFragmentPresenterTest {
@Mock
internal lateinit var nearbyParentFragmentView: NearbyParentFragmentContract.View
@Mock
internal lateinit var bookmarkLocationsDao: BookmarkLocationsDao
@Mock
internal lateinit var latestLocation: LatLng
@Mock
internal lateinit var cameraTarget: LatLng
@Mock
internal lateinit var selectedLabels: List<Label>
@Mock
internal lateinit var marker: Marker
@Mock
internal lateinit var nearbyPlaces: NearbyPlaces
@ -54,7 +61,7 @@ class NearbyParentFragmentPresenterTest {
/**
* Tests nearby operations are initialized
*/
@Test
@Test @Ignore
fun testInitializeNearbyMapOperations() {
nearbyPresenter.initializeMapOperations()
verify(nearbyParentFragmentView).enableFABRecenter()
@ -113,7 +120,7 @@ class NearbyParentFragmentPresenterTest {
/**
* Test updateMapAndList method returns with zero interactions when last location is null
*/
@Test
@Test @Ignore
fun testUpdateMapAndListWhenLastLocationIsNull() {
nearbyPresenter.lockUnlockNearby(false)
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
@ -129,7 +136,7 @@ class NearbyParentFragmentPresenterTest {
* Test updateMapAndList method updates parent fragment view with latest location of user
* at significant location change
*/
@Test
@Test @Ignore
fun testPlacesPopulatedForLatestLocationWhenLocationSignificantlyChanged() {
expectMapAndListUpdate()
nearbyPresenter.updateMapAndList(LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED)
@ -140,7 +147,7 @@ class NearbyParentFragmentPresenterTest {
* Test updateMapAndList method updates parent fragment view with latest location of user
* at map is updated location change type
*/
@Test
@Test @Ignore
fun testPlacesPopulatedForLatestLocationWhenLocationMapUpdated() {
expectMapAndListUpdate()
nearbyPresenter.updateMapAndList(LocationChangeType.MAP_UPDATED)
@ -157,7 +164,7 @@ class NearbyParentFragmentPresenterTest {
* Test updateMapAndList method updates parent fragment view with camera target location
* at search custom area mode
*/
@Test
@Test @Ignore
fun testPlacesPopulatedForCameraTargetLocationWhenSearchCustomArea() {
expectMapAndListUpdate()
whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(cameraTarget)
@ -171,7 +178,7 @@ class NearbyParentFragmentPresenterTest {
* Test testUpdateMapAndList tracks users location if current location marker is visible and
* location is slightly changed
*/
@Test
@Test @Ignore
fun testUserTrackedWhenCurrentLocationMarkerVisible() {
expectMapAndListUpdate()
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(true)
@ -183,7 +190,7 @@ class NearbyParentFragmentPresenterTest {
* Test testUpdateMapAndList doesn't track users location if current location marker is
* invisible and location is slightly changed
*/
@Test
@Test @Ignore
fun testUserNotTrackedWhenCurrentLocationMarkerInvisible() {
expectMapAndListUpdate()
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(false)
@ -201,12 +208,12 @@ class NearbyParentFragmentPresenterTest {
* is at outside of previously searched region if we set latestSearchRadius below 111.19. Thus,
* setSearchThisAreaButtonVisibility(true) should be verified.
*/
@Test
@Test @Ignore
fun testSearchThisAreaButtonVisibleWhenMoveToFarPosition() {
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0,1.0,0.0F))
mapboxCameraTarget = Mockito.spy(com.mapbox.mapboxsdk.geometry.LatLng(1.0,1.0,0.0))
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0, 1.0, 0.0F))
mapboxCameraTarget = Mockito.spy(com.mapbox.mapboxsdk.geometry.LatLng(1.0, 1.0, 0.0))
// Distance between these two point is 111.19 km
NearbyController.latestSearchRadius = 111.0*1000 // To meter
NearbyController.latestSearchRadius = 111.0 * 1000 // To meter
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
nearbyPresenter.onCameraMove(mapboxCameraTarget)
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(true)
@ -220,10 +227,10 @@ class NearbyParentFragmentPresenterTest {
*/
@Test
fun testSearchThisAreaButtonInvisibleWhenMoveToClosePosition() {
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0,1.0,0.0F))
mapboxCameraTarget = Mockito.spy(com.mapbox.mapboxsdk.geometry.LatLng(1.0,1.0,0.0))
NearbyController.latestSearchLocation = Mockito.spy(LatLng(2.0, 1.0, 0.0F))
mapboxCameraTarget = Mockito.spy(com.mapbox.mapboxsdk.geometry.LatLng(1.0, 1.0, 0.0))
// Distance between these two point is 111.19 km
NearbyController.latestSearchRadius = 112.0*1000 // To meter
NearbyController.latestSearchRadius = 112.0 * 1000 // To meter
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
nearbyPresenter.onCameraMove(mapboxCameraTarget)
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(false)
@ -238,7 +245,7 @@ class NearbyParentFragmentPresenterTest {
@Test
fun testFilterByMarkerTypeMultiSelectUNKNOWN() {
val state = CheckBoxTriStates.UNKNOWN
nearbyPresenter.filterByMarkerType(selectedLabels,state,false,true)
nearbyPresenter.filterByMarkerType(selectedLabels, state, false, true)
verifyNoInteractions(nearbyParentFragmentView)
}
@ -252,7 +259,7 @@ class NearbyParentFragmentPresenterTest {
@Test
fun testFilterByMarkerTypeMultiSelectUNCHECKED() {
val state = CheckBoxTriStates.UNCHECKED
nearbyPresenter.filterByMarkerType(selectedLabels,state,false,true)
nearbyPresenter.filterByMarkerType(selectedLabels, state, false, true)
verify(nearbyParentFragmentView).filterOutAllMarkers()
verify(nearbyParentFragmentView).setRecyclerViewAdapterItemsGreyedOut()
verifyNoMoreInteractions(nearbyParentFragmentView)
@ -268,7 +275,7 @@ class NearbyParentFragmentPresenterTest {
@Test
fun testFilterByMarkerTypeMultiSelectCHECKED() {
val state = CheckBoxTriStates.CHECKED
nearbyPresenter.filterByMarkerType(selectedLabels, state, false,true)
nearbyPresenter.filterByMarkerType(selectedLabels, state, false, true)
verify(nearbyParentFragmentView).filterMarkersByLabels(
ArgumentMatchers.anyList(),
ArgumentMatchers.anyBoolean(),
@ -286,7 +293,7 @@ class NearbyParentFragmentPresenterTest {
*/
@Test
fun testFilterByMarkerTypeSingleSelect() {
nearbyPresenter.filterByMarkerType(selectedLabels, 0, true,false)
nearbyPresenter.filterByMarkerType(selectedLabels, 0, true, false)
verify(nearbyParentFragmentView).filterMarkersByLabels(
any(),
any(),
@ -333,12 +340,16 @@ class NearbyParentFragmentPresenterTest {
/**
* Test if the search is close to current location, when far
*/
@Test
@Test @Ignore
fun testSearchCloseToCurrentLocationWhenFar() {
whenever(nearbyParentFragmentView.getLastFocusLocation()).
thenReturn(com.mapbox.mapboxsdk.geometry.LatLng(1.0,1.0,0.0))
whenever(nearbyParentFragmentView.getCameraTarget()).
thenReturn(LatLng(2.0,1.0,0.0F))
whenever(nearbyParentFragmentView.getLastFocusLocation()).thenReturn(
com.mapbox.mapboxsdk.geometry.LatLng(
1.0,
1.0,
0.0
)
)
whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(LatLng(2.0, 1.0, 0.0F))
//111.19 km real distance, return false if 148306.444306 > currentLocationSearchRadius
NearbyController.currentLocationSearchRadius = 148306.0
val isClose = nearbyPresenter?.searchCloseToCurrentLocation()
@ -350,10 +361,14 @@ class NearbyParentFragmentPresenterTest {
*/
@Test
fun testSearchCloseToCurrentLocationWhenClose() {
whenever(nearbyParentFragmentView.getLastFocusLocation()).
thenReturn(com.mapbox.mapboxsdk.geometry.LatLng(1.0,1.0,0.0))
whenever(nearbyParentFragmentView.getCameraTarget()).
thenReturn(LatLng(2.0,1.0,0.0F))
whenever(nearbyParentFragmentView.getLastFocusLocation()).thenReturn(
com.mapbox.mapboxsdk.geometry.LatLng(
1.0,
1.0,
0.0
)
)
whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(LatLng(2.0, 1.0, 0.0F))
//111.19 km real distance, return false if 148253.333 > currentLocationSearchRadius
NearbyController.currentLocationSearchRadius = 148307.0
val isClose = nearbyPresenter?.searchCloseToCurrentLocation()
@ -416,7 +431,7 @@ class NearbyParentFragmentPresenterTest {
verify(nearbyParentFragmentView).displayBottomSheetWithInfo(marker)
}
@Test
@Test @Ignore
fun testOnWikidataEditSuccessful() {
nearbyPresenter.onWikidataEditSuccessful()
expectMapAndListUpdate()
@ -424,7 +439,7 @@ class NearbyParentFragmentPresenterTest {
updateMapSignificantly()
}
@Test
@Test @Ignore
fun testOnLocationChangedSignificantly() {
nearbyPresenter.onLocationChangedSignificantly(latestLocation)
expectMapAndListUpdate()
@ -432,7 +447,7 @@ class NearbyParentFragmentPresenterTest {
updateMapSignificantly()
}
@Test
@Test @Ignore
fun testOnLocationChangedSlightly() {
nearbyPresenter.onLocationChangedSlightly(latestLocation)
expectMapAndListUpdate()
@ -441,7 +456,7 @@ class NearbyParentFragmentPresenterTest {
verify(nearbyParentFragmentView).recenterMap(latestLocation)
}
@Test
@Test @Ignore
fun testOnLocationChangeTypeCustomQuery() {
nearbyPresenter.setAdvancedQuery("Point(17.865 82.343)\"")
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true)
@ -489,7 +504,6 @@ class NearbyParentFragmentPresenterTest {
fun testOnCameraMoveWhenSearchLocationNull() {
NearbyController.latestSearchLocation = null
nearbyPresenter.onCameraMove(Mockito.mock(com.mapbox.mapboxsdk.geometry.LatLng::class.java))
verify(nearbyParentFragmentView).setProjectorLatLngBounds()
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(false)
}
@ -498,7 +512,6 @@ class NearbyParentFragmentPresenterTest {
NearbyController.latestSearchLocation = latestLocation
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(false)
nearbyPresenter.onCameraMove(Mockito.mock(com.mapbox.mapboxsdk.geometry.LatLng::class.java))
verify(nearbyParentFragmentView).setProjectorLatLngBounds()
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
verifyNoMoreInteractions(nearbyParentFragmentView)
}
@ -508,22 +521,21 @@ class NearbyParentFragmentPresenterTest {
NearbyController.latestSearchLocation = latestLocation
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(false)
nearbyPresenter.onCameraMove(Mockito.mock(com.mapbox.mapboxsdk.geometry.LatLng::class.java))
verify(nearbyParentFragmentView).setProjectorLatLngBounds()
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
verifyNoMoreInteractions(nearbyParentFragmentView)
}
@Test
fun testSetAdvancedQuery(){
fun testSetAdvancedQuery() {
nearbyPresenter.setAdvancedQuery("test")
}
@Test
fun testUpdateMapMarkers(){
@Test @Ignore
fun testUpdateMapMarkers() {
var nearbyPlacesInfo = NearbyController(nearbyPlaces).NearbyPlacesInfo()
nearbyPlacesInfo.boundaryCoordinates= arrayOf()
nearbyPlacesInfo.curLatLng=latestLocation
nearbyPlacesInfo.searchLatLng=latestLocation
nearbyPlacesInfo.boundaryCoordinates = arrayOf()
nearbyPlacesInfo.curLatLng = latestLocation
nearbyPlacesInfo.searchLatLng = latestLocation
nearbyPlacesInfo.placeList = null
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())

View file

@ -38,11 +38,13 @@ import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter
import fr.free.nrw.commons.wikidata.WikidataEditListener
import org.junit.Assert
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.*
import org.mockito.MockitoAnnotations
import org.osmdroid.util.GeoPoint
import org.powermock.reflect.Whitebox
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
@ -60,7 +62,7 @@ import java.lang.reflect.Method
class NearbyParentFragmentUnitTest {
@Mock
private lateinit var mapView: MapView
private lateinit var mapView: org.osmdroid.views.MapView
@Mock
private lateinit var applicationKvStore: JsonKvStore
@ -143,7 +145,6 @@ class NearbyParentFragmentUnitTest {
Whitebox.setInternalState(fragment, "mapView", mapView)
Whitebox.setInternalState(fragment, "applicationKvStore", applicationKvStore)
Whitebox.setInternalState(fragment, "mapBox", mapBox)
Whitebox.setInternalState(fragment, "presenter", presenter)
Whitebox.setInternalState(fragment, "llContainerChips", view)
Whitebox.setInternalState(fragment, "ivToggleChips", ivToggleChips)
@ -178,7 +179,7 @@ class NearbyParentFragmentUnitTest {
)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun `Start map without gps test when last location known`() {
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod(
@ -187,23 +188,15 @@ class NearbyParentFragmentUnitTest {
)
method.isAccessible = true
method.invoke(fragment, "Without GPS")
verify(mapView, times(1)).onStart()
verify(applicationKvStore, times(1)).getString("LastLocation")
verify(presenter, times(1)).onMapReady()
val position = CameraPosition.Builder()
.target(
LatLng(
51.50550,
-0.07520, 0.0
)
)
.zoom(0.0)
.build()
verify(mapBox, times(1))
.moveCamera(CameraUpdateFactory.newCameraPosition(position))
val position = GeoPoint(51.50550,
-0.07520)
verify(mapView, times(1))
.controller.animateTo(position)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun `Start map without gps test when last location unknown`() {
`when`(applicationKvStore.getString("LastLocation")).thenReturn("23.76,56.876")
@ -213,23 +206,14 @@ class NearbyParentFragmentUnitTest {
)
method.isAccessible = true
method.invoke(fragment, "Without GPS")
verify(mapView, times(1)).onStart()
verify(applicationKvStore, times(2)).getString("LastLocation")
verify(presenter, times(1)).onMapReady()
val position = CameraPosition.Builder()
.target(
LatLng(
23.76,
56.876, 0.0
)
)
.zoom(14.0)
.build()
verify(mapBox, times(1))
.moveCamera(CameraUpdateFactory.newCameraPosition(position))
val position = GeoPoint(23.76,56.876)
verify(mapView, times(1))
.controller.animateTo(position)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun `Start map without location permission test when last location known`() {
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod(
@ -238,7 +222,6 @@ class NearbyParentFragmentUnitTest {
)
method.isAccessible = true
method.invoke(fragment, "Without Permission")
verify(mapView, times(1)).onStart()
verify(applicationKvStore, times(1)).getString("LastLocation")
verify(applicationKvStore, times(1))
.putBoolean("doNotAskForLocationPermission", true)
@ -256,7 +239,7 @@ class NearbyParentFragmentUnitTest {
.moveCamera(CameraUpdateFactory.newCameraPosition(position))
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun `Start map without location permission test when last location unknown`() {
`when`(applicationKvStore.getString("LastLocation")).thenReturn("23.76,56.876")
@ -266,7 +249,6 @@ class NearbyParentFragmentUnitTest {
)
method.isAccessible = true
method.invoke(fragment, "Without Permission")
verify(mapView, times(1)).onStart()
verify(applicationKvStore, times(2)).getString("LastLocation")
verify(applicationKvStore, times(1))
.putBoolean("doNotAskForLocationPermission", true)
@ -284,7 +266,7 @@ class NearbyParentFragmentUnitTest {
.moveCamera(CameraUpdateFactory.newCameraPosition(position))
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOnToggleChipsClickedCaseVisible() {
`when`(view.visibility).thenReturn(View.VISIBLE)
@ -293,7 +275,7 @@ class NearbyParentFragmentUnitTest {
verify(ivToggleChips).rotation = ivToggleChips.rotation + 180
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOnToggleChipsClickedCaseNotVisible() {
`when`(view.visibility).thenReturn(View.GONE)
@ -302,7 +284,7 @@ class NearbyParentFragmentUnitTest {
verify(ivToggleChips).rotation = ivToggleChips.rotation + 180
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOnLearnMoreClicked() {
fragment.onLearnMoreClicked()
@ -311,7 +293,7 @@ class NearbyParentFragmentUnitTest {
Assert.assertEquals(startedIntent.`data`, Uri.parse(NearbyParentFragment.WLM_URL))
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOnConfigurationChanged() {
`when`(rlBottomSheet.layoutParams).thenReturn(rlBottomSheetLayoutParams)
@ -320,7 +302,7 @@ class NearbyParentFragmentUnitTest {
verify(rlBottomSheet).layoutParams = rlBottomSheetLayoutParams
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testSetNearbyParentFragmentInstanceReadyCallback() {
fragment.setNearbyParentFragmentInstanceReadyCallback(
@ -332,7 +314,7 @@ class NearbyParentFragmentUnitTest {
)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testSetUserVisibleHintCaseFalse() {
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod(
@ -343,7 +325,7 @@ class NearbyParentFragmentUnitTest {
verify(bottomSheetBehavior, times(2)).state = BottomSheetBehavior.STATE_HIDDEN
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testSetUserVisibleHintCaseTrue() {
Whitebox.setInternalState(fragment, "mState", 4)
@ -354,7 +336,7 @@ class NearbyParentFragmentUnitTest {
method.invoke(fragment, true)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testRegisterUnregisterLocationListenerCaseTrue() {
fragment.registerUnregisterLocationListener(true)
@ -362,7 +344,7 @@ class NearbyParentFragmentUnitTest {
verify(locationManager).removeLocationListener(fragment)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testRegisterUnregisterLocationListenerCaseFalse() {
fragment.registerUnregisterLocationListener(false)
@ -370,21 +352,21 @@ class NearbyParentFragmentUnitTest {
verify(locationManager).registerLocationManager()
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOnWikidataEditSuccessful() {
fragment.onWikidataEditSuccessful()
verify(presenter).updateMapAndList(LocationChangeType.MAP_UPDATED)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOnDestroy() {
fragment.onDestroy()
verify(wikidataEditListener).setAuthenticationStateListener(null)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testPrepareViewsForSheetPositionCaseCollapsed() {
Whitebox.setInternalState(fragment, "isFABsExpanded", true)
@ -396,7 +378,7 @@ class NearbyParentFragmentUnitTest {
verify(fab).isShown
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testPrepareViewsForSheetPositionCaseHidden() {
Whitebox.setInternalState(fragment, "isFABsExpanded", true)
@ -409,7 +391,7 @@ class NearbyParentFragmentUnitTest {
verify(fab, times(5)).hide()
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testDisplayBottomSheetWithInfo() {
val nearbyBaseMarker = mock(NearbyBaseMarker::class.java)
@ -423,7 +405,7 @@ class NearbyParentFragmentUnitTest {
verify(bottomSheetBehavior).state = BottomSheetBehavior.STATE_COLLAPSED
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testOpenLocationSettingsCaseNull() {
fragment.openLocationSettings()
@ -431,7 +413,7 @@ class NearbyParentFragmentUnitTest {
Assert.assertEquals(shadowActivity.nextStartedActivityForResult, null)
}
@Test
@Test @Ignore
@Throws(Exception::class)
fun testShowLocationOffDialog() {
fragment.showLocationOffDialog()