Da uma olhada em um que fiz
@RunWith(AndroidJUnit4::class)
@LargeTest
class MainActivityTest {
@get:Rule
val rule = ActivityScenarioRule(MainActivity::class.java)
@Test
fun happyPath() {
verifyThatLoadingScreenIsDisplayed()
verifyThatListScreenIsDisplayed()
verifyThatNewReviewsFoundWhenScrollToLastPosition()
verifyThatReviewDetailIsIsDisplayedWhenClickOnReview()
}
private fun verifyThatLoadingScreenIsDisplayed() {
onView(withId(R.id.loadingLottieView))
.check(matches(isDisplayed()))
Thread.sleep(5000)
}
private fun verifyThatListScreenIsDisplayed() {
onView(withId(R.id.review_list))
.check(matches(isDisplayed()))
onView(withId(R.id.review_list))
.check(matches(reviewIsDisplayed(atPosition = 0, hasRating = 5)))
onView(withId(R.id.review_list))
.check(matches(reviewIsDisplayed(atPosition = 1, hasRating = 4, hasImage = true)))
onView(withId(R.id.review_list))
.check(matches(reviewListCount(10)))
}
private fun verifyThatNewReviewsFoundWhenScrollToLastPosition() {
onView(withId(R.id.review_list)).perform(
RecyclerViewActions.scrollToPosition<ReviewAdapter.ReviewViewHolder>(9)
)
Thread.sleep(5000)
onView(withId(R.id.review_list))
.check(matches(reviewListCount(20)))
}
private fun verifyThatReviewDetailIsIsDisplayedWhenClickOnReview() {
onView(withId(R.id.review_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<ReviewAdapter.ReviewViewHolder>(9, click())
)
onView(withId(R.id.bottomSheetUser)).check(matches(isDisplayed()))
}