use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testSwipeUpToExpand.
@Test
@MediumTest
public void testSwipeUpToExpand() {
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.VISIBLE_CENTER, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return 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();
}
}
use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testNestedScroll.
@Test
@MediumTest
public void testNestedScroll() throws Throwable {
final ViewGroup bottomSheet = getBottomSheet();
final BottomSheetBehavior behavior = getBehavior();
final NestedScrollView scroll = new NestedScrollView(activityTestRule.getActivity());
// Set up nested scrolling area
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
bottomSheet.addView(scroll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
TextView view = new TextView(activityTestRule.getActivity());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 500; ++i) {
sb.append("It is fine today. ");
}
view.setText(sb);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do nothing
}
});
scroll.addView(view);
assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
// The scroll offset is 0 at first
assertThat(scroll.getScrollY(), is(0));
}
});
// Swipe from the very bottom of the bottom sheet to the top edge of the screen so that the
// scrolling content is also scrolled
Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new GeneralSwipeAction(Swipe.SLOW, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, view.getHeight() - 1 };
}
}, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, 1 };
}
}, Press.FINGER));
registerIdlingResourceCallback();
try {
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_EXPANDED));
// This confirms that the nested scrolling area was scrolled continuously after
// the bottom sheet is expanded.
assertThat(scroll.getScrollY(), is(not(0)));
}
});
} finally {
unregisterIdlingResourceCallback();
}
}
use of android.support.test.espresso.action.CoordinatesProvider in project CompactCalendarView by SundeepK.
the class ApplicationTest method scroll.
public ViewAction scroll(final int startX, final int startY, final int endX, final int endY) {
final DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float spStartX = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, startX, dm);
final float spStartY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, startY, dm);
final float spEndX = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, endX, dm);
final float spEndY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, endY, dm);
return new GeneralSwipeAction(Swipe.FAST, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final float screenX = screenPos[0] + spStartX;
final float screenY = screenPos[1] + spStartY;
float[] coordinates = { screenX, screenY };
return coordinates;
}
}, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final float screenX = screenPos[0] + spEndX;
final float screenY = screenPos[1] + spEndY;
float[] coordinates = { screenX, screenY };
return coordinates;
}
}, Press.FINGER);
}
use of android.support.test.espresso.action.CoordinatesProvider in project CompactCalendarView by SundeepK.
the class ApplicationTest method clickXY.
public ViewAction clickXY(final float x, final float y) {
final DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float spX = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, x, dm);
final float spY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, y, dm);
return new GeneralClickAction(Tap.SINGLE, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final float screenX = screenPos[0] + spX;
final float screenY = screenPos[1] + spY;
float[] coordinates = { screenX, screenY };
return coordinates;
}
}, Press.FINGER);
}
Aggregations