Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #213 from Ph0tonic/feature/mapManagingImplementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0tonic authored Jun 5, 2020
2 parents 03acef2 + 9a0d290 commit cbe3539
Show file tree
Hide file tree
Showing 48 changed files with 963 additions and 481 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.1'
implementation "androidx.core:core-ktx:1.3.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta6'
implementation "androidx.room:room-ktx:2.2.5"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'org.videolan.android:libvlc-all:3.1.12'
implementation 'com.google.firebase:firebase-analytics:17.4.2'
implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-database-ktx:19.3.0'
implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'io.mavsdk:mavsdk:0.3.1'
implementation 'io.mavsdk:mavsdk-server:0.3.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.0'
Expand All @@ -87,8 +89,6 @@ dependencies {
implementation 'com.mikhaellopez:circularimageview:4.2.0'
implementation 'com.github.mastrgamr:mapbox-android-utils:v0.3'
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta6'
implementation "androidx.room:room-ktx:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
testImplementation 'junit:junit:4.13'
debugImplementation 'androidx.fragment:fragment-testing:1.2.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ReturnDroneDialogFragmentTest {
ReturnDroneDialogFragment().show(mActivityRule.activity.supportFragmentManager, mActivityRule.activity.getString(R.string.return_drone_dialog))

onView(withText(applicationContext()
.getString(R.string.dialog_cancel)))
.getString(R.string.cancel)))
.perform(click())

onView(withText(applicationContext().getString(R.string.return_drone_dialog_title)))
Expand Down
19 changes: 0 additions & 19 deletions app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -427,25 +427,6 @@ class MapActivityTest {
}
}

@Test
fun storeMapButtonIsWorking() {
runOnUiThread {
MainDataManager.goOffline()
MainDataManager.groupId.value = DUMMY_GROUP_ID
MainDataManager.role.value = Role.OPERATOR
}
mActivityRule.launchActivity(Intent())

mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT)
assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true))

onView(withId(R.id.floating_menu_button)).perform(click())
onView(withId(R.id.store_button)).perform(click())
onView(withId(R.id.store_button)).perform(click())

intended(hasComponent(OfflineManagerActivity::class.java.name))
}

@Test
fun loosingDroneConnectionShowsToast() {
runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.mapbox.mapboxsdk.offline.OfflineManager
import com.mapbox.mapboxsdk.offline.OfflineRegion
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matchers.closeTo
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -39,15 +38,12 @@ class OfflineManagerActivityTest {
companion object {
private const val ZOOM_VALUE = 15.0

private const val FAKE_MAP_NAME_1 = "RandomName"
private const val FAKE_MAP_NAME_2 = "SEA"
private const val FAKE_MAP_NAME = "Random_Name"
private val FAKE_MAP_LOCATION = LatLng(14.0, 12.0)

private const val MAP_LOADING_TIMEOUT = 30000L
private const val EPSILON = 1e-0
private const val POSITIVE_BUTTON_ID: Int = android.R.id.button1
private const val NEGATIVE_BUTTON_ID: Int = android.R.id.button2
private const val NEUTRAL_BUTTON_ID: Int = android.R.id.button3

private const val ASYNC_CALL_TIMEOUT = 5L
}
Expand Down Expand Up @@ -76,51 +72,44 @@ class OfflineManagerActivityTest {
}

@Test
fun checkToastWhenNoMapsHaveBeenDownloaded() {
onView(withId(R.id.list_button)).perform(click())
onView(withText(applicationContext().getString(R.string.toast_no_regions_yet)))
.inRoot(withDecorView(not(mActivityRule.activity.window.decorView)))
.check(matches(isDisplayed()))
}

/**
* this also tests that Toast are shown
*/
@Test
fun canDownloadAndThenDeleteMap() {
//check that the downloaded list map is empty
fun canDownloadMap() {
//Check that the downloaded list map is empty
val checkedIfEmpty = CountDownLatch(1)
offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>) {
assertThat(offlineRegions.isEmpty(), equalTo(true))
val emptiedLatch = CountDownLatch(offlineRegions.size)
offlineRegions.forEach {
it.delete(object : OfflineRegion.OfflineRegionDeleteCallback {
override fun onDelete() {
emptiedLatch.countDown()
}

override fun onError(error: String?) {}
})
}
emptiedLatch.await(ASYNC_CALL_TIMEOUT, TimeUnit.SECONDS)
assertThat(emptiedLatch.count, equalTo(0L))

checkedIfEmpty.countDown()
}

override fun onError(error: String) {} //left intentionally empty
})
checkedIfEmpty.await(ASYNC_CALL_TIMEOUT, TimeUnit.SECONDS)
checkedIfEmpty.await(ASYNC_CALL_TIMEOUT * 2, TimeUnit.SECONDS)
assertThat(checkedIfEmpty.count, equalTo(0L))


//DOWNLOAD part
onView(withId(R.id.download_button)).perform(click())
onView(withId(R.id.dialog_textfield_id)).perform(typeText(FAKE_MAP_NAME_1))
onView(withId(R.id.dialog_textfield_id)).perform(typeText(FAKE_MAP_NAME))
mUiDevice.pressBack()

onView(withId(POSITIVE_BUTTON_ID)).perform(click())

mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT * 30)
assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true))

