use of android.support.test.filters.MediumTest 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();
}
}
use of android.support.test.filters.MediumTest 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.filters.MediumTest 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.filters.MediumTest in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testDynamicContent.
@Test
@MediumTest
public void testDynamicContent() throws Throwable {
registerIdlingResourceCallback();
try {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
ViewGroup.LayoutParams params = getBottomSheet().getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
getBottomSheet().setLayoutParams(params);
View view = new View(getBottomSheet().getContext());
int size = getBehavior().getPeekHeight() * 2;
getBottomSheet().addView(view, new ViewGroup.LayoutParams(size, size));
assertThat(getBottomSheet().getChildCount(), is(1));
// Shrink the content height.
ViewGroup.LayoutParams lp = view.getLayoutParams();
lp.height = (int) (size * 0.8);
view.setLayoutParams(lp);
// Immediately expand the bottom sheet.
getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
// Make sure that the bottom sheet is not floating above the bottom.
assertThat(getBottomSheet().getBottom(), is(getCoordinatorLayout().getBottom()));
} finally {
unregisterIdlingResourceCallback();
}
}
use of android.support.test.filters.MediumTest in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testInvisibleThenVisible.
@Test
@MediumTest
public void testInvisibleThenVisible() throws Throwable {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
// The bottom sheet is initially invisible
getBottomSheet().setVisibility(View.INVISIBLE);
// Then it becomes visible when the CoL is touched
getCoordinatorLayout().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent 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)).perform(new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
// The bottom sheet should not react to the touch events
assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed()));
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
}
});
}
Aggregations