Search in sources :

Example 26 with ViewAction

use of android.support.test.espresso.ViewAction in project iosched by google.

the class MatchersHelper method getTextForViewGroupDescendant.

/**
     * This returns the text for the view that has an id of {@code idOfDescendantViewToGetTextFor}
     * and is a descendant of the nth child of {@code parentViewWithMultipleChildren}, where n
     * equals {@code indexOfDescendant}. The parent view is expected to be a {@link ViewGroup} and
     * the descendant view is expected to be a {@link TextView}. This is used when there is a
     * certain randomness in the elements shown in a collection view, even with mock data.
     *
     * @see com.google.samples.apps.iosched.videolibrary.VideoLibraryModel
     */
public static String getTextForViewGroupDescendant(final Matcher<View> parentViewWithMultipleChildren, final int indexOfDescendant, final int idOfDescendantViewToGetTextFor) {
    /**
         * We cannot use a String directly as we need to make it final to access it inside the
         * inner method but we cannot reassign a value to a final String.
         */
    final String[] stringHolder = { null };
    onView(parentViewWithMultipleChildren).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ViewGroup.class);
        }

        @Override
        public String getDescription() {
            return "getting text from a TextView with a known id and that is a descendant of " + "the nth child of a viewgroup";
        }

        @Override
        public void perform(UiController uiController, View view) {
            ViewGroup vg = (ViewGroup) view;
            View nthDescendant = vg.getChildAt(indexOfDescendant);
            TextView matchedView = (TextView) nthDescendant.findViewById(idOfDescendantViewToGetTextFor);
            stringHolder[0] = matchedView.getText().toString();
        }
    });
    return stringHolder[0];
}
Also used : ViewAction(android.support.test.espresso.ViewAction) BaseMatcher(org.hamcrest.BaseMatcher) Matcher(org.hamcrest.Matcher) ViewGroup(android.view.ViewGroup) UiController(android.support.test.espresso.UiController) TextView(android.widget.TextView) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 27 with ViewAction

use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.

the class ColumnTest method clipToPadding_IsTrue_paddingStaySame.

@Test
public void clipToPadding_IsTrue_paddingStaySame() throws Exception {
    //arrange
    RecyclerView rvTest = (RecyclerView) activityTestRule.getActivity().findViewById(R.id.rvTest);
    ViewAction viewAction = actionDelegate((uiController, view) -> {
        view.setClipToPadding(true);
        view.setPadding(150, 150, 150, 150);
        view.requestLayout();
    });
    //act
    recyclerView.perform(viewAction);
    recyclerView.perform(RecyclerViewActions.scrollToPosition(18));
    //assert
    View view = layoutManager.getChildAt(0);
    double padding = view.getX() - rvTest.getX();
    assertTrue(padding >= 150);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Espresso.onView(android.support.test.espresso.Espresso.onView) Test(org.junit.Test)

Example 28 with ViewAction

use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.

the class ColumnTest method smoothScrollToPosition_ScrollItemIsNotVisible_FirstVisiblePositionsEqualsScrollingTarget.

@Test
public synchronized void smoothScrollToPosition_ScrollItemIsNotVisible_FirstVisiblePositionsEqualsScrollingTarget() throws Exception {
    //arrange
    InstrumentalUtil.waitForIdle();
    //act
    ViewAction scrollAction = smoothScrollToPosition(18);
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (scrollAction) {
        recyclerView.perform(scrollAction);
        //wait for completion of SmoothScrollAction
        scrollAction.wait();
    }
    //assert
    int actual = layoutManager.findFirstCompletelyVisibleItemPosition();
    assertEquals(18, actual);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) Test(org.junit.Test)

Example 29 with ViewAction

use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.

the class RowTest method clipToPadding_IsFalse_paddingOfScrolledViewIsLowerThanInitial.

@Test
public void clipToPadding_IsFalse_paddingOfScrolledViewIsLowerThanInitial() throws Exception {
    //arrange
    ViewAction arrangeAction = actionDelegate((uiController, view) -> {
        view.setClipToPadding(false);
        view.setPadding(150, 150, 150, 150);
        view.requestLayout();
    });
    recyclerView.perform(arrangeAction);
    //act
    recyclerView.perform(RecyclerViewActions.scrollToPosition(8), scrollBy(0, 200));
    //assert
    View view = layoutManager.getChildAt(0);
    int padding = layoutManager.getDecoratedTop(view);
    assertTrue(padding < 0);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Espresso.onView(android.support.test.espresso.Espresso.onView) Test(org.junit.Test)

Example 30 with ViewAction

use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.

the class RowTest method clipToPadding_IsTrue_paddingStaySame.

///////////////////////////////////////////////////////////////////////////
// padding
///////////////////////////////////////////////////////////////////////////
@Test
public void clipToPadding_IsTrue_paddingStaySame() throws Exception {
    //arrange
    RecyclerView rvTest = (RecyclerView) activityTestRule.getActivity().findViewById(R.id.rvTest);
    ViewAction initAction = actionDelegate((uiController, view) -> {
        view.setClipToPadding(true);
        view.setPadding(150, 150, 150, 150);
        view.requestLayout();
    });
    recyclerView.perform(initAction);
    //act
    recyclerView.perform(RecyclerViewActions.scrollToPosition(8));
    //assert
    View view = layoutManager.getChildAt(0);
    double padding = view.getY() - rvTest.getY();
    assertTrue(padding >= 150);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Espresso.onView(android.support.test.espresso.Espresso.onView) Test(org.junit.Test)

Aggregations

ViewAction (android.support.test.espresso.ViewAction)64 View (android.view.View)60 UiController (android.support.test.espresso.UiController)55 NavigationView (android.support.design.widget.NavigationView)17 Espresso.onView (android.support.test.espresso.Espresso.onView)11 TextView (android.widget.TextView)11 Test (org.junit.Test)9 ViewPager (android.support.v4.view.ViewPager)8 TabLayout (android.support.design.widget.TabLayout)7 TextInputLayout (android.support.design.widget.TextInputLayout)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)6 RecyclerView (android.support.v7.widget.RecyclerView)6 ViewGroup (android.view.ViewGroup)4 Matcher (org.hamcrest.Matcher)4 BaseMatcher (org.hamcrest.BaseMatcher)3 TabLayoutActions.setupWithViewPager (android.support.design.testutils.TabLayoutActions.setupWithViewPager)2 BottomNavigationView (android.support.design.widget.BottomNavigationView)2 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)2 ViewInteraction (android.support.test.espresso.ViewInteraction)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2