summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-03-05 12:03:56 +0100
committerTobrun <tobrun@mapbox.com>2019-03-06 14:22:43 +0100
commit500080ea6489bf7208859ed9bcfeefff16b301ad (patch)
tree3273b19e117aa29dc600a5bba587da60bfca45a6
parentbe75dc9a48764850ebb52e3bab7ae08b3370cd09 (diff)
downloadqtlocation-mapboxgl-500080ea6489bf7208859ed9bcfeefff16b301ad.tar.gz
[android] - fix dialog fragment setup, add regression test
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt33
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java28
2 files changed, 52 insertions, 9 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt
new file mode 100644
index 0000000000..418191e91a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt
@@ -0,0 +1,33 @@
+package com.mapbox.mapboxsdk.testapp.fragment
+
+import android.support.test.espresso.Espresso
+import android.support.test.espresso.Espresso.onView
+import android.support.test.espresso.action.ViewActions.click
+import android.support.test.espresso.matcher.ViewMatchers.withId
+import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
+import android.support.test.runner.AndroidJUnit4
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.action.WaitAction
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.MapInDialogActivity
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/**
+ * Regression test that validates that a map inside a DialogFragment can be opened and closed.
+ */
+@RunWith(AndroidJUnit4::class)
+@LargeTest
+class MapDialogFragmentTest {
+
+ @get:Rule
+ var activityRule: ActivityTestRule<MapInDialogActivity> = ActivityTestRule(MapInDialogActivity::class.java)
+
+ @Test
+ fun openCloseDialog() {
+ onView(withId(R.id.button_open_dialog)).perform(click())
+ onView(withId(R.id.mapView)).perform(WaitAction(2500))
+ Espresso.pressBack()
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
index 509b223d5f..c9a9377885 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
@@ -52,14 +52,13 @@ public class MapInDialogActivity extends AppCompatActivity {
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dialog_map, container);
}
@Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
-
mapView = view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.OUTDOORS));
@@ -75,6 +74,7 @@ public class MapInDialogActivity extends AppCompatActivity {
mapView.onPause();
mapView.onStop();
mapView.onDestroy();
+ mapView = null;
}
super.dismiss();
}
@@ -96,31 +96,41 @@ public class MapInDialogActivity extends AppCompatActivity {
@Override
public void onPause() {
super.onPause();
- mapView.onPause();
+ if (mapView != null) {
+ mapView.onPause();
+ }
}
@Override
public void onStop() {
super.onStop();
- mapView.onStop();
+ if (mapView != null) {
+ mapView.onStop();
+ }
}
@Override
public void onDestroyView() {
super.onDestroyView();
- mapView.onDestroy();
+ if (mapView != null) {
+ mapView.onDestroy();
+ }
}
@Override
public void onLowMemory() {
super.onLowMemory();
- mapView.onLowMemory();
+ if (mapView != null) {
+ mapView.onLowMemory();
+ }
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
+ if (mapView != null) {
+ mapView.onSaveInstanceState(outState);
+ }
}
}
-}
+} \ No newline at end of file