Search in sources :

Example 1 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxNestedScrollViewTest method scrollChangeEvents.

@Test
@UiThreadTest
public void scrollChangeEvents() {
    RecordingObserver<ViewScrollChangeEvent> o = new RecordingObserver<>();
    RxNestedScrollView.scrollChangeEvents(view).subscribe(o);
    o.assertNoMoreEvents();
    view.scrollTo(1000, 0);
    ViewScrollChangeEvent event = o.takeNext();
    assertSame(view, event.view());
    assertEquals(1000, event.scrollX());
    assertEquals(0, event.scrollY());
    assertEquals(0, event.oldScrollX());
    assertEquals(0, event.oldScrollY());
    o.dispose();
    view.scrollTo(2000, 0);
    o.assertNoMoreEvents();
}
Also used : ViewScrollChangeEvent(com.jakewharton.rxbinding2.view.ViewScrollChangeEvent) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 2 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxSlidingPaneLayoutTest method slides.

@Test
public void slides() {
    RecordingObserver<Float> o1 = new RecordingObserver<>();
    RxSlidingPaneLayout.panelSlides(view).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o1);
    o1.assertNoMoreEvents();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.openPane();
        }
    });
    instrumentation.waitForIdleSync();
    assertTrue(o1.takeNext() > 0f);
    o1.dispose();
    o1.assertNoMoreEvents();
    RecordingObserver<Float> o2 = new RecordingObserver<>();
    RxSlidingPaneLayout.panelSlides(view).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o2);
    o2.assertNoMoreEvents();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.closePane();
        }
    });
    instrumentation.waitForIdleSync();
    assertTrue(o2.takeNext() < 1f);
    o2.dispose();
    o2.assertNoMoreEvents();
}
Also used : UnsafeRunnable(com.jakewharton.rxbinding2.UnsafeRunnable) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test)

Example 3 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxViewTest method touches.

@Test
@UiThreadTest
public void touches() {
    RecordingObserver<MotionEvent> o = new RecordingObserver<>();
    RxView.touches(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchTouchEvent(motionEventAtPosition(view, ACTION_DOWN, 0, 50));
    MotionEvent event1 = o.takeNext();
    assertEquals(ACTION_DOWN, event1.getAction());
    view.dispatchTouchEvent(motionEventAtPosition(view, ACTION_MOVE, 1, 50));
    MotionEvent event2 = o.takeNext();
    assertEquals(ACTION_MOVE, event2.getAction());
    o.dispose();
    view.dispatchTouchEvent(motionEventAtPosition(view, ACTION_UP, 1, 50));
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) MotionEvent(android.view.MotionEvent) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 4 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxViewTest method hovers.

@Test
@UiThreadTest
public void hovers() {
    RecordingObserver<MotionEvent> o = new RecordingObserver<>();
    RxView.hovers(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_ENTER, 0, 50));
    MotionEvent event1 = o.takeNext();
    assertEquals(ACTION_HOVER_ENTER, event1.getAction());
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_MOVE, 1, 50));
    MotionEvent event2 = o.takeNext();
    assertEquals(ACTION_HOVER_MOVE, event2.getAction());
    o.dispose();
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_EXIT, 1, 50));
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) MotionEvent(android.view.MotionEvent) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 5 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxAdapterViewTest method itemClicks.

@Test
public void itemClicks() {
    RecordingObserver<Integer> o = new RecordingObserver<>();
    RxAdapterView.itemClicks(listView).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    o.assertNoMoreEvents();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            listView.performItemClick(listView.getChildAt(2), 2, 2);
        }
    });
    assertEquals(2, o.takeNext().intValue());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            listView.performItemClick(listView.getChildAt(0), 0, 0);
        }
    });
    assertEquals(0, o.takeNext().intValue());
    o.dispose();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            listView.performItemClick(listView.getChildAt(1), 1, 1);
        }
    });
    o.assertNoMoreEvents();
}
Also used : UnsafeRunnable(com.jakewharton.rxbinding2.UnsafeRunnable) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)41 RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)24 RecordingObserver (com.jakewharton.rxbinding4.RecordingObserver)17 UiThreadTest (android.support.test.annotation.UiThreadTest)15 UiThreadTest (androidx.test.annotation.UiThreadTest)15 Menu (android.view.Menu)10 MenuItem (android.view.MenuItem)10 UnsafeRunnable (com.jakewharton.rxbinding2.UnsafeRunnable)7 KeyEvent (android.view.KeyEvent)6 MotionEvent (android.view.MotionEvent)4 View (android.view.View)4 LinearLayout (android.widget.LinearLayout)4 TabLayout (android.support.design.widget.TabLayout)2 PopupMenu (android.widget.PopupMenu)2 TabLayout (com.google.android.material.tabs.TabLayout)2 Snackbar (android.support.design.widget.Snackbar)1 SwipeDismissBehavior (android.support.design.widget.SwipeDismissBehavior)1 Espresso.onView (android.support.test.espresso.Espresso.onView)1 PopupMenu (android.support.v7.widget.PopupMenu)1 PopupMenu (androidx.appcompat.widget.PopupMenu)1