diff --git a/geo/src/main/java/org/odk/collect/geo/geopoly/GeoPolyActivity.java b/geo/src/main/java/org/odk/collect/geo/geopoly/GeoPolyActivity.java index 306edbd0c66..7d35b1b83fa 100644 --- a/geo/src/main/java/org/odk/collect/geo/geopoly/GeoPolyActivity.java +++ b/geo/src/main/java/org/odk/collect/geo/geopoly/GeoPolyActivity.java @@ -91,11 +91,12 @@ public enum OutputMode { GEOTRACE, GEOSHAPE } private List originalPoly; private ImageButton zoomButton; - private ImageButton playButton; - private ImageButton clearButton; + ImageButton playButton; + ImageButton clearButton; private Button recordButton; private ImageButton pauseButton; - private ImageButton backspaceButton; + ImageButton backspaceButton; + ImageButton saveButton; private TextView locationStatus; private TextView collectionStatus; @@ -127,7 +128,7 @@ public enum OutputMode { GEOTRACE, GEOSHAPE } private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { - if (map != null && !originalPoly.equals(map.getPolyLinePoints(featureId))) { + if (!intentReadOnly && map != null && !originalPoly.equals(map.getPolyLinePoints(featureId))) { showBackDialog(); } else { finish(); @@ -225,7 +226,7 @@ public void initMap(MapFragment newMapFragment) { backspaceButton = findViewById(R.id.backspace); backspaceButton.setOnClickListener(v -> removeLastPoint()); - ImageButton saveButton = findViewById(R.id.save); + saveButton = findViewById(R.id.save); saveButton.setOnClickListener(v -> { if (!map.getPolyLinePoints(featureId).isEmpty()) { if (outputMode == OutputMode.GEOTRACE) { @@ -276,7 +277,7 @@ public void initMap(MapFragment newMapFragment) { if (restoredPoints != null) { points = restoredPoints; } - featureId = map.addPolyLine(new LineDescription(points, String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, true, outputMode == OutputMode.GEOSHAPE)); + featureId = map.addPolyLine(new LineDescription(points, String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, !intentReadOnly, outputMode == OutputMode.GEOSHAPE)); if (inputActive && !intentReadOnly) { startInput(); @@ -444,7 +445,7 @@ private void removeLastPoint() { private void clear() { map.clearFeatures(); - featureId = map.addPolyLine(new LineDescription(new ArrayList<>(), String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, true, outputMode == OutputMode.GEOSHAPE)); + featureId = map.addPolyLine(new LineDescription(new ArrayList<>(), String.valueOf(MapConsts.DEFAULT_STROKE_WIDTH), null, !intentReadOnly, outputMode == OutputMode.GEOSHAPE)); inputActive = false; updateUi(); } @@ -470,6 +471,7 @@ private void updateUi() { playButton.setEnabled(false); backspaceButton.setEnabled(false); clearButton.setEnabled(false); + saveButton.setEnabled(false); } // Settings dialog diff --git a/geo/src/test/java/org/odk/collect/geo/geopoly/GeoPolyActivityTest.java b/geo/src/test/java/org/odk/collect/geo/geopoly/GeoPolyActivityTest.java deleted file mode 100644 index 6db730f2d0c..00000000000 --- a/geo/src/test/java/org/odk/collect/geo/geopoly/GeoPolyActivityTest.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2018 Nafundi - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.odk.collect.geo.geopoly; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.isDialog; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.odk.collect.androidtest.ActivityScenarioExtensions.isFinishing; -import static org.robolectric.Shadows.shadowOf; - -import android.app.Application; -import android.content.Intent; - -import androidx.annotation.NonNull; -import androidx.lifecycle.Lifecycle; -import androidx.test.core.app.ActivityScenario; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.espresso.Espresso; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.odk.collect.androidtest.ActivityScenarioLauncherRule; -import org.odk.collect.geo.Constants; -import org.odk.collect.geo.DaggerGeoDependencyComponent; -import org.odk.collect.geo.GeoDependencyModule; -import org.odk.collect.geo.R; -import org.odk.collect.geo.ReferenceLayerSettingsNavigator; -import org.odk.collect.geo.support.FakeMapFragment; -import org.odk.collect.geo.support.RobolectricApplication; -import org.odk.collect.location.tracker.LocationTracker; -import org.odk.collect.maps.LineDescription; -import org.odk.collect.maps.MapFragmentFactory; -import org.odk.collect.maps.MapPoint; -import org.robolectric.shadows.ShadowApplication; - -import java.util.ArrayList; -import java.util.List; - -@RunWith(AndroidJUnit4.class) -public class GeoPolyActivityTest { - - private final FakeMapFragment mapFragment = new FakeMapFragment(); - private final LocationTracker locationTracker = mock(LocationTracker.class); - - @Rule - public ActivityScenarioLauncherRule launcherRule = new ActivityScenarioLauncherRule(); - - @Before - public void setUp() { - ShadowApplication shadowApplication = shadowOf(ApplicationProvider.getApplicationContext()); - shadowApplication.grantPermissions("android.permission.ACCESS_FINE_LOCATION"); - shadowApplication.grantPermissions("android.permission.ACCESS_COARSE_LOCATION"); - - RobolectricApplication application = ApplicationProvider.getApplicationContext(); - application.geoDependencyComponent = DaggerGeoDependencyComponent.builder() - .application(application) - .geoDependencyModule(new GeoDependencyModule() { - @NonNull - @Override - public MapFragmentFactory providesMapFragmentFactory() { - return () -> mapFragment; - } - - @NonNull - @Override - public ReferenceLayerSettingsNavigator providesReferenceLayerSettingsNavigator() { - return (activity) -> { - }; - } - - @NonNull - @Override - public LocationTracker providesLocationTracker(@NonNull Application application) { - return locationTracker; - } - }) - .build(); - } - - @Test - public void testLocationTrackerLifecycle() { - ActivityScenario scenario = launcherRule.launch(GeoPolyActivity.class); - mapFragment.ready(); - - // Stopping the activity should stop the location tracker - scenario.moveToState(Lifecycle.State.DESTROYED); - verify(locationTracker).stop(); - } - - @Test - public void recordButton_should_beHiddenForAutomaticMode() { - launcherRule.launch(GeoPolyActivity.class); - mapFragment.ready(); - - startInput(R.id.automatic_mode); - onView(withId(R.id.record_button)).check(matches(not(isDisplayed()))); - } - - @Test - public void recordButton_should_beVisibleForManualMode() { - launcherRule.launch(GeoPolyActivity.class); - mapFragment.ready(); - - startInput(R.id.manual_mode); - onView(withId(R.id.record_button)).check(matches(isDisplayed())); - } - - @Test - public void whenPolygonExtraPresent_showsPoly() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity.class); - - ArrayList polygon = new ArrayList<>(); - polygon.add(new MapPoint(1.0, 2.0, 3, 4)); - intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon); - launcherRule.launch(intent); - - mapFragment.ready(); - - List polys = mapFragment.getPolyLines(); - assertThat(polys.size(), equalTo(1)); - assertThat(polys.get(0).getPoints(), equalTo(polygon)); - } - - @Test - public void whenPolygonExtraPresent_andOutputModeIsShape_showsClosedPoly() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity.class); - - ArrayList polygon = new ArrayList<>(); - polygon.add(new MapPoint(1.0, 2.0, 3, 4)); - polygon.add(new MapPoint(2.0, 3.0, 3, 4)); - polygon.add(new MapPoint(1.0, 2.0, 3, 4)); - intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon); - intent.putExtra(GeoPolyActivity.OUTPUT_MODE_KEY, GeoPolyActivity.OutputMode.GEOSHAPE); - launcherRule.launch(intent); - - mapFragment.ready(); - - List polys = mapFragment.getPolyLines(); - assertThat(polys.size(), equalTo(1)); - - ArrayList expectedPolygon = new ArrayList<>(); - expectedPolygon.add(new MapPoint(1.0, 2.0, 3, 4)); - expectedPolygon.add(new MapPoint(2.0, 3.0, 3, 4)); - assertThat(polys.get(0).getPoints(), equalTo(expectedPolygon)); - assertThat(mapFragment.isPolyClosed(0), equalTo(true)); - } - - @Test - public void whenPolygonExtraPresent_andPolyIsEmpty_andOutputModeIsShape_doesNotShowPoly() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity.class); - - ArrayList polygon = new ArrayList<>(); - intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon); - intent.putExtra(GeoPolyActivity.OUTPUT_MODE_KEY, GeoPolyActivity.OutputMode.GEOSHAPE); - launcherRule.launch(intent); - - mapFragment.ready(); - - List polys = mapFragment.getPolyLines(); - assertThat(polys.size(), equalTo(1)); - assertThat(polys.get(0).getPoints().isEmpty(), equalTo(true)); - } - - @Test - public void whenPolygonExtraPresent_andPolyIsEmpty_pressingBack_finishes() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity.class); - - ArrayList polygon = new ArrayList<>(); - intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon); - intent.putExtra(GeoPolyActivity.OUTPUT_MODE_KEY, GeoPolyActivity.OutputMode.GEOSHAPE); - ActivityScenario scenario = launcherRule.launch(intent); - - mapFragment.ready(); - Espresso.pressBack(); - assertThat(isFinishing(scenario), equalTo(true)); - } - - @Test - public void startingInput_usingAutomaticMode_usesRetainMockAccuracyTrueToStartLocationTracker() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity.class); - - intent.putExtra(Constants.EXTRA_RETAIN_MOCK_ACCURACY, true); - launcherRule.launch(intent); - - mapFragment.ready(); - startInput(R.id.automatic_mode); - verify(locationTracker).start(true); - } - - @Test - public void startingInput_usingAutomaticMode_usesRetainMockAccuracyFalseToStartLocationTracker() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity.class); - - intent.putExtra(Constants.EXTRA_RETAIN_MOCK_ACCURACY, false); - launcherRule.launch(intent); - - mapFragment.ready(); - startInput(R.id.automatic_mode); - verify(locationTracker).start(false); - } - - @Test - public void recordingPointManually_whenPointIsADuplicateOfTheLastPoint_skipsPoint() { - launcherRule.launch(GeoPolyActivity.class); - mapFragment.ready(); - - startInput(R.id.manual_mode); - - mapFragment.setLocation(new MapPoint(1, 1)); - onView(withId(R.id.record_button)).perform(click()); - onView(withId(R.id.record_button)).perform(click()); - assertThat(mapFragment.getPolyLines().get(0).getPoints().size(), equalTo(1)); - } - - @Test - public void placingPoint_whenPointIsADuplicateOfTheLastPoint_skipsPoint() { - launcherRule.launch(GeoPolyActivity.class); - mapFragment.ready(); - - startInput(R.id.placement_mode); - - mapFragment.click(new MapPoint(1, 1)); - mapFragment.click(new MapPoint(1, 1)); - assertThat(mapFragment.getPolyLines().get(0).getPoints().size(), equalTo(1)); - } - - private void startInput(int mode) { - onView(withId(R.id.play)).perform(click()); - onView(withId(mode)).inRoot(isDialog()).perform(click()); - onView(withId(android.R.id.button1)).inRoot(isDialog()).perform(click()); - } -} diff --git a/geo/src/test/java/org/odk/collect/geo/geopoly/GeoPolyActivityTest.kt b/geo/src/test/java/org/odk/collect/geo/geopoly/GeoPolyActivityTest.kt new file mode 100644 index 00000000000..3eb3f707910 --- /dev/null +++ b/geo/src/test/java/org/odk/collect/geo/geopoly/GeoPolyActivityTest.kt @@ -0,0 +1,279 @@ +package org.odk.collect.geo.geopoly + +import android.app.Activity +import android.app.Application +import android.content.Intent +import androidx.fragment.app.FragmentActivity +import androidx.lifecycle.Lifecycle +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers.assertThat +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.not +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mockito +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify +import org.odk.collect.androidtest.ActivityScenarioExtensions.isFinishing +import org.odk.collect.androidtest.ActivityScenarioLauncherRule +import org.odk.collect.geo.Constants +import org.odk.collect.geo.DaggerGeoDependencyComponent +import org.odk.collect.geo.GeoDependencyModule +import org.odk.collect.geo.R +import org.odk.collect.geo.ReferenceLayerSettingsNavigator +import org.odk.collect.geo.support.FakeMapFragment +import org.odk.collect.geo.support.RobolectricApplication +import org.odk.collect.location.tracker.LocationTracker +import org.odk.collect.maps.MapFragment +import org.odk.collect.maps.MapFragmentFactory +import org.odk.collect.maps.MapPoint +import org.robolectric.Shadows + +@RunWith(AndroidJUnit4::class) +class GeoPolyActivityTest { + private val mapFragment = FakeMapFragment() + private val locationTracker = mock() + + @get:Rule + val launcherRule = ActivityScenarioLauncherRule() + + @Before + fun setUp() { + val shadowApplication = Shadows.shadowOf(ApplicationProvider.getApplicationContext()) + shadowApplication.grantPermissions("android.permission.ACCESS_FINE_LOCATION") + shadowApplication.grantPermissions("android.permission.ACCESS_COARSE_LOCATION") + val application = ApplicationProvider.getApplicationContext() + application.geoDependencyComponent = DaggerGeoDependencyComponent.builder() + .application(application) + .geoDependencyModule(object : GeoDependencyModule() { + override fun providesMapFragmentFactory(): MapFragmentFactory { + return object : MapFragmentFactory { + override fun createMapFragment(): MapFragment { + return mapFragment + } + } + } + + override fun providesReferenceLayerSettingsNavigator(): ReferenceLayerSettingsNavigator { + return object : ReferenceLayerSettingsNavigator { + override fun navigateToReferenceLayerSettings(activity: FragmentActivity) { + } + } + } + + override fun providesLocationTracker(application: Application): LocationTracker { + return locationTracker + } + }) + .build() + } + + @Test + fun testLocationTrackerLifecycle() { + val scenario = launcherRule.launch( + GeoPolyActivity::class.java + ) + mapFragment.ready() + + // Stopping the activity should stop the location tracker + scenario.moveToState(Lifecycle.State.DESTROYED) + Mockito.verify(locationTracker).stop() + } + + @Test + fun recordButton_should_beHiddenForAutomaticMode() { + launcherRule.launch(GeoPolyActivity::class.java) + mapFragment.ready() + startInput(R.id.automatic_mode) + onView(withId(R.id.record_button)).check(matches(not(isDisplayed()))) + } + + @Test + fun recordButton_should_beVisibleForManualMode() { + launcherRule.launch(GeoPolyActivity::class.java) + mapFragment.ready() + startInput(R.id.manual_mode) + onView(withId(R.id.record_button)).check(matches(isDisplayed())) + } + + @Test + fun whenPolygonExtraPresent_showsPoly() { + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + val polygon = ArrayList() + polygon.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon) + launcherRule.launch(intent) + mapFragment.ready() + val polys = mapFragment.getPolyLines() + assertThat(polys.size, equalTo(1)) + assertThat(polys[0].points, equalTo(polygon)) + } + + @Test + fun whenPolygonExtraPresent_andOutputModeIsShape_showsClosedPoly() { + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + val polygon = ArrayList() + polygon.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + polygon.add(MapPoint(2.0, 3.0, 3.0, 4.0)) + polygon.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon) + intent.putExtra(GeoPolyActivity.OUTPUT_MODE_KEY, GeoPolyActivity.OutputMode.GEOSHAPE) + launcherRule.launch(intent) + mapFragment.ready() + val polys = mapFragment.getPolyLines() + assertThat(polys.size, equalTo(1)) + val expectedPolygon = ArrayList() + expectedPolygon.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + expectedPolygon.add(MapPoint(2.0, 3.0, 3.0, 4.0)) + assertThat(polys[0].points, equalTo(expectedPolygon)) + assertThat(mapFragment.isPolyClosed(0), equalTo(true)) + } + + @Test + fun whenPolygonExtraPresent_andPolyIsEmpty_andOutputModeIsShape_doesNotShowPoly() { + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + val polygon = ArrayList() + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon) + intent.putExtra(GeoPolyActivity.OUTPUT_MODE_KEY, GeoPolyActivity.OutputMode.GEOSHAPE) + launcherRule.launch(intent) + mapFragment.ready() + val polys = mapFragment.getPolyLines() + assertThat(polys.size, equalTo(1)) + assertThat(polys[0].points.isEmpty(), equalTo(true)) + } + + @Test + fun whenPolygonExtraPresent_andPolyIsEmpty_pressingBack_finishes() { + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + val polygon = ArrayList() + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon) + intent.putExtra(GeoPolyActivity.OUTPUT_MODE_KEY, GeoPolyActivity.OutputMode.GEOSHAPE) + val scenario = launcherRule.launch(intent) + mapFragment.ready() + Espresso.pressBack() + assertThat(scenario.isFinishing, equalTo(true)) + } + + @Test + fun startingInput_usingAutomaticMode_usesRetainMockAccuracyTrueToStartLocationTracker() { + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + intent.putExtra(Constants.EXTRA_RETAIN_MOCK_ACCURACY, true) + launcherRule.launch(intent) + mapFragment.ready() + startInput(R.id.automatic_mode) + verify(locationTracker).start(true) + } + + @Test + fun startingInput_usingAutomaticMode_usesRetainMockAccuracyFalseToStartLocationTracker() { + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + intent.putExtra(Constants.EXTRA_RETAIN_MOCK_ACCURACY, false) + launcherRule.launch(intent) + mapFragment.ready() + startInput(R.id.automatic_mode) + verify(locationTracker).start(false) + } + + @Test + fun recordingPointManually_whenPointIsADuplicateOfTheLastPoint_skipsPoint() { + launcherRule.launch(GeoPolyActivity::class.java) + mapFragment.ready() + startInput(R.id.manual_mode) + mapFragment.setLocation(MapPoint(1.0, 1.0)) + onView(withId(R.id.record_button)).perform(click()) + onView(withId(R.id.record_button)).perform(click()) + assertThat(mapFragment.getPolyLines()[0].points.size, equalTo(1)) + } + + @Test + fun placingPoint_whenPointIsADuplicateOfTheLastPoint_skipsPoint() { + launcherRule.launch(GeoPolyActivity::class.java) + mapFragment.ready() + startInput(R.id.placement_mode) + mapFragment.click(MapPoint(1.0, 1.0)) + mapFragment.click(MapPoint(1.0, 1.0)) + assertThat(mapFragment.getPolyLines()[0].points.size, equalTo(1)) + } + + @Test + fun buttonsShouldBeEnabledInEditableMode() { + val polyline = ArrayList() + polyline.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polyline) + val scenario = launcherRule.launch(intent) + mapFragment.ready() + scenario.onActivity { activity: GeoPolyActivity -> + assertThat(activity.playButton.isEnabled, equalTo(true)) + assertThat(activity.backspaceButton.isEnabled, equalTo(true)) + assertThat(activity.clearButton.isEnabled, equalTo(true)) + assertThat(activity.saveButton.isEnabled, equalTo(true)) + } + } + + @Test + fun buttonsShouldBeDisabledInReadOnlyMode() { + val polygon = ArrayList() + polygon.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon) + intent.putExtra(Constants.EXTRA_READ_ONLY, true) + val scenario = launcherRule.launch(intent) + mapFragment.ready() + scenario.onActivity { activity: GeoPolyActivity -> + assertThat(activity.playButton.isEnabled, equalTo(false)) + assertThat(activity.backspaceButton.isEnabled, equalTo(false)) + assertThat(activity.clearButton.isEnabled, equalTo(false)) + assertThat(activity.saveButton.isEnabled, equalTo(false)) + } + } + + @Test + fun polyShouldBeDraggableInEditableMode() { + val polyline = ArrayList() + polyline.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polyline) + launcherRule.launch(intent) + mapFragment.ready() + assertThat(mapFragment.isPolyDraggable(0), equalTo(true)) + } + + @Test + fun polyShouldNotBeDraggableInReadOnlyMode() { + val polygon = ArrayList() + polygon.add(MapPoint(1.0, 2.0, 3.0, 4.0)) + val intent = + Intent(ApplicationProvider.getApplicationContext(), GeoPolyActivity::class.java) + intent.putExtra(GeoPolyActivity.EXTRA_POLYGON, polygon) + intent.putExtra(Constants.EXTRA_READ_ONLY, true) + launcherRule.launch(intent) + mapFragment.ready() + assertThat(mapFragment.isPolyDraggable(0), equalTo(false)) + } + + private fun startInput(mode: Int) { + onView(withId(R.id.play)).perform(click()) + onView(withId(mode)).inRoot(isDialog()).perform(click()) + onView(withId(android.R.id.button1)).inRoot(isDialog()).perform(click()) + } +}