package org.msf.records.ui.patientlist;

import org.msf.records.R;
import org.msf.records.data.app.AppPatient;
import org.msf.records.ui.FunctionalTestCase;
import org.msf.records.ui.userlogin.UserLoginActivity;

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.action.ViewActions.click;
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.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.is;
import static org.msf.records.ui.matchers.StringMatchers.matchesRegex;

public class PatientListActivityTest extends FunctionalTestCase {

    public void setUp() throws Exception {
        super.setUp();
        onView(withText("Guest User")).perform(click());
        onView(withText("ALL PATIENTS")).perform(click());
    }

    /** Looks for the filter menu. */
    public void testFilterMenu() {
        onView(withText("All Patients")).perform(click());
        onView(withText("Triage")).check(matches(isDisplayed()));
        onView(withText("Pregnant")).check(matches(isDisplayed()));
    }

    /** Looks for a zone heading and at least one patient. */
    public void testZoneAndPatientDisplayed() {
        onView(withText(matchesRegex("(Triage|S1) \\((No|[0-9]+) patients?\\)")))
                .check(matches(isDisplayed()));

        // Click the first patient
        onData(is(AppPatient.class))
                .inAdapterView(withId(R.id.fragment_patient_list))
                .atPosition(0)
                .perform(click());
    }
}

@@ -1508,17 +1508,19 @@
 oks for 
-a
+two
  zone he
@@ -1524,16 +1524,17 @@
  heading
+s
  and at 
@@ -1599,24 +1599,83 @@
 splayed() %7B%0A
+        // There should be patients in both Triage and S1.%0A
         onVi
@@ -1704,19 +1704,136 @@
 ex(%22
-(
 Triage
-%7C
+ %5C%5C((No%7C%5B0-9%5D+) patients?%5C%5C)%22)))%0A                .check(matches(isDisplayed()));%0A%0A        onView(withText(matchesRegex(%22
 S1
-)
  %5C%5C(

Fix functional test.