androidx.test.espresso.action.GeneralLocation Java Examples

The following examples show how to use androidx.test.espresso.action.GeneralLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testSwipeUpToExpand() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #2
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testNoSwipeUpToExpand() {
  getBehavior().setDraggable(false);
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));

  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
  assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
}
 
Example #3
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testNoDragging() {
  getBehavior().setDraggable(false);
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      // Drag (and not release)
      .perform(
          new DragAction(
              GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER))
      // Check that the bottom sheet is NOT in STATE_DRAGGING
      .check(
          (view, e) -> {
            assertThat(view, is(ViewMatchers.isDisplayed()));
            BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view);
            assertThat(behavior.getState(), not(is(BottomSheetBehavior.STATE_DRAGGING)));
          });
}
 
Example #4
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testHalfExpandedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_HALF_EXPANDED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #5
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testCollapsedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #6
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testInvisible() throws Throwable {
  // Make the bottomsheet invisible
  activityTestRule.runOnUiThread(
      () -> {
        getBottomSheet().setVisibility(View.INVISIBLE);
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
      });
  // Swipe up as if to expand it
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              not(ViewMatchers.isDisplayed())));
  // Check that the bottom sheet stays the same collapsed state
  activityTestRule.runOnUiThread(
      () -> assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)));
}
 
Example #7
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testLayoutWhileDragging() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      // Drag (and not release)
      .perform(
          new DragAction(
              GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER))
      // Check that the bottom sheet is in STATE_DRAGGING
      .check(
          (view, e) -> {
            assertThat(view, is(ViewMatchers.isDisplayed()));
            BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view);
            assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_DRAGGING));
          })
      // Add a new view
      .perform(new AddViewAction(R.layout.frame_layout))
      // Check that the newly added view is properly laid out
      .check(
          (view, e) -> {
            ViewGroup parent = (ViewGroup) view;
            assertThat(parent.getChildCount(), is(1));
            View child = parent.getChildAt(0);
            assertThat(ViewCompat.isLaidOut(child), is(true));
          });
}
 
Example #8
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
@MediumTest
public void testInvisibleThenVisible() throws Throwable {
  activityTestRule.runOnUiThread(
      () -> {
        // The bottom sheet is initially invisible
        getBottomSheet().setVisibility(View.INVISIBLE);
        // Then it becomes visible when the CoL is touched
        getCoordinatorLayout()
            .setOnTouchListener(
                (view, e) -> {
                  if (e.getAction() == MotionEvent.ACTION_DOWN) {
                    getBottomSheet().setVisibility(View.VISIBLE);
                    return true;
                  }
                  return false;
                });
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
      });
  // Drag over the CoL
  Espresso.onView(ViewMatchers.withId(R.id.coordinator))
      // Drag (and not release)
      .perform(
          new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER))
      .check(
          (view, e) -> {
            // The bottom sheet should not react to the touch events
            assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed()));
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
          });
}
 
Example #9
Source File: MainActivityTest.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ClickWithoutDisplayConstraint getClickAction() {
    return new ClickWithoutDisplayConstraint(
            Tap.SINGLE,
            GeneralLocation.VISIBLE_CENTER,
            Press.FINGER,
            InputDevice.SOURCE_UNKNOWN,
            MotionEvent.BUTTON_PRIMARY);
}
 
Example #10
Source File: MainActivityTest.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ClickWithoutDisplayConstraint getLongClickAction() {
    return new ClickWithoutDisplayConstraint(
            Tap.LONG,
            GeneralLocation.CENTER,
            Press.FINGER,
            InputDevice.SOURCE_UNKNOWN,
            MotionEvent.BUTTON_PRIMARY);
}
 
Example #11
Source File: SwipeOpenItemTouchHelperTest.java    From SwipeOpenItemTouchHelper with Apache License 2.0 2 votes vote down vote up
/**
 * Uses a slow swipe to simulate a scroll
 *
 * @return the view action
 */
private ViewAction scroll() {
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.BOTTOM_CENTER,
      GeneralLocation.TOP_CENTER, Press.FINGER);
}
 
Example #12
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe right-to-left across the vertical center of the
 * view. The swipe doesn't start at the very edge of the view, but is a bit offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeLeftSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.CENTER_RIGHT, -EDGE_FUZZ_FACTOR, 0),
            GeneralLocation.CENTER_LEFT, Press.FINGER));
}
 
Example #13
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe left-to-right across the vertical center of the
 * view. The swipe doesn't start at the very edge of the view, but is a bit offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeRightSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.CENTER_LEFT, EDGE_FUZZ_FACTOR, 0),
            GeneralLocation.CENTER_RIGHT, Press.FINGER));
}
 
Example #14
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.
 * The swipe doesn't start at the very edge of the view, but has a bit of offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeDownSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.TOP_CENTER, 0, EDGE_FUZZ_FACTOR),
            GeneralLocation.BOTTOM_CENTER, Press.FINGER));
}
 
Example #15
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.
 * The swipe doesn't start at the very edge of the view, but has a bit of offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeUpSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.BOTTOM_CENTER, 0, -EDGE_FUZZ_FACTOR),
            GeneralLocation.TOP_CENTER, Press.FINGER));
}