use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testSkipCollapsed.
@Test
@MediumTest
public void testSkipCollapsed() throws Throwable {
getBehavior().setSkipCollapsed(true);
checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, // actually falls onto the view on Gingerbread
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
int[] location = new int[2];
view.getLocationInWindow(location);
return new float[] { view.getWidth() / 2, location[1] + 1 };
}
}, // sheet is collapsed, not hidden
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
BottomSheetBehavior behavior = getBehavior();
return new float[] { // x: center of the bottom sheet
view.getWidth() / 2, // y: just above the peek height
view.getHeight() - behavior.getPeekHeight() };
}
}, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5)));
registerIdlingResourceCallback();
try {
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN));
} finally {
unregisterIdlingResourceCallback();
}
}
use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testSwipeDownToCollapse.
@Test
@MediumTest
public void testSwipeDownToCollapse() throws Throwable {
checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, // actually falls onto the view on Gingerbread
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
int[] location = new int[2];
view.getLocationInWindow(location);
return new float[] { view.getWidth() / 2, location[1] + 1 };
}
}, // sheet is collapsed, not hidden
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
BottomSheetBehavior behavior = getBehavior();
return new float[] { // x: center of the bottom sheet
view.getWidth() / 2, // y: just above the peek height
view.getHeight() - behavior.getPeekHeight() };
}
}, 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_COLLAPSED));
} finally {
unregisterIdlingResourceCallback();
}
}
use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testInvisible.
@Test
@MediumTest
public void testInvisible() throws Throwable {
// Make the bottomsheet invisible
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
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, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, 0 };
}
}, Press.FINGER), not(ViewMatchers.isDisplayed())));
// Check that the bottom sheet stays the same collapsed state
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
}
});
}
use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class SnackbarTest method testSwipeUpDismissesViaTimeout.
@Test
public void testSwipeUpDismissesViaTimeout() throws Throwable {
verifyDismissCallback(onView(isAssignableFrom(Snackbar.SnackbarLayout.class)), // (outside the bounds)
new GeneralSwipeAction(Swipe.SLOW, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] loc = new int[2];
view.getLocationOnScreen(loc);
return new float[] { loc[0] + view.getWidth() / 2, loc[1] + view.getHeight() / 2 };
}
}, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] loc = new int[2];
view.getLocationOnScreen(loc);
return new float[] { loc[0] + view.getWidth() / 2, loc[1] - view.getHeight() };
}
}, Press.FINGER), null, Snackbar.LENGTH_SHORT, Snackbar.Callback.DISMISS_EVENT_TIMEOUT);
}
use of android.support.test.espresso.action.CoordinatesProvider in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testDragOutside.
@Test
@MediumTest
public void testDragOutside() {
// Swipe up outside of the bottom sheet
Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, // Just above the bottom sheet
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, view.getHeight() - getBehavior().getPeekHeight() - 9 };
}
}, // Top of the CoordinatorLayout
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, 1 };
}
}, Press.FINGER), ViewMatchers.isDisplayed()));
registerIdlingResourceCallback();
try {
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
// The bottom sheet should remain collapsed
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
} finally {
unregisterIdlingResourceCallback();
}
}
Aggregations