package com.designatednerd.wino.ui;

import android.support.annotation.IdRes;
import android.support.annotation.StringRes;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import org.hamcrest.Matcher;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.*;
import static android.support.test.espresso.matcher.ViewMatchers.*;
//import static android.support.test.espresso.contrib.RecyclerViewActions.*;
//
//import static android.support.test.espresso.Espresso.onView;
//import static android.support.test.espresso.action.ViewActions.*;
//import static android.support.test.espresso.assertion.ViewAssertions.matches;
//import static android.support.test.espresso.contrib.DrawerActions.openDrawer;
//import static android.support.test.espresso.contrib.DrawerMatchers.isClosed;
//import static android.support.test.espresso.matcher.ViewMatchers.*;
import static org.hamcrest.CoreMatchers.allOf;

public class EspressoHelpers {

    public static void enterTextIntoViewWithID(String aTextToEnter, @IdRes int aViewID) {
        onView(withId(aViewID)).perform(typeText(aTextToEnter));
    }

    public static void scrollToViewWithID(@IdRes int aViewIDRes) {
        onView(withId(aViewIDRes)).perform(scrollTo());
    }

    public static void tapViewWithText(String aText) {
        onView(withText(aText)).perform(click());
    }

    public static void tapViewWithText(@StringRes int aTextResID) {
        onView(withText(aTextResID)).perform(click());
    }

    public static void tapViewWithID(@IdRes int aViewResID) {
        onView(withId(aViewResID)).perform(click());
    }

    //TODO: FIX

//    public static Matcher<View> withRecyclerView(@IdRes int viewId) {
//        return allOf(isAssignableFrom(RecyclerView.class), withId(viewId));
//    }
//
//
//    //Modified from https://gist.github.com/tommyd3mdi/2622caecc1b2d498cd1a
//    public static ViewInteraction checkRecyclerViewHasItemWithTitle(@IdRes int aParentRecyclerViewID,
//                                                                    @IdRes int aRecyclerRowLayoutID,
//                                                     @IdRes int aRecyclerViewTextViewID,
//                                                    String title) {
//
//        onView(allOf(withParent(withRecyclerView(aParentRecyclerViewID)), //The view has a parent which is the recyclerview
//                withChild(allOf(withId(aRecyclerRowLayoutID),
//                        withChild())));
//
//        Matcher<View> matcher = withChild(allOf(withId(identifyingView), identifyingMatcher)))
//        withRecyclerView(aParentRecyclerViewID)
//        Matcher<View> on =
//
//                allOf(withParent(withId(aRecyclerRowID)), //Parent of the view is the full recyclerview
//                withId(aRecyclerViewTextViewID), //Has the given id and
//                withChild(allOf(withId(aRecyclerViewTextViewID), aChildIdentifyingMatcher))); //which has a child with the text view ID and matching the matcher.
//
//        return onView(outerSubview);
//    }
}

@@ -1015,16 +1015,254 @@
 pers %7B%0A%0A
+    /**************%0A     * TEXT ENTRY *%0A     **************/%0A%0A    public static void enterTextIntoViewWithHint(String aTextToEnter, @StringRes int aHintResID) %7B%0A        onView(withHint(aHintResID)).perform(typeText(aTextToEnter));%0A    %7D%0A%0A
     publ
@@ -1407,32 +1407,91 @@
 Enter));%0A    %7D%0A%0A
+    /*************%0A     * SCROLLING *%0A     *************/%0A%0A
     public stati
@@ -1596,32 +1596,85 @@
 llTo());%0A    %7D%0A%0A
+    /***********%0A     * TAPPING *%0A     ***********/%0A%0A
     public stati
@@ -2030,22 +2030,89 @@
    /
-/TODO: FIX%0A%0A//
+**********************%0A     * RECYCLERVIEW STUFF *%0A     **********************/%0A%0A
     
@@ -2177,18 +2177,16 @@
 ewId) %7B%0A
-//
         
@@ -2253,18 +2253,16 @@
 ewId));%0A
-//
     %7D%0A//

Clarify separation of methods in helper class, add new text-with-hint