Pass unit tests

This commit is contained in:
savsch 2024-12-20 16:05:41 +05:30
parent b02fe08988
commit 5bdaafad56
4 changed files with 28 additions and 16 deletions

View file

@ -8,6 +8,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng; import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType; import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType;
import fr.free.nrw.commons.nearby.Label; import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.MarkerPlaceGroup;
import fr.free.nrw.commons.nearby.Place; import fr.free.nrw.commons.nearby.Place;
import java.util.List; import java.util.List;
@ -69,7 +70,7 @@ public interface NearbyParentFragmentContract {
Context getContext(); Context getContext();
void updateMapMarkers(List<BaseMarker> BaseMarkers); void replaceMarkerOverlays(List<MarkerPlaceGroup> markerPlaceGroups);
void filterOutAllMarkers(); void filterOutAllMarkers();

View file

@ -1709,13 +1709,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
} }
@Override
public void updateMapMarkers(final List<BaseMarker> BaseMarkers) {
if (binding.map != null) {
presenter.updateMapMarkersToController(BaseMarkers);
}
}
@Override @Override
public void filterOutAllMarkers() { public void filterOutAllMarkers() {
clearAllMarkers(); clearAllMarkers();
@ -1739,7 +1732,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
replaceMarkerOverlays(NearbyController.markerLabelList); replaceMarkerOverlays(NearbyController.markerLabelList);
return; return;
} }
ArrayList<MarkerPlaceGroup> placeGroupsToShow = new ArrayList<>(); final ArrayList<MarkerPlaceGroup> placeGroupsToShow = new ArrayList<>();
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) { for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
final Place place = markerPlaceGroup.getPlace(); final Place place = markerPlaceGroup.getPlace();
// When label filter is engaged // When label filter is engaged
@ -1891,6 +1884,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* @param markerPlaceGroups The list of marker place groups containing the places and * @param markerPlaceGroups The list of marker place groups containing the places and
* their bookmarked status * their bookmarked status
*/ */
@Override
public void replaceMarkerOverlays(final List<MarkerPlaceGroup> markerPlaceGroups) { public void replaceMarkerOverlays(final List<MarkerPlaceGroup> markerPlaceGroups) {
ArrayList<Marker> newMarkers = new ArrayList<>(markerPlaceGroups.size()); ArrayList<Marker> newMarkers = new ArrayList<>(markerPlaceGroups.size());
for (MarkerPlaceGroup markerPlaceGroup : markerPlaceGroups) { for (MarkerPlaceGroup markerPlaceGroup : markerPlaceGroups) {

View file

@ -162,9 +162,12 @@ class NearbyParentFragmentPresenter
/** /**
* Sets click listeners of FABs, and 2 bottom sheets * Sets click listeners of FABs, and 2 bottom sheets
*/ */
override fun setActionListeners(applicationKvStore: JsonKvStore) { override fun setActionListeners(applicationKvStore: JsonKvStore?) {
nearbyParentFragmentView.setFABPlusAction(View.OnClickListener { v: View? -> nearbyParentFragmentView.setFABPlusAction(View.OnClickListener { v: View? ->
if (applicationKvStore.getBoolean("login_skipped", false)) { if (applicationKvStore != null && applicationKvStore.getBoolean(
"login_skipped", false
)
) {
// prompt the user to login // prompt the user to login
nearbyParentFragmentView.displayLoginSkippedWarning() nearbyParentFragmentView.displayLoginSkippedWarning()
} else { } else {
@ -497,8 +500,15 @@ class NearbyParentFragmentPresenter
} }
} }
/**
* Sends the supplied markerPlaceGroups to `NearbyController` and nearby list fragment,
* and tells nearby parent fragment to filter the updated values to be rendered as overlays
* on the map
*
* @param markerPlaceGroups the new/updated list of places along with their bookmarked status
*/
@MainThread @MainThread
fun updatePlaceGroupsToControllerAndRender(markerPlaceGroups: List<MarkerPlaceGroup>) { private fun updatePlaceGroupsToControllerAndRender(markerPlaceGroups: List<MarkerPlaceGroup>) {
NearbyController.markerLabelList.clear() NearbyController.markerLabelList.clear()
NearbyController.markerLabelList.addAll(markerPlaceGroups) NearbyController.markerLabelList.addAll(markerPlaceGroups)
nearbyParentFragmentView.setFilterState() nearbyParentFragmentView.setFilterState()

View file

@ -31,6 +31,12 @@ class NearbyParentFragmentPresenterTest {
@Mock @Mock
internal lateinit var bookmarkLocationsDao: BookmarkLocationsDao internal lateinit var bookmarkLocationsDao: BookmarkLocationsDao
@Mock
internal lateinit var placesRepository: PlacesRepository
@Mock
internal lateinit var nearbyController: NearbyController
@Mock @Mock
internal lateinit var latestLocation: LatLng internal lateinit var latestLocation: LatLng
@ -52,7 +58,8 @@ class NearbyParentFragmentPresenterTest {
@Throws(Exception::class) @Throws(Exception::class)
fun setUp() { fun setUp() {
MockitoAnnotations.openMocks(this) MockitoAnnotations.openMocks(this)
nearbyPresenter = NearbyParentFragmentPresenter(bookmarkLocationsDao) nearbyPresenter =
NearbyParentFragmentPresenter(bookmarkLocationsDao, placesRepository, nearbyController)
nearbyPresenter.attachView(nearbyParentFragmentView) nearbyPresenter.attachView(nearbyParentFragmentView)
} }
@ -322,7 +329,7 @@ class NearbyParentFragmentPresenterTest {
@Test @Test
fun testSetActionListeners() { fun testSetActionListeners() {
nearbyPresenter.setActionListeners(any()) nearbyPresenter.setActionListeners(null)
verify(nearbyParentFragmentView).setFABPlusAction(any()) verify(nearbyParentFragmentView).setFABPlusAction(any())
verify(nearbyParentFragmentView).setFABRecenterAction(any()) verify(nearbyParentFragmentView).setFABRecenterAction(any())
} }
@ -454,11 +461,11 @@ class NearbyParentFragmentPresenterTest {
nearbyPlacesInfo.boundaryCoordinates = arrayOf() nearbyPlacesInfo.boundaryCoordinates = arrayOf()
nearbyPlacesInfo.currentLatLng = latestLocation nearbyPlacesInfo.currentLatLng = latestLocation
nearbyPlacesInfo.searchLatLng = latestLocation nearbyPlacesInfo.searchLatLng = latestLocation
nearbyPlacesInfo.placeList = null nearbyPlacesInfo.placeList = emptyList<Place>()
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList()) whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null) nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null)
Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any()) Mockito.verify(nearbyParentFragmentView).setFilterState()
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false) Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList) Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)
} }