Skip to content

Commit dfd5f09

Browse files
authored
Merge pull request #18578 from wordpress-mobile/add-pages-card-ui-test
[UI Tests] Added a UI test for "Pages" dashboard card navigation.
2 parents 39ecbc7 + 691f307 commit dfd5f09

File tree

10 files changed

+573
-51
lines changed

10 files changed

+573
-51
lines changed

WordPress/src/androidTest/java/org/wordpress/android/e2e/DashboardTests.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,19 @@ class DashboardTests : BaseTest() {
2828
.tapDomainsCard()
2929
.assertDomainsScreenLoaded()
3030
}
31+
32+
@Test
33+
fun e2ePagesCardNavigation() {
34+
MySitesPage()
35+
.scrollToPagesCard()
36+
.assertPagesCard()
37+
.assertPagesCardHasPage("Blog")
38+
.assertPagesCardHasPage("Cart")
39+
.assertPagesCardHasPage("Shop")
40+
.tapPagesCard()
41+
.assertPagesScreenLoaded()
42+
.assertPagesScreenHasPage("Blog")
43+
.assertPagesScreenHasPage("Cart")
44+
.assertPagesScreenHasPage("Shop")
45+
}
3146
}

WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/MySitesPage.kt

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,22 @@ class MySitesPage {
283283
}
284284

285285
private fun scrollToCard(elementID: Int): MySitesPage {
286-
WPSupportUtils.waitForElementToBeDisplayed(elementID)
287286
Espresso.onView(ViewMatchers.withId(elementID))
288287
.perform(scrollTo())
289288

290289
return this
291290
}
292291

293-
fun scrollToDomainsCard(): MySitesPage {
294-
return scrollToCard(R.id.dashboard_card_domain_cta)
295-
}
296-
297292
private fun tapCard(elementID: Int) {
298293
WPSupportUtils.clickOn(elementID)
299294
}
300295

