Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1b5bf90 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extract the SidebarBot ClickAction to RelaxedClickAction for reuse" into main

parents 633172ec 3a1fbab6
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.documentsui.actions

import android.view.View
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.Matcher

/**
 * A custom action to remove the constraints on requiring 90% of the views area to be covered.
 * Useful to use on elements (such as menus or search chips which don't fulfill this criteria).
 */
class RelaxedClickAction internal constructor() : ViewAction {
    private val mWrappedClickAction: ViewAction = ViewActions.click()

    override fun getConstraints(): Matcher<View?> = ViewMatchers.isEnabled()

    override fun getDescription(): String? = mWrappedClickAction.description

    override fun perform(uiController: UiController?, view: View?) {
        mWrappedClickAction.perform(uiController, view)
    }
}
+2 −33
Original line number Diff line number Diff line
@@ -17,10 +17,8 @@
package com.android.documentsui.bots;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.swipeLeft;
import static androidx.test.espresso.action.ViewActions.swipeRight;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

@@ -32,8 +30,6 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
@@ -41,11 +37,10 @@ import androidx.test.uiautomator.UiScrollable;
import androidx.test.uiautomator.UiSelector;

import com.android.documentsui.R;
import com.android.documentsui.actions.RelaxedClickAction;

import junit.framework.Assert;

import org.hamcrest.Matcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -180,32 +175,6 @@ public class SidebarBot extends Bots.BaseBot {
                        MotionEvent.ACTION_UP, point.centerX(), point.centerY());
        mAutomation.injectInputEvent(motionUp, true);

        onView(withText(menuOption)).perform(new ClickAction());
    }

    /**
     * A custom action to remove the constraints on requiring 90% of the views area to be covered.
     */
    static final class ClickAction implements ViewAction {
        private final ViewAction mWrappedClickAction;

        ClickAction() {
            mWrappedClickAction = click();
        }

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

        @Override
        public String getDescription() {
            return mWrappedClickAction.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view) {
            mWrappedClickAction.perform(uiController, view);
        }
        onView(withText(menuOption)).perform(new RelaxedClickAction());
    }
}