mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Nearby: No longer keeps loading until timeout when map is zoomed out (#6070)
* Nearby: Search for actual map center * Add query syntax and methods * Nearby: Added binary search for loading pins * Add NearbyQueryParams and refactor * Add unit tests and complete implementation * Nearby: Increase max radius from 100km to 300km * Nearby: Centermost pins now appear on top * getNearbyItemCount: Added javadoc --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
c963cd9ea4
commit
369e79be5e
11 changed files with 303 additions and 37 deletions
|
|
@ -6,6 +6,7 @@ import com.nhaarman.mockitokotlin2.verify
|
|||
import fr.free.nrw.commons.explore.depictions.DepictsClient
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
|
||||
import fr.free.nrw.commons.nearby.model.NearbyQueryParams
|
||||
import okhttp3.Call
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
|
|
@ -14,6 +15,7 @@ import org.junit.Before
|
|||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.lang.Exception
|
||||
|
||||
|
|
@ -64,12 +66,16 @@ class OkHttpJsonApiClientTests {
|
|||
Mockito.`when`(response.message).thenReturn("test")
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyPlaces(latLng, "test", 10.0, "test")
|
||||
okHttpJsonApiClient.getNearbyPlaces(latLng, latLng, "test", true, "test")
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
verify(okhttpClient).newCall(any())
|
||||
verify(call).execute()
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyPlaces(NearbyQueryParams.Rectangular(latLng, latLng), "test", true, "test")
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
verify(okhttpClient, times(2)).newCall(any())
|
||||
verify(call, times(2)).execute()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -77,11 +83,48 @@ class OkHttpJsonApiClientTests {
|
|||
Mockito.`when`(response.message).thenReturn("test")
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyPlaces(latLng, "test", 10.0, null)
|
||||
okHttpJsonApiClient.getNearbyPlaces(latLng, latLng, "test", true, null)
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
verify(okhttpClient).newCall(any())
|
||||
verify(call).execute()
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyPlaces(
|
||||
NearbyQueryParams.Rectangular(latLng, latLng),
|
||||
"test",
|
||||
true,
|
||||
null
|
||||
)
|
||||
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyPlaces(
|
||||
NearbyQueryParams.Radial(latLng, 10f),
|
||||
"test",
|
||||
true,
|
||||
null
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
verify(okhttpClient, times(3)).newCall(any())
|
||||
verify(call, times(3)).execute()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetNearbyItemCount() {
|
||||
Mockito.`when`(response.message).thenReturn("test")
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyItemCount(NearbyQueryParams.Radial(latLng, 10f))
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
try {
|
||||
okHttpJsonApiClient.getNearbyItemCount(NearbyQueryParams.Rectangular(latLng, latLng))
|
||||
} catch (e: Exception) {
|
||||
assert(e.message.equals("test"))
|
||||
}
|
||||
verify(okhttpClient, times(2)).newCall(any())
|
||||
verify(call, times(2)).execute()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue