Search in sources :

Example 6 with RecordingObserver

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

the class RxAdapterViewTest method itemClickEvents.

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

        @Override
        public void run() {
            listView.performItemClick(listView.getChildAt(2), 2, 2);
        }
    });
    AdapterViewItemClickEvent event = o.takeNext();
    assertEquals(listView, event.view());
    assertNotNull(event.clickedView());
    assertEquals(2, event.position());
    assertEquals(2, event.id());
    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)

Example 7 with RecordingObserver

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

the class RxSearchBarTest method searchQueryChangeEventsKeyboardDismissed.

@Test
@UiThreadTest
public void searchQueryChangeEventsKeyboardDismissed() {
    RecordingObserver<SearchBarSearchQueryEvent> o = new RecordingObserver<>();
    RxSearchBar.searchQueryChangeEvents(searchBar).subscribe(o);
    o.assertNoMoreEvents();
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
    searchBar.setSearchQuery("q");
    searchEditText.onKeyPreIme(KeyEvent.KEYCODE_BACK, keyEvent);
    assertEquals(SearchBarSearchQueryChangedEvent.create(searchBar, "q"), o.takeNext());
    assertEquals(SearchBarSearchQueryKeyboardDismissedEvent.create(searchBar, "q"), o.takeNext());
    o.dispose();
    searchEditText.onKeyPreIme(KeyEvent.KEYCODE_BACK, keyEvent);
    o.assertNoMoreEvents();
}
Also used : KeyEvent(android.view.KeyEvent) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 8 with RecordingObserver

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

the class RxSnackbarTest method dismisses.

@Test
public void dismisses() {
    final Snackbar view = Snackbar.make(parent, "Hey", LENGTH_SHORT);
    RecordingObserver<Integer> o = new RecordingObserver<>();
    RxSnackbar.dismisses(view).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    o.assertNoMoreEvents();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.show();
        }
    });
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            view.dismiss();
        }
    });
    assertEquals(DISMISS_EVENT_MANUAL, o.takeNext().intValue());
    instrumentation.runOnMainSync(new Runnable() {

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

        @Override
        public void run() {
            view.dismiss();
        }
    });
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Snackbar(android.support.design.widget.Snackbar) Test(org.junit.Test)

Example 9 with RecordingObserver

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

the class RxToolbarTest 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<>();
    RxToolbar.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 10 with RecordingObserver

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

the class RxViewTest method longClicks.

@Test
@UiThreadTest
public void longClicks() {
    // We need a parent because long presses delegate to the parent.
    LinearLayout parent = new LinearLayout(context) {

        @Override
        public boolean showContextMenuForChild(View originalView) {
            return true;
        }
    };
    parent.addView(view);
    RecordingObserver<Object> o = new RecordingObserver<>();
    RxView.longClicks(view).subscribe(o);
    // No initial value.
    o.assertNoMoreEvents();
    view.performLongClick();
    assertNotNull(o.takeNext());
    view.performLongClick();
    assertNotNull(o.takeNext());
    o.dispose();
    view.performLongClick();
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) View(android.view.View) LinearLayout(android.widget.LinearLayout) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

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