package cgeo.geocaching.waypointactivity;

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.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 cgeo.geocaching.R;
import cgeo.geocaching.enumerations.WaypointType;

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()));
    }
}

@@ -36,16 +36,254 @@
 ivity;%0A%0A
+import cgeo.geocaching.R;%0Aimport cgeo.geocaching.enumerations.WaypointType;%0A%0Aimport com.google.android.apps.common.testing.ui.espresso.action.ViewActions;%0A%0Aimport static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;%0A
 import s
@@ -356,16 +356,17 @@
 onView;%0A
+%0A
 import s
@@ -455,16 +455,116 @@
 matches;
+%0A%0Aimport static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isClickable;
 %0Aimport 
@@ -1054,75 +1054,229 @@
 ort 
-cgeo.geocaching.R;%0Aimport cgeo.geocaching.enumerations.WaypointType
+static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;%0A%0Aimport static org.hamcrest.Matchers.hasToString;%0Aimport static org.hamcrest.Matchers.not;%0Aimport static org.hamcrest.Matchers.startsWith
 ;%0A%0Ap
@@ -2153,11 +2153,637 @@
 );%0A    %7D
+%0A%0A    public static void testSwitchingWaypointTypeChangesWaypointName() %7B%0A        WaypointType waypointType = WaypointType.FINAL;%0A%0A        // verify we don't have a final type yet%0A        onView(withId(R.id.name)).check(matches(not(withText(waypointType.getL10n()))));%0A%0A        // open type selector%0A        onView(withId(R.id.type)).perform(ViewActions.click());%0A%0A        // select final type%0A        onData(hasToString(startsWith(waypointType.getL10n()))).inAdapterView(isClickable()).perform(click());%0A%0A        // verify changed name%0A        onView(withId(R.id.name)).check(matches(withText(waypointType.getL10n())));%0A    %7D
 %0A%7D%0A

verify waypoint name change on type change