Skip to content

Commit

Permalink
Fix tier list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanKharkevych committed Apr 7, 2024
1 parent 1518247 commit 9efbde2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.doubleClick
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intended
Expand All @@ -29,7 +28,6 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isNotEnabled
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.filters.FlakyTest
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import me.khruslan.tierlistmaker.R
Expand All @@ -41,8 +39,6 @@ import me.khruslan.tierlistmaker.utils.dragTo
import me.khruslan.tierlistmaker.utils.dragToBottomOf
import me.khruslan.tierlistmaker.utils.fetchTierListImage
import me.khruslan.tierlistmaker.utils.fetchTierListImages
import me.khruslan.tierlistmaker.utils.hasEmptyToolbarSubtitle
import me.khruslan.tierlistmaker.utils.hasToolbarSubtitle
import me.khruslan.tierlistmaker.utils.hasToolbarTitle
import me.khruslan.tierlistmaker.utils.isEmpty
import me.khruslan.tierlistmaker.utils.isFirstTierListImage
Expand All @@ -53,6 +49,7 @@ import me.khruslan.tierlistmaker.utils.isTierHeaderAtPosition
import me.khruslan.tierlistmaker.utils.isTierListImageAtPosition
import me.khruslan.tierlistmaker.utils.scaledWithZoomValue
import me.khruslan.tierlistmaker.utils.scrollToLastItem
import me.khruslan.tierlistmaker.utils.swipeRightFromCenter
import me.khruslan.tierlistmaker.utils.waitUntil
import me.khruslan.tierlistmaker.utils.withTierListImage
import me.khruslan.tierlistmaker.utils.withTierListImages
Expand All @@ -61,7 +58,6 @@ import org.hamcrest.Matchers.any
import org.hamcrest.Matchers.not
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

Expand Down Expand Up @@ -135,11 +131,10 @@ class TierListTests {
}

@Test
@FlakyTest
fun viewTierList() {
openTierListWithTitle(R.string.tier_list_sports)
onView(withId(R.id.btn_view)).perform(click()).check(matches(isNotEnabled()))
waitUntilLoadingIsCompleted()
onView(withId(R.id.progress_loading)).perform(waitUntil(not(isDisplayed())))
intended(
allOf(
hasAction(ACTION_VIEW),
Expand All @@ -154,7 +149,7 @@ class TierListTests {
fun shareTierList() {
openTierListWithTitle(R.string.tier_list_fruits)
onView(withId(R.id.btn_share)).perform(click()).check(matches(isNotEnabled()))
waitUntilLoadingIsCompleted()
onView(withId(R.id.progress_loading)).perform(waitUntil(not(isDisplayed())))
intended(
allOf(
hasAction(ACTION_SEND),
Expand All @@ -175,11 +170,12 @@ class TierListTests {
}

@Test
@Ignore("Issue with back navigation gesture on swipeRight()")
fun removeTier() = dataProvider.withTierListData(R.string.tier_list_school_subjects) {
openTierListWithTitle(R.string.tier_list_school_subjects)
onView(withId(R.id.list_tiers)).perform(scrollToLastItem())
onView(isTierHeaderAtPosition(lastTierPosition)).perform(swipeRight()).check(doesNotExist())
onView(isTierHeaderAtPosition(lastTierPosition))
.perform(swipeRightFromCenter())
.check(doesNotExist())
onView(withId(R.id.list_backlog_images)).check(matches(not(isEmpty())))
}

Expand Down Expand Up @@ -211,13 +207,4 @@ class TierListTests {
clickOnTierListWithTitle(title)
)
}

private fun waitUntilLoadingIsCompleted() {
onView(withId(R.id.toolbar))
.check(matches(hasToolbarSubtitle(R.string.toolbar_subtitle_indeterminate_loading)))
onView(withId(R.id.progress_loading))
.check(matches(isDisplayed()))
.perform(waitUntil(not(isDisplayed())))
onView(withId(R.id.toolbar)).check(matches(hasEmptyToolbarSubtitle()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.CoordinatesProvider
import androidx.test.espresso.action.GeneralClickAction
import androidx.test.espresso.action.GeneralLocation
import androidx.test.espresso.action.GeneralSwipeAction
import androidx.test.espresso.action.Press
import androidx.test.espresso.action.Swipe
import androidx.test.espresso.action.Tap
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.swipeRight
Expand Down Expand Up @@ -55,6 +58,15 @@ fun setProgress(progress: Int): ViewAction {
)
}

fun swipeRightFromCenter(): ViewAction {
return GeneralSwipeAction(
Swipe.FAST,
GeneralLocation.CENTER,
GeneralLocation.CENTER_RIGHT,
Press.FINGER
)
}

fun swipeTierListWithTitle(@StringRes titleResId: Int): PositionableRecyclerViewAction {
return actionOnItem<RecyclerView.ViewHolder>(withTierListTitle(titleResId), swipeRight())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ fun hasBackgroundColor(@ColorRes colorResId: Int): Matcher<View> {
return HasBackgroundColorMatcher(colorResId)
}

fun hasEmptyToolbarSubtitle(): Matcher<View> {
return HasToolbarSubtitleMatcher("")
}

fun hasToolbarSubtitle(@StringRes subtitleResId: Int): Matcher<View> {
return HasToolbarSubtitleMatcher(targetContext.getString(subtitleResId))
}

fun hasToolbarTitle(title: String): Matcher<View> {
return HasToolbarTitleMatcher(title)
}
Expand Down Expand Up @@ -269,26 +261,6 @@ private class HasBackgroundColorMatcher(@ColorRes private val colorResId: Int) :
}
}

private class HasToolbarSubtitleMatcher(private val expectedSubtitle: String) :
BoundedDiagnosingMatcher<View, Toolbar>(Toolbar::class.java) {

override fun describeMoreTo(description: Description) {
description
.appendText("toolbar.subtitle is ")
.appendValue(expectedSubtitle)
}

override fun matchesSafely(item: Toolbar, mismatchDescription: Description): Boolean {
val actualTitle = item.subtitle

mismatchDescription
.appendText("toolbar.subtitle was ")
.appendValue(actualTitle)

return expectedSubtitle == actualTitle
}
}

private class HasToolbarTitleMatcher(private val expectedTitle: String) :
BoundedDiagnosingMatcher<View, Toolbar>(Toolbar::class.java) {

Expand Down

0 comments on commit 9efbde2

Please sign in to comment.