Search in sources :

Example 1 with CoordinatesProvider

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();
    }
}
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 2 with CoordinatesProvider

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();
    }
}
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 3 with CoordinatesProvider

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));
        }
    });
}
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 4 with CoordinatesProvider

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);
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 5 with CoordinatesProvider

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();
    }
}
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)

Aggregations

CoordinatesProvider (android.support.test.espresso.action.CoordinatesProvider)9 View (android.view.View)9 GeneralSwipeAction (android.support.test.espresso.action.GeneralSwipeAction)8 TextView (android.widget.TextView)8 MediumTest (android.support.test.filters.MediumTest)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)3 DisplayMetrics (android.util.DisplayMetrics)2 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)2 GeneralClickAction (android.support.test.espresso.action.GeneralClickAction)1 ViewGroup (android.view.ViewGroup)1