Search in sources :

Example 6 with GeneralSwipeAction

use of android.support.test.espresso.action.GeneralSwipeAction 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();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 7 with GeneralSwipeAction

use of android.support.test.espresso.action.GeneralSwipeAction 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();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) ViewGroup(android.view.ViewGroup) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 8 with GeneralSwipeAction

use of android.support.test.espresso.action.GeneralSwipeAction 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);
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) DisplayMetrics(android.util.DisplayMetrics) View(android.view.View) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) CompactCalendarView(com.github.sundeepk.compactcalendarview.CompactCalendarView)

Aggregations

CoordinatesProvider (android.support.test.espresso.action.CoordinatesProvider)8 GeneralSwipeAction (android.support.test.espresso.action.GeneralSwipeAction)8 View (android.view.View)8 MediumTest (android.support.test.filters.MediumTest)7 TextView (android.widget.TextView)7 Test (org.junit.Test)7 SmallTest (android.support.test.filters.SmallTest)6 NestedScrollView (android.support.v4.widget.NestedScrollView)6 Espresso.onView (android.support.test.espresso.Espresso.onView)2 DisplayMetrics (android.util.DisplayMetrics)1 ViewGroup (android.view.ViewGroup)1 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)1