296+
// "Domains" Dashboard Card
297+
298+
fun scrollToDomainsCard(): MySitesPage {
299+
return scrollToCard(R.id.dashboard_card_domain_cta)
300+
}
301+
301302
fun tapDomainsCard(): DomainsScreen {
302303
tapCard(R.id.dashboard_card_domain_cta)
303304
return DomainsScreen()
@@ -313,7 +314,6 @@ class MySitesPage {
313314

314315
ViewMatchers.hasDescendant(
315316
Matchers.allOf(
316-
317317
ViewMatchers.withText(R.string.dashboard_card_domain_title),
318318
ViewMatchers.withId(R.id.dashboard_card_domain_title),
319319
)
@@ -324,8 +324,64 @@ class MySitesPage {
324324
ViewMatchers.withText(R.string.dashboard_card_domain_sub_title),
325325
ViewMatchers.withId(R.id.dashboard_card_domain_sub_title),
326326
)
327+
)
328+
)
329+
)
330+
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
331+
332+
return this
333+
}
334+
335+
// "Pages" Dashboard Card
336+
337+
fun scrollToPagesCard(): MySitesPage {
338+
return scrollToCard(R.id.dashboard_card_pages)
339+
}
340+
341+
fun tapPagesCard(): PagesScreen {
342+
tapCard(R.id.dashboard_card_pages)
343+
return PagesScreen()
344+
}
345+
346+
fun assertPagesCard(): MySitesPage {
347+
Espresso.onView(
348+
Matchers.allOf(
349+
ViewMatchers.withId(R.id.dashboard_card_pages),
350+
ViewMatchers.isDescendantOfA(ViewMatchers.withId(R.id.dashboard_cards)),
351+
352+
ViewMatchers.hasDescendant(
353+
Matchers.allOf(
354+
ViewMatchers.withText(R.string.dashboard_pages_card_title),
355+
ViewMatchers.withId(R.id.my_site_card_toolbar_title),
356+
)
327357
),
328358

359+
ViewMatchers.hasDescendant(ViewMatchers.withId(R.id.my_site_card_toolbar_more)),
360+
361+
ViewMatchers.hasDescendant(
362+
Matchers.allOf(
363+
ViewMatchers.withText(R.string.dashboard_pages_card_create_another_page_button),
364+
ViewMatchers.withId(R.id.link_label),
365+
)
366+
)
367+
)
368+
)
369+
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
370+
371+
return this
372+
}
373+
374+
fun assertPagesCardHasPage(pageTitle: String): MySitesPage {
375+
Espresso.onView(
376+
Matchers.allOf(
377+
ViewMatchers.withId(R.id.dashboard_card_pages),
378+
379+
ViewMatchers.hasDescendant(
380+
Matchers.allOf(
381+
ViewMatchers.withText(pageTitle),
382+
ViewMatchers.withId(R.id.title),
383+
)
384+
)
329385
)
330386
)
331387
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.wordpress.android.e2e.pages
2+
3+
import androidx.test.espresso.Espresso
4+
import androidx.test.espresso.ViewInteraction
5+
import androidx.test.espresso.assertion.ViewAssertions
6+
import androidx.test.espresso.matcher.ViewMatchers
7+
import org.hamcrest.Matchers
8+
import org.wordpress.android.R
9+
import org.wordpress.android.support.WPSupportUtils
10+
11+
class PagesScreen {
12+
fun assertPagesScreenLoaded(): PagesScreen {
13+
WPSupportUtils.waitForElementToBeDisplayed(pagesListScreenNavbar)
14+
return this
15+
}
16+
17+
fun assertPagesScreenHasPage(pageTitle: String): PagesScreen {
18+
Espresso.onView(
19+
Matchers.allOf(
20+
ViewMatchers.withId(R.id.page_list_layout),
21+
22+
ViewMatchers.hasDescendant(
23+
Matchers.allOf(
24+
ViewMatchers.withText(pageTitle),
25+
ViewMatchers.withId(R.id.page_title),
26+
)
27+
)
28+
)
29+
)
30+
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
31+
32+
return this
33+
}
34+
35+
companion object {
36+
var pagesListScreenNavbar: ViewInteraction = Espresso.onView(
37+
Matchers.allOf(
38+
ViewMatchers.withId(R.id.toolbar),
39+
ViewMatchers.hasDescendant(ViewMatchers.withText(R.string.pages)),
40+
)
41+
)
42+
}
43+
}

WordPress/src/main/res/layout/my_site_pages_card_with_page_items.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/dashboard_card_pages"
45
style="@style/WordPress.CardView.Unelevated"
56
android:layout_width="match_parent"
67
android:layout_height="wrap_content">
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"request": {
3+
"method": "GET",
4+
"urlPattern": "/wpcom/v2/sites/106707880/dashboard/cards-data(/)?($|\\?.*)"
5+
},
6+
"response": {
7+
"status": 200,
8+
"jsonBody": {
9+
10+
"todays_stats": {
11+
"views": 56,
12+
"visitors": 44,
13+
"likes": 19,
14+
"comments": 0
15+
},
16+
"posts": {
17+
"has_published": true,
18+
"draft": [],
19+
"scheduled": []
20+
},
21+
"pages": [
22+
{
23+
"id": 51,
24+
"title": "Blog",
25+
"content": "Introduce yourself and your blog My Latest Posts • • • • • •",
26+
"status": "publish",
27+
"modified": "2023-05-18 10:33:38",
28+
"date": "2023-05-18 10:33:38"
29+
},
30+
{
31+
"id": 30,
32+
"title": "Cart",
33+
"content": "",
34+
"status": "publish",
35+
"modified": "2023-02-03 09:46:32",
36+
"date": "2023-02-03 09:46:32"
37+
},
38+
{
39+
"id": 31,
40+
"title": "Shop",
41+
"content": "",
42+
"status": "publish",
43+
"modified": "2023-02-03 09:46:32",
44+
"date": "2023-02-03 09:46:32"
45+
}
46+
],
47+
48+
"activity": {
49+
"@context": "https://www.w3.org/ns/activitystreams",
50+
"summary": "Activity log",
51+
"type": "OrderedCollection",
52+
"totalItems": 3,
53+
"page": 1,
54+
"totalPages": 1,
55+
"itemsPerPage": 5,
56+
"id": "https://public-api.wordpress.com/wpcom/v2/sites/106707880/activity",
57+
"oldestItemTs": 1654043700542,
58+
"first": "https://public-api.wordpress.com/wpcom/v2/sites/106707880/activity?page=1",
59+
"last": "https://public-api.wordpress.com/wpcom/v2/sites/106707880/activity?page=1",
60+
"current": {
61+
"type": "OrderedCollectionPage",
62+
"id": "https://public-api.wordpress.com/wpcom/v2/sites/106707880/activity",
63+
"totalItems": 1,
64+
"orderedItems": [
65+
{
66+
"summary": "Setting changed",
67+
"content": {
68+
"text": "Enabled Jetpack Social for automatic social sharing"
69+
},
70+
"name": "setting__changed_jetpack_module_publicize",
71+
"actor": {
72+
"type": "Person",
73+
"name": "demo",
74+
"external_user_id": 1,
75+
"wpcom_user_id": 195654479,
76+
"icon": {
77+
"type": "Image",
78+
"url": "https://secure.gravatar.com/avatar/eea057209f5e29d6ca4103bc165d645b?s=96&d=mm&r=g",
79+
"width": 96,
80+
"height": 96
81+
},
82+
"role": "administrator"
83+
},
84+
"type": "Announce",
85+
"published": "2023-04-04T10:33:09.300+00:00",
86+
"generator": {
87+
"jetpack_version": 0,
88+
"blog_id": 106707880
89+
},
90+
"is_rewindable": false,
91+
"rewind_id": "1680604388.4567",
92+
"gridicon": "cog",
93+
"status": null,
94+
"activity_id": "6gjTS4cBfytF4jpL6MFT",
95+
"is_discarded": false
96+
},
97+
{
98+
"summary": "Site owner connected",
99+
"content": {
100+
"text": "The Jetpack connection is now complete. Welcome!"
101+
},
102+
"name": "jetpack__site_owner_connected",
103+
"actor": {
104+
"type": "Person",
105+
"name": "Kevin Jorge",
106+
"external_user_id": 1,
107+
"wpcom_user_id": 11111111,
108+
"icon": {
109+
"type": "Image",
110+
"url": "https://secure.gravatar.com/avatar/eea057209f5e29d6ca4103bc165d645b?s=96&d=mm&r=g",
111+
"width": 96,
112+
"height": 96
113+
},
114+
"role": "administrator"
115+
},
116+
"type": "Announce",
117+
"published": "2023-04-04T10:33:05.614+00:00",
118+
"generator": {
119+
"jetpack_version": 0,
120+
"blog_id": 106707880
121+
},
122+
"is_rewindable": false,
123+
"rewind_id": "1680604385.6144",
124+
"gridicon": "plans",
125+
"status": "success",
126+
"activity_id": "avfTS4cB98Gh8vy65ZU4",
127+
"is_discarded": false
128+
},
129+
{
130+
"summary": "Site connected",
131+
"content": {
132+
"text": "This site is connected to Jetpack."
133+
},
134+
"name": "jetpack__site_connected",
135+
"actor": {
136+
"type": "Application",
137+
"name": "Jetpack"
138+
},
139+
"type": "Announce",
140+
"published": "2023-04-04T10:32:54.647+00:00",
141+
"generator": {
142+
"jetpack_version": 0,
143+
"blog_id": 106707880
144+
},
145+
"is_rewindable": false,
146+
"rewind_id": "1680604374.6466",
147+
"gridicon": "plans",
148+
"status": "success",
149+
"activity_id": "XvfTS4cB98Gh8vy6sI2-",
150+
"is_discarded": false
151+
}
152+
]
153+
}
154+
}
155+
156+
}
157+
}
158+
}

libs/mocks/src/main/assets/mocks/mappings/wpcom/mobile/feature-flags.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"response": {
2727
"status": 200,
2828
"jsonBody": {
29-
"dashboard_card_domain": true
29+
"dashboard_card_domain": true,
30+
"dashboard_card_pages": true
3031
}
3132
}
3233
}

0 commit comments

Comments
 (0)