Search in sources :

Example 36 with RecordingObserver

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

the class RxTabLayoutTest method selectionsNoInitial.

@Test
@UiThreadTest
public void selectionsNoInitial() {
    TabLayout empty = new TabLayout(context);
    RecordingObserver<TabLayout.Tab> o = new RecordingObserver<>();
    RxTabLayout.selections(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)

Example 37 with RecordingObserver

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

the class RxViewTest method focusChanges.

@Test
@UiThreadTest
public void focusChanges() {
    // We need a parent which can take focus from our view when it attempts to clear.
    LinearLayout parent = new LinearLayout(context);
    parent.setFocusable(true);
    parent.addView(view);
    view.setFocusable(true);
    RecordingObserver<Boolean> o = new RecordingObserver<>();
    RxView.focusChanges(view).subscribe(o);
    assertFalse(o.takeNext());
    view.requestFocus();
    assertTrue(o.takeNext());
    view.clearFocus();
    assertFalse(o.takeNext());
    o.dispose();
    view.requestFocus();
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 38 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.rxbinding4.RecordingObserver) MotionEvent(android.view.MotionEvent) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 39 with RecordingObserver

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

the class RxViewTest method keys.

@Test
@UiThreadTest
public void keys() {
    RecordingObserver<KeyEvent> o = new RecordingObserver<>();
    RxView.keys(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_R));
    KeyEvent event1 = o.takeNext();
    assertEquals(KeyEvent.ACTION_DOWN, event1.getAction());
    view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_H));
    KeyEvent event2 = o.takeNext();
    assertEquals(KeyEvent.KEYCODE_H, event2.getKeyCode());
    o.dispose();
    view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_S));
    o.assertNoMoreEvents();
}
Also used : KeyEvent(android.view.KeyEvent) RecordingObserver(com.jakewharton.rxbinding4.RecordingObserver) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 40 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<>();
    com.jakewharton.rxbinding4.appcompat.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.rxbinding4.RecordingObserver) PopupMenu(androidx.appcompat.widget.PopupMenu) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) 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