// onView(withText(applicationContext().getString(R.string.end_progress_success)))
// .inRoot(withDecorView(not(mActivityRule.activity.window.decorView)))
// .check(matches(isDisplayed()))

val calledList = CountDownLatch(1)
offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>) {
//check that the region has been downloaded
assertThat(getRegionName(offlineRegions[0]), equalTo(FAKE_MAP_NAME_1))
assertThat(getRegionName(offlineRegions[0]), equalTo(FAKE_MAP_NAME))
calledList.countDown()
}

Expand All @@ -130,116 +119,19 @@ class OfflineManagerActivityTest {
calledList.await(ASYNC_CALL_TIMEOUT, TimeUnit.SECONDS)
assertThat(calledList.count, equalTo(0L))

onView(withId(R.id.list_button)).perform(click())
onView(withId(NEGATIVE_BUTTON_ID)).perform(click())

//DELETE PART
onView(withId(R.id.list_button)).perform(click())
onView(withId(NEUTRAL_BUTTON_ID)).perform(click())
// onView(withText(applicationContext().getString(R.string.toast_region_deleted)))
// .inRoot(withDecorView(not(mActivityRule.activity.window.decorView)))
// .check(matches(isDisplayed()))
mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT)
assertThat(mActivityRule.activity.mapView.contentDescription.toString(), equalTo(applicationContext().getString(R.string.map_ready)))

//check that the downloaded list map is empty
val calledDelete = CountDownLatch(1)
offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>) {
assert(offlineRegions.isEmpty())
calledDelete.countDown()
}

override fun onError(error: String) {} //left intentionally empty
})
calledDelete.await(ASYNC_CALL_TIMEOUT, TimeUnit.SECONDS)
assertThat(calledDelete.count, equalTo(0L))
}

/**
* We move the camera over CMA
* Download CMA map
* Then we move the camera somewhere random on the globe
* And finally we try to navigate back to CMA
*
* this also tests that Toast are shown
*/
@Test
fun canNavigateToDownloadedMap() {
val randomLocation = LatLng((-90..90).random().toDouble(), (-180..180).random().toDouble())

moveCameraToPosition(FAKE_MAP_LOCATION)

//check that the downloaded list map is empty
offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>) {
assert(offlineRegions.isEmpty())
}

override fun onError(error: String) {} //left intentionally empty
})

mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT * 15)
assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true))

//DOWNLOAD Part
onView(withId(R.id.download_button)).perform(click())
onView(withId(R.id.dialog_textfield_id)).perform(typeText(FAKE_MAP_NAME_2))
mUiDevice.pressBack()

onView(withId(POSITIVE_BUTTON_ID)).perform(click())

mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT * 15)
assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true))

onView(withText(applicationContext().getString(R.string.end_progress_success)))
.inRoot(withDecorView(not(mActivityRule.activity.window.decorView)))
.check(matches(isDisplayed()))

offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>) {
//check that the region has been downloaded
assertThat(getRegionName(offlineRegions[0]), equalTo(FAKE_MAP_NAME_2))
}

override fun onError(error: String) {} //left intentionally empty
})

moveCameraToPosition(randomLocation)

//NAVIGATE Part
onView(withId(R.id.list_button)).perform(click())
onView(withId(POSITIVE_BUTTON_ID)).perform(click())
onView(withText(FAKE_MAP_NAME_2))
.inRoot(withDecorView(not(mActivityRule.activity.window.decorView)))
.check(matches(isDisplayed()))

mActivityRule.activity.mapView.getMapAsync { mapboxMap ->
assertThat(mapboxMap.cameraPosition.target.distanceTo(FAKE_MAP_LOCATION), closeTo(0.0, EPSILON))
}

//DELETE PART
onView(withId(R.id.list_button)).perform(click())
onView(withId(NEUTRAL_BUTTON_ID)).perform(click())
mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT)
assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true))

onView(withText(applicationContext().getString(R.string.toast_region_deleted)))
.inRoot(withDecorView(not(mActivityRule.activity.window.decorView)))
.check(matches(isDisplayed()))

//check that the downloaded list map is empty
val called = CountDownLatch(1)
offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<OfflineRegion>) {
assertThat(offlineRegions.isEmpty(), equalTo(true))
called.countDown()
offlineRegions.forEach { it ->
it.delete(object : OfflineRegion.OfflineRegionDeleteCallback {
override fun onDelete() {}
override fun onError(error: String?) {}
})
}
}

override fun onError(error: String) {} //left intentionally empty
override fun onError(error: String?) {}
})
called.await(ASYNC_CALL_TIMEOUT, TimeUnit.SECONDS)
assertThat(called.count, equalTo(0L))
}

@Test
Expand Down
Loading

0 comments on commit cbe3539

Please sign in to comment.