package com.jakewharton.rxbinding.support.design.widget;

import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.SwipeDismissBehavior;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import com.jakewharton.rxbinding.RecordingObserver;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.google.common.truth.Truth.assertThat;

@RunWith(AndroidJUnit4.class)
public final class RxSwipeDismissBehaviorTest {
  @Rule public final ActivityTestRule<RxSwipeDismissBehaviorTestActivity> activityRule =
      new ActivityTestRule<>(RxSwipeDismissBehaviorTestActivity.class);

  private View view;

  @Before public void setUp() {
    RxSwipeDismissBehaviorTestActivity activity = activityRule.getActivity();
    view = activity.view;
  }

  @Ignore("https://github.com/JakeWharton/RxBinding/issues/263")
  @Test public void dismisses() {
    ((CoordinatorLayout.LayoutParams) view.getLayoutParams()).setBehavior(
        new SwipeDismissBehavior());

    RecordingObserver<View> o = new RecordingObserver<>();
    Subscription subscription = RxSwipeDismissBehavior.dismisses(view)
        .subscribeOn(AndroidSchedulers.mainThread())
        .subscribe(o);
    o.assertNoMoreEvents(); // No initial value.

    onView(withId(1)).perform(swipeRight());
    assertThat(o.takeNext()).isEqualTo(view);

    subscription.unsubscribe();

    onView(withId(1)).perform(swipeRight());
    o.assertNoMoreEvents();
  }

  private static ViewAction swipeRight() {
    return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.CENTER_LEFT,
        GeneralLocation.CENTER_RIGHT, Press.FINGER);
  }
}

@@ -650,33 +650,8 @@
 re;%0A
-import org.junit.Ignore;%0A
 impo
@@ -665,24 +665,24 @@
 junit.Rule;%0A
+
 import org.j
@@ -1396,73 +1396,8 @@
  %7D%0A%0A
-  @Ignore(%22https://github.com/JakeWharton/RxBinding/issues/263%22)%0A
   @T
@@ -2085,12 +2085,12 @@
 ipe.
-SLOW
+FAST
 , Ge

change swipe speed to FAST to fix flaky test