diff --git a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt index f3bae2955..bf707d4a3 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt @@ -126,7 +126,6 @@ class MapActivityTest { 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)) - runOnUiThread { val searchArea = QuadrilateralArea(arrayListOf( LatLng(47.397026, 8.543067), //we consider the closest point to the drone @@ -134,16 +133,13 @@ class MapActivityTest { LatLng(47.398279, 8.543934), LatLng(47.397426, 8.544867) )) - mActivityRule.activity.missionBuilder + val mission = mActivityRule.activity.missionBuilder .withSearchArea(searchArea) .withStartingLocation(LatLng(47.397026, 8.543067)) - .withStrategy(SimpleQuadStrategy(Drone.GROUND_SENSOR_SCOPE)) + .withStrategy(SimpleQuadStrategy(Drone.GROUND_SENSOR_SCOPE)).build() + mActivityRule.activity.launchMission(mission) } - // Then start mission officially - runOnUiThread { - mActivityRule.activity.launchMission() - } val uploadedMission = Drone.missionLiveData.value assertThat(uploadedMission, `is`(notNullValue())) @@ -240,32 +236,6 @@ class MapActivityTest { HeatmapRepository.daoProvider = { OfflineHeatmapDao() } } - @Test - fun canUpdateUserLocation() { - //TODO Rewrite this test - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - } - - @Test - fun canUpdateUserLocationTwice() { - //TODO Rewrite this test - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - } - - @Test - fun canOnRequestPermissionResult() { - //TODO Rewrite this test - runOnUiThread { - MainDataManager.goOffline() - MainDataManager.groupId.value = DUMMY_GROUP_ID - MainDataManager.role.value = Role.OPERATOR - } - mActivityRule.launchActivity(Intent()) - - mActivityRule.activity.onRequestPermissionsResult(1011, Array(0) { "" }, IntArray(0)) - } - @Test fun droneStatusIsVisibleForOperator() { runOnUiThread { diff --git a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt index 6cb624072..e9dcf368b 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt @@ -31,8 +31,6 @@ import org.junit.runner.RunWith import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit - -//TODO extract toast tests (now commented) @RunWith(AndroidJUnit4::class) class OfflineManagerActivityTest { private lateinit var mUiDevice: UiDevice diff --git a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt index 5c4d9a0d8..1b2258165 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt @@ -23,6 +23,8 @@ import ch.epfl.sdp.database.repository.HeatmapRepository import ch.epfl.sdp.database.repository.MarkerRepository import ch.epfl.sdp.drone.DroneInstanceMock import ch.epfl.sdp.ui.maps.MapActivity +import ch.epfl.sdp.ui.maps.MapActivityTest +import com.mapbox.mapboxsdk.geometry.LatLng import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat import org.junit.Before @@ -102,4 +104,5 @@ class LocationWithPermissionTest { CentralLocationManager.onRequestPermissionsResult(1011, Array(0) { "" }, IntArray(0)) Mockito.verify(manager, Mockito.times(2)).requestLocationUpdates(Mockito.eq(LocationManager.GPS_PROVIDER), Mockito.eq(REFRESH_RATE), Mockito.eq(MIN_DIST), Mockito.any()) } + } diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt index c7340c919..f51fa5708 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt @@ -130,7 +130,6 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo super.initMapView(savedInstanceState, R.layout.activity_map, R.id.mapView) mapView.getMapAsync(this) - //TODO: Give user location if current drone position is not available CentralLocationManager.configure(this) mapView.contentDescription = getString(R.string.map_not_ready) @@ -302,10 +301,11 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo fun startOrPauseMissionButton(v: View) { if (Drone.isFlyingLiveData.value!!) { if (Drone.isMissionPausedLiveData.value!!) Drone.resumeMission() else Drone.pauseMission() - } else if (!searchAreaBuilder.isComplete()) { //TODO add missionBuilder isComplete method + } else if (!searchAreaBuilder.isComplete()) { Toast.makeText(this, getString(R.string.not_enough_waypoints_message), Toast.LENGTH_SHORT).show() } else { - launchMission() + val mission = missionBuilder.build() + launchMission(mission) } } @@ -314,10 +314,10 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo } @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - fun launchMission() { + fun launchMission(mission: List) { val altitude = PreferenceManager.getDefaultSharedPreferences(this) .getString(this.getString(R.string.pref_key_drone_altitude), Drone.DEFAULT_ALTITUDE.toString()).toString().toFloat() - Drone.startMission(DroneUtils.makeDroneMission(missionBuilder.build(), altitude), groupId.value!!) + Drone.startMission(DroneUtils.makeDroneMission(mission, altitude), groupId.value!!) searchAreaBuilder.reset() } diff --git a/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt b/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt index 2a63a6735..dc1983a54 100644 --- a/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt +++ b/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt @@ -2,8 +2,8 @@ package ch.epfl.sdp.mission import ch.epfl.sdp.searcharea.QuadrilateralArea import com.mapbox.mapboxsdk.geometry.LatLng +import net.mastrgamr.mbmapboxutils.SphericalUtil.computeOffset import org.hamcrest.CoreMatchers.equalTo -import net.mastrgamr.mbmapboxutils.SphericalUtil.* import org.hamcrest.MatcherAssert.assertThat import org.junit.Test import java.lang.Double.max @@ -76,5 +76,21 @@ class SimpleQuadStrategyTest { assertThat("Wanted $theoryRes, but got: $res", diff < 0.01) } - //TODO test that starting location is taken into account. + @Test + fun missionStartsWithClosestPoint() { + val waypoints = arrayListOf( + LatLng(47.397026, 8.543067), //we consider the closest point to the drone + LatLng(47.398979, 8.543434), + LatLng(47.398279, 8.543934), + LatLng(47.397426, 8.544867) + ) + + val searchArea = QuadrilateralArea(waypoints + ) + val dronePos = LatLng(47.4, 8.6) + val strategy = SimpleQuadStrategy(20.0) + val path = strategy.createFlightPath(dronePos, searchArea) + val orderedSearchArea = waypoints.sortedBy { it.distanceTo(dronePos) } + assertThat(path[0], equalTo(orderedSearchArea[0])) + } } \ No newline at end of file