Search in sources :

Example 31 with UiController

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

the class NavigationViewActions method removeMenuItem.

/**
   * Removes the specified menu item from the navigation view.
   *
   * @param menuItemId The ID of the menu item to be removed.
   */
public static ViewAction removeMenuItem(@IdRes final int menuItemId) {
    return new ViewAction() {

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

        @Override
        public String getDescription() {
            return "Remove menu item " + menuItemId;
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            NavigationView navigationView = (NavigationView) view;
            navigationView.getMenu().removeItem(menuItemId);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 32 with UiController

use of android.support.test.espresso.UiController 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 33 with UiController

use of android.support.test.espresso.UiController 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 34 with UiController

use of android.support.test.espresso.UiController 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 35 with UiController

use of android.support.test.espresso.UiController 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)

Aggregations

UiController (android.support.test.espresso.UiController)57 View (android.view.View)57 ViewAction (android.support.test.espresso.ViewAction)56 NavigationView (android.support.design.widget.NavigationView)18 TextView (android.widget.TextView)11 ViewPager (android.support.v4.view.ViewPager)8 TabLayout (android.support.design.widget.TabLayout)7 TextInputLayout (android.support.design.widget.TextInputLayout)7 Espresso.onView (android.support.test.espresso.Espresso.onView)7 FloatingActionButton (android.support.design.widget.FloatingActionButton)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 DrawerLayout (android.support.v4.widget.DrawerLayout)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 TimeoutException (java.util.concurrent.TimeoutException)2 NotFoundException (android.content.res.Resources.NotFoundException)1