package com.mauriciotogneri.greencoffee.interactions;

import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewAssertion;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.matcher.ViewMatchers;

import org.hamcrest.Matchers;

public class ActionableView
{
    private final ViewInteraction viewInteraction;

    public ActionableView(ViewInteraction viewInteraction)
    {
        this.viewInteraction = viewInteraction;
    }

    public ActionableView click()
    {
        return perform(ViewActions.click());
    }

    public ActionableView doubleClick()
    {
        return perform(ViewActions.doubleClick());
    }

    public ActionableView longClick()
    {
        return perform(ViewActions.longClick());
    }

    public ActionableView type(String text)
    {
        return perform(ViewActions.typeText(text));
    }

    public ActionableView clearText()
    {
        return perform(ViewActions.clearText());
    }

    public ActionableView scrollTo()
    {
        return perform(ViewActions.scrollTo());
    }

    public ActionableView swipeUp()
    {
        return perform(ViewActions.swipeUp());
    }

    public ActionableView swipeDown()
    {
        return perform(ViewActions.swipeDown());
    }

    public ActionableView swipeLeft()
    {
        return perform(ViewActions.swipeLeft());
    }

    public ActionableView swipeRight()
    {
        return perform(ViewActions.swipeRight());
    }

    public ActionableView doesNotExist()
    {
        return check(ViewAssertions.doesNotExist());
    }

    public ActionableView contains(Object text)
    {
        return check(ViewAssertions.matches(ViewMatchers.withText(text.toString())));
    }

    public ActionableView isEmpty()
    {
        return check(ViewAssertions.matches(ViewMatchers.withText("")));
    }

    public ActionableView isNotEmpty()
    {
        return check(ViewAssertions.matches(Matchers.not(ViewMatchers.withText(""))));
    }

    public ActionableView hasFocus()
    {
        return check(ViewAssertions.matches(ViewMatchers.hasFocus()));
    }

    public ActionableView doesNotHaveFocus()
    {
        return check(ViewAssertions.matches(Matchers.not(ViewMatchers.hasFocus())));
    }

    public ActionableView hasErrorText(Object text)
    {
        return check(ViewAssertions.matches(ViewMatchers.hasErrorText(text.toString())));
    }

    public ActionableView isChecked()
    {
        return check(ViewAssertions.matches(ViewMatchers.isChecked()));
    }

    public ActionableView isNotChecked()
    {
        return check(ViewAssertions.matches(ViewMatchers.isNotChecked()));
    }

    public ActionableView isClickable()
    {
        return check(ViewAssertions.matches(ViewMatchers.isClickable()));
    }

    public ActionableView isFocusable()
    {
        return check(ViewAssertions.matches(ViewMatchers.isFocusable()));
    }

    public ActionableView isNotFocusable()
    {
        return check(ViewAssertions.matches(Matchers.not(ViewMatchers.isFocusable())));
    }

    public ActionableView isEnabled()
    {
        return check(ViewAssertions.matches(ViewMatchers.isEnabled()));
    }

    public ActionableView isDisabled()
    {
        return check(ViewAssertions.matches(Matchers.not(ViewMatchers.isEnabled())));
    }

    public ActionableView isSelected()
    {
        return check(ViewAssertions.matches(ViewMatchers.isSelected()));
    }

    public ActionableView isNotSelected()
    {
        return check(ViewAssertions.matches(Matchers.not(ViewMatchers.isSelected())));
    }

    public ActionableView isDisplayed()
    {
        return check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    }

    public ActionableView isCompletelyDisplayed()
    {
        return check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()));
    }

    public ActionableView isNotDisplayed()
    {
        return check(ViewAssertions.matches(Matchers.not(ViewMatchers.isDisplayed())));
    }

    private ActionableView check(ViewAssertion viewAssertion)
    {
        return new ActionableView(viewInteraction.check(viewAssertion));
    }

    private ActionableView perform(ViewAction viewAction)
    {
        return new ActionableView(viewInteraction.perform(viewAction));
    }
}
@@ -372,22 +372,175 @@
 her.
-ViewMatchers;%0A
+BoundedMatcher;%0Aimport android.support.test.espresso.matcher.ViewMatchers;%0Aimport android.view.View;%0Aimport android.widget.ImageView;%0A%0Aimport org.hamcrest.Description;
 %0Aimp
@@ -4292,32 +4292,281 @@
 ed())));%0A    %7D%0A%0A
+    public ActionableView isHasDrawable()%0A    %7B%0A        return check(ViewAssertions.matches(hasDrawable()));%0A    %7D%0A%0A    public ActionableView isHasNotDrawable()%0A    %7B%0A        return check(ViewAssertions.matches(Matchers.not(hasDrawable())));%0A    %7D%0A%0A
     private Acti
@@ -4838,10 +4838,740 @@
 );%0A    %7D
+%0A%0A    //from here:https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IntentsAdvancedSample/app/src/androidTest/java/com/example/android/testing/espresso/intents/AdvancedSample/ImageViewHasDrawableMatcher.java%0A    public static BoundedMatcher%3CView, ImageView%3E hasDrawable()%0A    %7B%0A        return new BoundedMatcher%3CView, ImageView%3E(ImageView.class)%0A        %7B%0A            @Override%0A            public void describeTo(Description description)%0A            %7B%0A                description.appendText(%22has drawable%22);%0A            %7D%0A%0A            @Override%0A            public boolean matchesSafely(ImageView imageView)%0A            %7B%0A                return imageView.getDrawable() != null;%0A            %7D%0A        %7D;%0A    %7D
 %0A%7D

Add isHasDrawable, isHasNotDrawable