use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.
the class FewChipsColumnTest method wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease.
@Test
public void wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease() throws Exception {
//arrange
activity.runOnUiThread(() -> activity.initialize());
final RecyclerView[] rvTest = new RecyclerView[1];
ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));
ViewAction viewAction = actionDelegate(((uiController, view) -> {
rvTest[0] = view;
view.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
view.requestLayout();
}));
recyclerView.perform(viewAction);
int startWidth = rvTest[0].getHeight();
//act
recyclerView.perform(actionDelegate(((uiController, view) -> items.remove(9))), notifyItemRemovedAction(9));
InstrumentalUtil.waitForIdle();
//assert
int endWidth = rvTest[0].getWidth();
System.out.println(String.format(Locale.getDefault(), "start height = %d, end height = %d", startWidth, endWidth));
assertTrue(endWidth < startWidth);
}
use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.
the class FewChipsRowTest method wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease.
@Test
public void wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease() throws Exception {
//arrange
activity.runOnUiThread(() -> activity.initialize());
final RecyclerView[] rvTest = new RecyclerView[1];
ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));
ViewAction viewAction = actionDelegate((uiController, view) -> {
rvTest[0] = view;
view.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
view.requestLayout();
});
recyclerView.perform(viewAction);
int startHeight = rvTest[0].getHeight();
//act
recyclerView.perform(actionDelegate(((uiController, view) -> items.remove(9))), notifyItemRemovedAction(9));
//assert
int endHeight = rvTest[0].getHeight();
System.out.println(String.format(Locale.getDefault(), "start height = %d, end height = %d", startHeight, endHeight));
assertTrue(endHeight < startHeight);
}
use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.
the class RowTest method smoothScrollToPosition_LMInInitialState_FirstVisiblePositionsEqualsScrollingTarget.
@Test
public synchronized void smoothScrollToPosition_LMInInitialState_FirstVisiblePositionsEqualsScrollingTarget() throws Exception {
//arrange
InstrumentalUtil.waitForIdle();
//act
ViewAction scrollAction = smoothScrollToPosition(8);
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (scrollAction) {
recyclerView.perform(scrollAction);
//wait for completion of SmoothScrollAction
scrollAction.wait();
}
//assert
int actual = layoutManager.findFirstCompletelyVisibleItemPosition();
assertEquals(8, actual);
}
use of android.support.test.espresso.ViewAction in project BottomNavigation by Ashok-Varma.
the class Utils method waitId.
/**
* Perform action of waiting for a specific view id.
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
};
}
Aggregations