Search in sources :

Example 11 with RecordingObserver

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

the class RxActionMenuViewTest method itemClicks.

@Test
@UiThreadTest
public void itemClicks() {
    Menu menu = view.getMenu();
    MenuItem item1 = menu.add(0, 1, 0, "Hi");
    MenuItem item2 = menu.add(0, 2, 0, "Hey");
    RecordingObserver<MenuItem> o = new RecordingObserver<>();
    RxActionMenuView.itemClicks(view).subscribe(o);
    o.assertNoMoreEvents();
    menu.performIdentifierAction(2, 0);
    assertSame(item2, o.takeNext());
    menu.performIdentifierAction(1, 0);
    assertSame(item1, o.takeNext());
    o.dispose();
    menu.performIdentifierAction(2, 0);
    o.assertNoMoreEvents();
}
Also used : MenuItem(android.view.MenuItem) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 12 with RecordingObserver

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

the class RxPopupMenuTest method itemClicks.

@Test
@UiThreadTest
public void itemClicks() {
    Menu menu = view.getMenu();
    MenuItem item1 = menu.add(0, 1, 0, "Hi");
    MenuItem item2 = menu.add(0, 2, 0, "Hey");
    RecordingObserver<MenuItem> o = new RecordingObserver<>();
    RxPopupMenu.itemClicks(view).subscribe(o);
    o.assertNoMoreEvents();
    menu.performIdentifierAction(2, 0);
    assertSame(item2, o.takeNext());
    menu.performIdentifierAction(1, 0);
    assertSame(item1, o.takeNext());
    o.dispose();
    menu.performIdentifierAction(2, 0);
    o.assertNoMoreEvents();
}
Also used : MenuItem(android.view.MenuItem) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) PopupMenu(android.support.v7.widget.PopupMenu) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 13 with RecordingObserver

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

the class RxSearchEditTextTest method keyboardDismisses.

@Test
@UiThreadTest
public void keyboardDismisses() {
    RecordingObserver<Object> o = new RecordingObserver<>();
    RxSearchEditText.keyboardDismisses(view).subscribe(o);
    o.assertNoMoreEvents();
    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
    view.onKeyPreIme(KeyEvent.KEYCODE_BACK, event);
    assertNotNull(o.takeNext());
    o.dispose();
    view.onKeyPreIme(KeyEvent.KEYCODE_BACK, event);
    o.assertNoMoreEvents();
}
Also used : KeyEvent(android.view.KeyEvent) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 14 with RecordingObserver

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

the class RxDrawerLayoutTest method drawerOpen.

@Test
public void drawerOpen() {
    RecordingObserver<Boolean> o = new RecordingObserver<>();
    //
    RxDrawerLayout.drawerOpen(view, RIGHT).subscribeOn(//
    AndroidSchedulers.mainThread()).subscribe(o);
    assertFalse(o.takeNext());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.openDrawer(RIGHT);
        }
    });
    assertTrue(o.takeNext());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.closeDrawer(RIGHT);
        }
    });
    assertFalse(o.takeNext());
    o.dispose();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.openDrawer(RIGHT);
        }
    });
    o.assertNoMoreEvents();
}
Also used : UnsafeRunnable(com.jakewharton.rxbinding2.UnsafeRunnable) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test)

Example 15 with RecordingObserver

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

the class RxSlidingPaneLayoutTest method paneOpen.

@Test
public void paneOpen() {
    RecordingObserver<Boolean> o = new RecordingObserver<>();
    RxSlidingPaneLayout.panelOpens(view).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    assertFalse(o.takeNext());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.openPane();
        }
    });
    assertTrue(o.takeNext());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.closePane();
        }
    });
    assertFalse(o.takeNext());
    o.dispose();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.openPane();
        }
    });
    o.assertNoMoreEvents();
}
Also used : UnsafeRunnable(com.jakewharton.rxbinding2.UnsafeRunnable) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test)

Aggregations

RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)24 Test (org.junit.Test)24 UiThreadTest (android.support.test.annotation.UiThreadTest)15 UnsafeRunnable (com.jakewharton.rxbinding2.UnsafeRunnable)7 Menu (android.view.Menu)5 MenuItem (android.view.MenuItem)5 KeyEvent (android.view.KeyEvent)3 TabLayout (android.support.design.widget.TabLayout)2 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2 LinearLayout (android.widget.LinearLayout)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 (android.widget.PopupMenu)1 ViewScrollChangeEvent (com.jakewharton.rxbinding2.view.ViewScrollChangeEvent)1