diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/activity/waypoint')
7 files changed, 249 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java new file mode 100644 index 0000000..7be6150 --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java @@ -0,0 +1,12 @@ +package cgeo.geocaching.activity.waypoint; + +import cgeo.geocaching.EditWaypointActivity_; + +public abstract class AbstractAddWaypointActivityTest extends AbstractWaypointActivityTest { + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityIntent(new EditWaypointActivity_.IntentBuilder_(getInstrumentation().getContext()).geocode(getCache().getGeocode()).get()); + getActivity(); + } +} diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java new file mode 100644 index 0000000..bf8224a --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java @@ -0,0 +1,28 @@ +package cgeo.geocaching.activity.waypoint; + +import cgeo.geocaching.EditWaypointActivity_; +import cgeo.geocaching.Waypoint; +import cgeo.geocaching.enumerations.WaypointType; + +public abstract class AbstractEditWaypointActivityTest extends AbstractWaypointActivityTest { + private Waypoint waypoint; + + @Override + protected void setUp() throws Exception { + super.setUp(); + createWaypoint(); + getCache().addOrChangeWaypoint(waypoint, true); + final int waypointId = getCache().getWaypoints().get(0).getId(); + setActivityIntent(new EditWaypointActivity_.IntentBuilder_(getInstrumentation().getContext()).geocode(getCache().getGeocode()).waypointId(waypointId).get()); + getActivity(); + } + + private void createWaypoint() { + waypoint = new Waypoint("Test waypoint", WaypointType.PUZZLE, true); + waypoint.setNote("Test note"); + } + + protected final Waypoint getWaypoint() { + return waypoint; + } +} diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java new file mode 100644 index 0000000..36c4302 --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java @@ -0,0 +1,52 @@ +package cgeo.geocaching.activity.waypoint; + +import static org.assertj.core.api.Assertions.assertThat; + +import cgeo.geocaching.DataStore; +import cgeo.geocaching.EditWaypointActivity_; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.activity.AbstractEspressoTest; +import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags; +import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; + +import java.util.Collections; + +public abstract class AbstractWaypointActivityTest extends AbstractEspressoTest<EditWaypointActivity_> { + + private Geocache cache; + + public AbstractWaypointActivityTest() { + super(EditWaypointActivity_.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + cache = createTestCache(); + DataStore.saveCache(cache, Collections.singleton(SaveFlag.CACHE)); + } + + @Override + protected void tearDown() throws Exception { + removeTestCache(); + super.tearDown(); + } + + protected final Geocache getCache() { + return cache; + } + + private void removeTestCache() { + DataStore.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL); + assertThat(DataStore.loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB)).isNull(); + } + + @SuppressWarnings("static-method") + protected Geocache createTestCache() { + Geocache testCache = new Geocache(); + testCache.setGeocode("TEST"); + testCache.setType(CacheType.TRADITIONAL); + return testCache; + } +} diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java new file mode 100644 index 0000000..853054a --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java @@ -0,0 +1,62 @@ +package cgeo.geocaching.activity.waypoint; + +import cgeo.geocaching.R; +import cgeo.geocaching.enumerations.WaypointType; + +import com.google.android.apps.common.testing.ui.espresso.action.ViewActions; + +import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData; +import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; + +import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; + +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isClickable; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isNotChecked; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; + +import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click; + +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; + +public class AddWaypointActivityTest extends AbstractAddWaypointActivityTest { + + public static void testAddWayPointHasTypeSelection() { + onView(withId(R.id.type)).check(matches(isDisplayed())); + } + + public static void testDefaultWaypointTypeForTraditional() { + onView(withId(R.id.type)).check(matches(withChild(withText(WaypointType.WAYPOINT.getL10n())))); + onView(withId(R.id.name)).check(matches(withText(WaypointType.WAYPOINT.getL10n() + " 1"))); + } + + public static void testFieldsAreEmpty() { + onView(withId(R.id.note)).check(matches(withText(""))); + onView(withId(R.id.bearing)).check(matches(withText(""))); + onView(withId(R.id.distance)).check(matches(withText(""))); + } + + public static void testNewWaypointNotVisited() { + onView(withId(R.id.wpt_visited_checkbox)).check(matches(isNotChecked())); + } + + public static void testSwitchingWaypointTypeChangesWaypointName() { + WaypointType waypointType = WaypointType.FINAL; + + // verify we don't have a final type yet + onView(withId(R.id.name)).check(matches(not(withText(waypointType.getL10n())))); + + // open type selector + onView(withId(R.id.type)).perform(ViewActions.click()); + + // select final type + onData(hasToString(startsWith(waypointType.getL10n()))).inAdapterView(isClickable()).perform(click()); + + // verify changed name + onView(withId(R.id.name)).check(matches(withText(waypointType.getL10n()))); + } +} diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java new file mode 100644 index 0000000..c66c8de --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java @@ -0,0 +1,34 @@ +package cgeo.geocaching.activity.waypoint; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.WaypointType; + +import com.google.android.apps.common.testing.ui.espresso.ViewInteraction; + +import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; + +import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; + +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; + +public class AddWaypointMultiTest extends AbstractAddWaypointActivityTest { + + @Override + protected Geocache createTestCache() { + final Geocache cache = super.createTestCache(); + cache.setType(CacheType.MULTI); + return cache; + } + + public static void testMysteryDefaultWaypointFinal() { + final ViewInteraction waypointTypeSelector = onView(withId(R.id.type)); + waypointTypeSelector.check(matches(isDisplayed())); + waypointTypeSelector.check(matches(withChild(withText(WaypointType.STAGE.getL10n())))); + } + +} diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java new file mode 100644 index 0000000..810aa25 --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java @@ -0,0 +1,32 @@ +package cgeo.geocaching.activity.waypoint; + +import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; +import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.WaypointType; + +import com.google.android.apps.common.testing.ui.espresso.ViewInteraction; + +public class AddWaypointMysteryTest extends AbstractAddWaypointActivityTest { + + @Override + protected Geocache createTestCache() { + final Geocache cache = super.createTestCache(); + cache.setType(CacheType.MYSTERY); + return cache; + } + + public static void testMysteryDefaultWaypointFinal() { + final ViewInteraction waypointTypeSelector = onView(withId(R.id.type)); + waypointTypeSelector.check(matches(isDisplayed())); + waypointTypeSelector.check(matches(withChild(withText(WaypointType.FINAL.getL10n())))); + } + +} diff --git a/tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java new file mode 100644 index 0000000..d419555 --- /dev/null +++ b/tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java @@ -0,0 +1,29 @@ +package cgeo.geocaching.activity.waypoint; + +import cgeo.geocaching.R; + +import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; + +import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; + +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EditWaypointActivityTest extends AbstractEditWaypointActivityTest { + + public void testFieldsAreNotEmpty() { + String name = getWaypoint().getName(); + assertThat(name).isNotEmpty(); + onView(withId(R.id.name)).check(matches(withText(name))); + + final String note = getWaypoint().getNote(); + assertThat(note).isNotEmpty(); + onView(withId(R.id.note)).check(matches(withText(note))); + + onView(withId(R.id.type)).check(matches(withChild(withText(getWaypoint().getWaypointType().getL10n())))); + } + +} |
