Search in sources :

Example 36 with ViewAction

use of android.support.test.espresso.ViewAction in project material-components-android by material-components.

the class TabLayoutActions method setupWithViewPager.

/** Wires <code>TabLayout</code> to <code>ViewPager</code> content. */
public static ViewAction setupWithViewPager(@Nullable final ViewPager viewPager) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Setup with ViewPager content";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TabLayout tabLayout = (TabLayout) view;
            tabLayout.setupWithViewPager(viewPager);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) TabLayout(android.support.design.widget.TabLayout) UiController(android.support.test.espresso.UiController) View(android.view.View)

Example 37 with ViewAction

use of android.support.test.espresso.ViewAction in project material-components-android by material-components.

the class TabLayoutActions method setScrollPosition.

/**
   * Calls <code>setScrollPosition(position, positionOffset, true)</code> on the <code>TabLayout
   * </code>
   */
public static ViewAction setScrollPosition(final int position, final float positionOffset) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "setScrollPosition(" + position + ", " + positionOffset + ", true)";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TabLayout tabs = (TabLayout) view;
            tabs.setScrollPosition(position, positionOffset, true);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) TabLayout(android.support.design.widget.TabLayout) UiController(android.support.test.espresso.UiController) View(android.view.View)

Example 38 with ViewAction

use of android.support.test.espresso.ViewAction in project material-components-android by material-components.

the class TestUtilsActions method addTabs.

/** Adds tabs to {@link TabLayout} */
public static ViewAction addTabs(final String... tabs) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "TabLayout add tabs";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            TabLayout tabLayout = (TabLayout) view;
            for (int i = 0; i < tabs.length; i++) {
                tabLayout.addTab(tabLayout.newTab().setText(tabs[i]));
            }
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) TabLayout(android.support.design.widget.TabLayout) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View)

Example 39 with ViewAction

use of android.support.test.espresso.ViewAction in project material-components-android by material-components.

the class TestUtilsActions method setTitle.

/** Sets title on the {@link CollapsingToolbarLayout}. */
public static ViewAction setTitle(final CharSequence title) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "set toolbar title";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) view;
            collapsingToolbarLayout.setTitle(title);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View)

Example 40 with ViewAction

use of android.support.test.espresso.ViewAction in project material-components-android by material-components.

the class TestUtilsActions method replaceTabLayout.

/**
   * Replaces an existing {@link TabLayout} with a new one inflated from the specified layout
   * resource.
   */
public static ViewAction replaceTabLayout(@LayoutRes final int tabLayoutResId) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "Replace TabLayout";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final ViewGroup viewGroup = (ViewGroup) view;
            final int childCount = viewGroup.getChildCount();
            // Iterate over children and find TabLayout
            for (int i = 0; i < childCount; i++) {
                View child = viewGroup.getChildAt(i);
                if (child instanceof TabLayout) {
                    // Remove the existing TabLayout
                    viewGroup.removeView(child);
                    // Create a new one
                    final LayoutInflater layoutInflater = LayoutInflater.from(view.getContext());
                    final TabLayout newTabLayout = (TabLayout) layoutInflater.inflate(tabLayoutResId, viewGroup, false);
                    // Make sure we're adding the new TabLayout at the same index
                    viewGroup.addView(newTabLayout, i);
                    break;
                }
            }
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) ViewGroup(android.view.ViewGroup) TabLayout(android.support.design.widget.TabLayout) LayoutInflater(android.view.LayoutInflater) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

ViewAction (android.support.test.espresso.ViewAction)65 View (android.view.View)61 UiController (android.support.test.espresso.UiController)56 NavigationView (android.support.design.widget.NavigationView)18 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