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];
}
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);
}
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);
}
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);
}
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);
}
Aggregations