Something went wrong. Try again.
A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
Something went wrong. Try again.
SimpleTimeTracker-WearOS app src androidTest java com example util simpletimetracker utils ViewInteractions.kt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101package com.example.util.simpletimetracker.utils
import android.view.Viewimport androidx.test.espresso.Espresso.onViewimport androidx.test.espresso.Espresso.pressBackimport androidx.test.espresso.ViewInteractionimport androidx.test.espresso.action.ViewActions.clickimport androidx.test.espresso.action.ViewActions.longClickimport androidx.test.espresso.action.ViewActions.replaceTextimport androidx.test.espresso.assertion.ViewAssertions.doesNotExistimport androidx.test.espresso.assertion.ViewAssertions.matchesimport androidx.test.espresso.contrib.PickerActions.setTimeimport androidx.test.espresso.contrib.RecyclerViewActions.scrollToimport androidx.test.espresso.contrib.RecyclerViewActions.scrollToPositionimport androidx.test.espresso.matcher.ViewMatchers.isCheckedimport androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayedimport androidx.test.espresso.matcher.ViewMatchers.isDescendantOfAimport androidx.test.espresso.matcher.ViewMatchers.isDisplayedimport androidx.test.espresso.matcher.ViewMatchers.isNotCheckedimport androidx.test.espresso.matcher.ViewMatchers.withClassNameimport androidx.test.espresso.matcher.ViewMatchers.withIdimport androidx.test.espresso.matcher.ViewMatchers.withTextimport com.example.util.simpletimetracker.feature_base_adapter.BaseRecyclerViewHolderimport com.example.util.simpletimetracker.feature_dialogs.dateTime.CustomTimePickerimport org.hamcrest.CoreMatchers.allOfimport org.hamcrest.CoreMatchers.equalToimport org.hamcrest.CoreMatchers.notimport org.hamcrest.Matcher
fun checkViewIsNotDisplayed(matcher: Matcher<View>): ViewInteraction = onView(matcher).check(matches(not(isDisplayed())))
fun checkViewDoesNotExist(matcher: Matcher<View>): ViewInteraction = onView(matcher).check(doesNotExist())
fun checkViewIsDisplayed(matcher: Matcher<View>): ViewInteraction = onView(matcher).check(matches(isDisplayed()))
fun typeTextIntoView(id: Int, text: String): ViewInteraction = onView(withId(id)).perform(replaceText(text)) // typeText sometimes misses letters
fun clickOnViewWithId(id: Int): ViewInteraction = onView(withId(id)).perform(click())
fun clickOnViewWithIdOnPager(id: Int): ViewInteraction = onView(allOf(isCompletelyDisplayed(), withId(id))).perform(click())
fun clickOnViewWithText(textId: Int): ViewInteraction = onView(withText(textId)).perform(click())
fun clickOnViewWithText(text: String): ViewInteraction = onView(withText(text)).perform(click())
fun clickOnView(matcher: Matcher<View>): ViewInteraction = onView(matcher).perform(click())
fun unconstrainedClickOnView(matcher: Matcher<View>): ViewInteraction = onView(matcher).perform(unconstrainedClick())
fun longClickOnView(matcher: Matcher<View>): ViewInteraction = onView(matcher).perform(longClick())
fun longClickOnViewWithId(id: Int): ViewInteraction = onView(withId(id)).perform(longClick())
fun clickOnRecyclerItem(id: Int, matcher: Matcher<View>): ViewInteraction = onView(allOf(isDescendantOfA(withId(id)), matcher)).perform(click())
fun scrollRecyclerToPosition(id: Int, position: Int): ViewInteraction = onView(withId(id)).perform(scrollToPosition<BaseRecyclerViewHolder>(position))
fun scrollRecyclerToView(id: Int, matcher: Matcher<View>): ViewInteraction = onView(withId(id)).perform(scrollTo<BaseRecyclerViewHolder>(matcher))
fun scrollRecyclerInPagerToView(id: Int, matcher: Matcher<View>): ViewInteraction = onView(allOf(withId(id), isCompletelyDisplayed())).perform(scrollTo<BaseRecyclerViewHolder>(matcher))
fun toastTextShowing(textId: Int): ViewInteraction = onView(withText(textId)).inRoot(isToast()).check(matches(isDisplayed()))
fun clickOnSpinnerWithId(id: Int) { onView(withId(id)).perform(nestedScrollTo()) // Double click to avoid failure on low api small screens clickOnViewWithId(id) pressBack() clickOnViewWithId(id)}
fun checkSliderValue(id: Int, expectedValue: Int): ViewInteraction = onView(withId(id)).check(matches(withSliderValue((expectedValue))))
fun setPickerTime(hour: Int, minute: Int) { onView(withClassName(equalTo(CustomTimePicker::class.java.name))).perform(setTime(hour, minute))}
fun checkCheckboxIsChecked(matcher: Matcher<View>): ViewInteraction = onView(matcher).check(matches(isChecked()))
fun checkCheckboxIsNotChecked(matcher: Matcher<View>): ViewInteraction = onView(matcher).check(matches(isNotChecked()))