Skip to content

Commit

Permalink
[Stats] Fixed broken stats UI tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Valdez authored and Andy Valdez committed Feb 28, 2024
1 parent 6fbf3fd commit 375a15f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Expand Up @@ -24,7 +24,7 @@ class StatsTests : BaseTest() {
fun setUp() {
// We're not running Stats tests for JP.
// See https://github.com/wordpress-mobile/WordPress-Android/issues/18065
assumeTrue(!BuildConfig.IS_JETPACK_APP)
assumeTrue(BuildConfig.IS_JETPACK_APP)
ComposeEspressoLink().unregister()
logoutIfNecessary()
wpLogin()
Expand All @@ -39,7 +39,7 @@ class StatsTests : BaseTest() {
}
}

@Ignore("Will be taken care of in a future PR - scrollToPosts is not working")
// @Ignore("Will be taken care of in a future PR - scrollToPosts is not working")
@Test
fun e2eAllDayStatsLoad() {
val todayVisits = StatsVisitsData("97", "28", "14", "11")
Expand Down
Expand Up @@ -149,7 +149,7 @@ class MySitesPage {
val statsButton = Espresso.onView(
Matchers.allOf(
ViewMatchers.withText(R.string.stats),
ViewMatchers.withId(R.id.my_site_item_primary_text)
ViewMatchers.withId(R.id.quick_link_item)
)
)
WPSupportUtils.clickOn(statsButton)
Expand All @@ -158,7 +158,7 @@ class MySitesPage {
WPSupportUtils.waitForElementToBeDisplayedWithoutFailure(R.id.tabLayout)

// Wait for the stats to load
WPSupportUtils.idleFor(8000)
WPSupportUtils.idleFor(4000)
return StatsPage()
}

Expand Down
@@ -1,12 +1,15 @@
package org.wordpress.android.e2e.pages

import androidx.recyclerview.widget.RecyclerView.ViewHolder
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.Matchers
import org.wordpress.android.R
import org.wordpress.android.support.WPSupportUtils
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel
import org.wordpress.android.util.StatsKeyValueData
import org.wordpress.android.util.StatsVisitsData

Expand All @@ -31,37 +34,37 @@ class StatsPage {
}

fun scrollToPosts(): StatsPage {
scrollToCard("Posts and Pages")
scrollToCard(1, StatsListViewModel.StatsSection.DAYS)
return this
}

fun scrollToReferrers(): StatsPage {
scrollToCard("Referrers")
scrollToCard(2, StatsListViewModel.StatsSection.DAYS)
return this
}

fun scrollToClicks(): StatsPage {
scrollToCard("Clicks")
scrollToCard(3, StatsListViewModel.StatsSection.DAYS)
return this
}

fun scrollToAuthors(): StatsPage {
scrollToCard("Authors")
scrollToCard(4, StatsListViewModel.StatsSection.DAYS)
return this
}

fun scrollToCountries(): StatsPage {
scrollToCard("Countries")
scrollToCard(5, StatsListViewModel.StatsSection.DAYS)
return this
}

fun scrollToVideos(): StatsPage {
scrollToCard("Videos")
scrollToCard(7, StatsListViewModel.StatsSection.DAYS)
return this
}

fun scrollToFileDownloads(): StatsPage {
scrollToCard("File downloads")
scrollToCard(8, StatsListViewModel.StatsSection.DAYS)
return this
}

Expand Down Expand Up @@ -96,7 +99,7 @@ class StatsPage {
)
)
)
cardStructure.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
cardStructure.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
return this
}

Expand All @@ -121,7 +124,7 @@ class StatsPage {
)
)
)
cardStructure.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
cardStructure.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}
}

Expand Down Expand Up @@ -160,15 +163,14 @@ class StatsPage {
return this
}

private fun scrollToCard(cardHeader: String) {
val card = Espresso.onView(
Matchers.allOf(
ViewMatchers.isDescendantOfA(visibleCoordinatorLayout),
ViewMatchers.withId(R.id.stats_block_list),
ViewMatchers.hasDescendant(ViewMatchers.withText(cardHeader))
)
private fun scrollToCard(viewholderPosition: Int, section: StatsListViewModel.StatsSection) {
WPSupportUtils.idleFor(2000)
Espresso.onView(Matchers.allOf(
ViewMatchers.withTagValue(Matchers.`is`(section.name))
)).perform(
RecyclerViewActions.scrollToPosition<ViewHolder>(viewholderPosition) // This works
)
WPSupportUtils.scrollIntoView(R.id.statsPager, card, 0.5.toFloat())
WPSupportUtils.idleFor(2000)
}

companion object {
Expand Down
Expand Up @@ -128,6 +128,7 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) {
}

this@StatsListFragment.layoutManager = layoutManager
this.recyclerView.tag = statsSection.name
recyclerView.layoutManager = this@StatsListFragment.layoutManager
recyclerView.addItemDecoration(
StatsListItemDecoration(
Expand Down

0 comments on commit 375a15f

Please sign in to comment.