Lazy load view components in MapView. (#141)

* Lazy load view components in MapView.

* Fix failing tests.

* Fix style.

* Lazy inflating view components.

* Remove debug logging.

* Fix android ui tests.
This commit is contained in:
Peng Liu
2020-01-29 15:03:42 +02:00
committed by GitHub
parent a5477963ae
commit aea886e741
7 changed files with 281 additions and 146 deletions

View File

@@ -35,9 +35,11 @@ import static androidx.test.espresso.intent.matcher.IntentMatchers.hasData;
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 androidx.test.espresso.matcher.ViewMatchers.withTagValue;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assume.assumeTrue;
@@ -56,10 +58,10 @@ public class AttributionTest extends EspressoTest {
validateTestSetup();
// Default
onView(withId(R.id.attributionView)).check(matches(isDisplayed()));
onView(withTagValue(is("attrView"))).check(matches(isDisplayed()));
// Disabled
onView(withId(R.id.attributionView))
onView(withTagValue(is("attrView")))
.perform(new DisableAction(mapboxMap))
.check(matches(not(isDisplayed())));
}
@@ -73,7 +75,7 @@ public class AttributionTest extends EspressoTest {
}
// click on View to open dialog
onView(withId(R.id.attributionView)).perform(click());
onView(withTagValue(is("attrView"))).perform(click());
onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed()));
// test for trigger url intent
@@ -94,7 +96,7 @@ public class AttributionTest extends EspressoTest {
}
// click on View to open dialog
onView(withId(R.id.attributionView)).perform(click());
onView(withTagValue(is("attrView"))).perform(click());
onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed()));
// test for trigger url intent
@@ -115,7 +117,7 @@ public class AttributionTest extends EspressoTest {
}
// click on View to open dialog
onView(withId(R.id.attributionView)).perform(click());
onView(withTagValue(is("attrView"))).perform(click());
onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed()));
// test for trigger url intent
@@ -137,7 +139,7 @@ public class AttributionTest extends EspressoTest {
validateTestSetup();
// click on View to open dialog
onView(withId(R.id.attributionView)).perform(click());
onView(withTagValue(is("attrView"))).perform(click());
onView(withText(R.string.mapbox_attributionsDialogTitle)).inRoot(isDialog()).check(matches(isDisplayed()));
// click on item to open second dialog

View File

@@ -3,10 +3,10 @@ package com.mapbox.mapboxsdk.testapp.maps.widgets;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.WaitAction;
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
import org.junit.Ignore;
import org.junit.Test;
@@ -14,8 +14,9 @@ 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.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withTagValue;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
@@ -24,7 +25,7 @@ public class CompassViewTest extends EspressoTest {
@Test
public void testDefault() {
validateTestSetup();
onView(withId(R.id.compassView)).check(matches(not(isDisplayed())));
onView(withTagValue(is("compassView"))).check(matches(not(isDisplayed())));
}
@Test
@@ -41,7 +42,7 @@ public class CompassViewTest extends EspressoTest {
));
uiController.loopMainThreadForAtLeast(500);
});
onView(withId(R.id.compassView)).check(matches(isDisplayed()));
onView(withTagValue(is("compassView"))).check(matches(isDisplayed()));
}
@Test
@@ -55,9 +56,9 @@ public class CompassViewTest extends EspressoTest {
.target(new LatLng())
.build()
)));
onView(withId(R.id.compassView)).perform(click());
onView(withTagValue(is("compassView"))).perform(click());
WaitAction.invoke(500);
onView(withId(R.id.compassView)).check(matches(not(isDisplayed())));
onView(withTagValue(is("compassView"))).check(matches(not(isDisplayed())));
invoke(mapboxMap, (uiController, mapboxMap) -> {
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Camera bearing should face north, ", 0, cameraPosition.bearing, TestConstants.BEARING_DELTA);

View File

@@ -1,11 +1,11 @@
package com.mapbox.mapboxsdk.testapp.maps.widgets;
import android.view.View;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import android.view.View;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
import org.hamcrest.Matcher;
@@ -14,7 +14,8 @@ import org.junit.Test;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withTagValue;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
public class LogoTest extends EspressoTest {
@@ -22,16 +23,16 @@ public class LogoTest extends EspressoTest {
@Test
public void testDefault() {
validateTestSetup();
onView(withId(R.id.logoView)).check(matches(isDisplayed()));
onView(withTagValue(is("logoView"))).check(matches(isDisplayed()));
}
@Test
public void testDisabled() {
validateTestSetup();
onView(withId(R.id.logoView))
.perform(new DisableAction(mapboxMap))
.check(matches(not(isDisplayed())));
onView(withTagValue(is("logoView")))
.perform(new DisableAction(mapboxMap))
.check(matches(not(isDisplayed())));
}
private class DisableAction implements ViewAction {