11package org.wordpress.android.e2e.pages
22
3+ import androidx.recyclerview.widget.RecyclerView.ViewHolder
34import androidx.test.espresso.Espresso
45import androidx.test.espresso.action.ViewActions
56import androidx.test.espresso.assertion.ViewAssertions
7+ import androidx.test.espresso.contrib.RecyclerViewActions
68import androidx.test.espresso.matcher.ViewMatchers
79import org.hamcrest.Matchers
810import org.wordpress.android.R
911import org.wordpress.android.support.WPSupportUtils
12+ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel
1013import org.wordpress.android.util.StatsKeyValueData
1114import org.wordpress.android.util.StatsVisitsData
1215
@@ -31,37 +34,37 @@ class StatsPage {
3134 }
3235
3336 fun scrollToPosts (): StatsPage {
34- scrollToCard(" Posts and Pages " )
37+ scrollToCard(1 , StatsListViewModel . StatsSection . DAYS )
3538 return this
3639 }
3740
3841 fun scrollToReferrers (): StatsPage {
39- scrollToCard(" Referrers " )
42+ scrollToCard(2 , StatsListViewModel . StatsSection . DAYS )
4043 return this
4144 }
4245
4346 fun scrollToClicks (): StatsPage {
44- scrollToCard(" Clicks " )
47+ scrollToCard(3 , StatsListViewModel . StatsSection . DAYS )
4548 return this
4649 }
4750
4851 fun scrollToAuthors (): StatsPage {
49- scrollToCard(" Authors " )
52+ scrollToCard(4 , StatsListViewModel . StatsSection . DAYS )
5053 return this
5154 }
5255
5356 fun scrollToCountries (): StatsPage {
54- scrollToCard(" Countries " )
57+ scrollToCard(5 , StatsListViewModel . StatsSection . DAYS )
5558 return this
5659 }
5760
5861 fun scrollToVideos (): StatsPage {
59- scrollToCard(" Videos " )
62+ scrollToCard(7 , StatsListViewModel . StatsSection . DAYS )
6063 return this
6164 }
6265
6366 fun scrollToFileDownloads (): StatsPage {
64- scrollToCard(" File downloads " )
67+ scrollToCard(8 , StatsListViewModel . StatsSection . DAYS )
6568 return this
6669 }
6770
@@ -96,7 +99,7 @@ class StatsPage {
9699 )
97100 )
98101 )
99- cardStructure.check(ViewAssertions .matches(ViewMatchers .isCompletelyDisplayed ()))
102+ cardStructure.check(ViewAssertions .matches(ViewMatchers .isDisplayed ()))
100103 return this
101104 }
102105
@@ -121,7 +124,7 @@ class StatsPage {
121124 )
122125 )
123126 )
124- cardStructure.check(ViewAssertions .matches(ViewMatchers .isCompletelyDisplayed ()))
127+ cardStructure.check(ViewAssertions .matches(ViewMatchers .isDisplayed ()))
125128 }
126129 }
127130
@@ -160,15 +163,14 @@ class StatsPage {
160163 return this
161164 }
162165
163- private fun scrollToCard (cardHeader : String ) {
164- val card = Espresso .onView(
165- Matchers .allOf(
166- ViewMatchers .isDescendantOfA(visibleCoordinatorLayout),
167- ViewMatchers .withId(R .id.stats_block_list),
168- ViewMatchers .hasDescendant(ViewMatchers .withText(cardHeader))
169- )
166+ private fun scrollToCard (viewholderPosition : Int , section : StatsListViewModel .StatsSection ) {
167+ WPSupportUtils .idleFor(2000 )
168+ Espresso .onView(Matchers .allOf(
169+ ViewMatchers .withTagValue(Matchers .`is `(section.name))
170+ )).perform(
171+ RecyclerViewActions .scrollToPosition<ViewHolder >(viewholderPosition)
170172 )
171- WPSupportUtils .scrollIntoView( R .id.statsPager, card, 0.5 .toFloat() )
173+ WPSupportUtils .idleFor( 2000 )
172174 }
173175
174176 companion object {
0 commit comments