Skip to content

Commit

Permalink
Merge pull request #20315 from wordpress-mobile/andy/fix-stats-ui-test
Browse files Browse the repository at this point in the history
[Stats] Fixed broken Stats UI tests.
  • Loading branch information
notandyvee authored Mar 1, 2024
2 parents f6ae416 + 6c461e5 commit b355f63
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.wordpress.android.BuildConfig
import org.wordpress.android.R
Expand All @@ -22,9 +21,7 @@ import org.wordpress.android.util.StatsVisitsData
class StatsTests : BaseTest() {
@Before
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 @@ -38,8 +35,7 @@ class StatsTests : BaseTest() {
Espresso.pressBack()
}
}

@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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)
)
WPSupportUtils.scrollIntoView(R.id.statsPager, card, 0.5.toFloat())
WPSupportUtils.idleFor(2000)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
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 b355f63

Please sign in to comment.