Search in sources :

Example 61 with ViewAction

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);
}
Also used : Assert.assertEquals(junit.framework.Assert.assertEquals) ViewAction(android.support.test.espresso.ViewAction) ChipsFacade(com.beloo.chipslayoutmanager.sample.ui.ChipsFacade) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) TestActivity(com.beloo.chipslayoutmanager.sample.ui.TestActivity) ISpy(com.beloo.widget.chipslayoutmanager.util.testing.ISpy) ViewMatchers.isDisplayed(android.support.test.espresso.matcher.ViewMatchers.isDisplayed) LayoutManagerFactory(com.beloo.chipslayoutmanager.sample.ui.LayoutManagerFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) Assert.assertTrue(junit.framework.Assert.assertTrue) Locale(java.util.Locale) View(android.view.View) RecyclerViewEspressoFactory.notifyItemRemovedAction(com.beloo.test.util.RecyclerViewEspressoFactory.notifyItemRemovedAction) ChipsEntity(com.beloo.chipslayoutmanager.sample.entity.ChipsEntity) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ViewInteraction(android.support.test.espresso.ViewInteraction) ActivityTestRule(android.support.test.rule.ActivityTestRule) R(com.beloo.chipslayoutmanager.sample.R) Test(org.junit.Test) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) Mockito.when(org.mockito.Mockito.when) ViewGroup(android.view.ViewGroup) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) RecyclerView(android.support.v7.widget.RecyclerView) ViewAssertions.matches(android.support.test.espresso.assertion.ViewAssertions.matches) List(java.util.List) Rule(org.junit.Rule) Espresso.onView(android.support.test.espresso.Espresso.onView) InstrumentalUtil(com.beloo.widget.chipslayoutmanager.util.InstrumentalUtil) Mockito.atMost(org.mockito.Mockito.atMost) ViewMatchers.withId(android.support.test.espresso.matcher.ViewMatchers.withId) RecyclerViewEspressoFactory.actionDelegate(com.beloo.test.util.RecyclerViewEspressoFactory.actionDelegate) ViewAction(android.support.test.espresso.ViewAction) RecyclerView(android.support.v7.widget.RecyclerView) ViewInteraction(android.support.test.espresso.ViewInteraction) Test(org.junit.Test)

Example 62 with ViewAction

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);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) ViewInteraction(android.support.test.espresso.ViewInteraction) Test(org.junit.Test)

Example 63 with ViewAction

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);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) Test(org.junit.Test)

Example 64 with ViewAction

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();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) View(android.view.View) TimeoutException(java.util.concurrent.TimeoutException)

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