Search in sources :

Example 11 with RecordingObserver

use of com.jakewharton.rxbinding4.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.rxbinding4.RecordingObserver) Menu(android.view.Menu) UiThreadTest(androidx.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 12 with RecordingObserver

use of com.jakewharton.rxbinding4.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.getView());
    assertEquals(1000, event.getScrollX());
    assertEquals(0, event.getScrollY());
    assertEquals(0, event.getOldScrollX());
    assertEquals(0, event.getOldScrollY());
    o.dispose();
    view.scrollTo(2000, 0);
    o.assertNoMoreEvents();
}
Also used : ViewScrollChangeEvent(com.jakewharton.rxbinding4.view.ViewScrollChangeEvent) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) UiThreadTest(androidx.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 13 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(new SearchBarSearchQueryChangedEvent(searchBar, "q"), o.takeNext());
    assertEquals(new SearchBarSearchQueryKeyboardDismissedEvent(searchBar, "q"), o.takeNext());
    o.dispose();
    searchEditText.onKeyPreIme(KeyEvent.KEYCODE_BACK, keyEvent);
    o.assertNoMoreEvents();
}
Also used : KeyEvent(android.view.KeyEvent) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) UiThreadTest(androidx.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 14 with RecordingObserver

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

the class RxSwipeDismissBehaviorTest method dismisses.

@Test
public void dismisses() {
    ((CoordinatorLayout.LayoutParams) view.getLayoutParams()).setBehavior(new SwipeDismissBehavior());
    RecordingObserver<View> o = new RecordingObserver<>();
    RxSwipeDismissBehavior.dismisses(view).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    // No initial value.
    o.assertNoMoreEvents();
    onView(withId(1)).perform(swipeRight());
    assertEquals(view, o.takeNext());
    o.dispose();
    onView(withId(1)).perform(swipeRight());
    o.assertNoMoreEvents();
}
Also used : SwipeDismissBehavior(com.google.android.material.behavior.SwipeDismissBehavior) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) Espresso.onView(androidx.test.espresso.Espresso.onView) View(android.view.View) Test(org.junit.Test)

Example 15 with RecordingObserver

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

the class RxTabLayoutTest method selectionEventsNoInitial.

@Test
@UiThreadTest
public void selectionEventsNoInitial() {
    TabLayout empty = new TabLayout(context);
    RecordingObserver<TabLayoutSelectionEvent> o = new RecordingObserver<>();
    RxTabLayout.selectionEvents(empty).subscribe(o);
    o.assertNoMoreEvents();
}
Also used : TabLayout(com.google.android.material.tabs.TabLayout) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) UiThreadTest(androidx.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(androidx.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