Skip to content

Commit 5942bb3

Browse files
committed
Added a UI test for "Pages" dashboard card navigation.
1 parent e4e265d commit 5942bb3

File tree

10 files changed

+575
-51
lines changed

10 files changed

+575
-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: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,23 @@ class MySitesPage {
283283
}
284284

285285
private fun scrollToCard(elementID: Int): MySitesPage {
286-
WPSupportUtils.waitForElementToBeDisplayed(elementID)
286+
//WPSupportUtils.waitForElementToBeDisplayed(elementID)
287287
Espresso.onView(ViewMatchers.withId(elementID))
288288
.perform(scrollTo())
289289

290290
return this
291291
}
292292

293-
fun scrollToDomainsCard(): MySitesPage {
294-
return scrollToCard(R.id.dashboard_card_domain_cta)
295-
}
296-
297293
private fun tapCard(elementID: Int) {
298294
WPSupportUtils.clickOn(elementID)
299295
}
300296

297+
// "Domains" Dashboard Card
298+
299+
fun scrollToDomainsCard(): MySitesPage {
300+
return scrollToCard(R.id.dashboard_card_domain_cta)
301+
}
302+
301303
fun tapDomainsCard(): DomainsScreen {
302304
tapCard(R.id.dashboard_card_domain_cta)
303305
return DomainsScreen()
@@ -313,7 +315,6 @@ class MySitesPage {
313315

314316
ViewMatchers.hasDescendant(
315317
Matchers.allOf(
316-
317318
ViewMatchers.withText(R.string.dashboard_card_domain_title),
318319
ViewMatchers.withId(R.id.dashboard_card_domain_title),
319320
)
@@ -324,8 +325,64 @@ class MySitesPage {
324325
ViewMatchers.withText(R.string.dashboard_card_domain_sub_title),
325326
ViewMatchers.withId(R.id.dashboard_card_domain_sub_title),
326327
)
328+
)
329+
)
330+
)
331+
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
332+
333+
return this
334+
}
335+
336+
// "Pages" Dashboard Card
337+
338+
fun scrollToPagesCard(): MySitesPage {
339+
return scrollToCard(R.id.dashboard_card_pages)
340+
}
341+
342+
fun tapPagesCard(): PagesScreen {
343+
tapCard(R.id.dashboard_card_pages)
344+
return PagesScreen()
345+
}
346+
347+
fun assertPagesCard(): MySitesPage {
348+
Espresso.onView(
349+
Matchers.allOf(
350+
ViewMatchers.withId(R.id.dashboard_card_pages),
351+
ViewMatchers.isDescendantOfA(ViewMatchers.withId(R.id.dashboard_cards)),
352+
353+
ViewMatchers.hasDescendant(
354+
Matchers.allOf(
355+
ViewMatchers.withText(R.string.dashboard_pages_card_title),
356+
ViewMatchers.withId(R.id.my_site_card_toolbar_title),
357+
)
327358
),
328359

360+
ViewMatchers.hasDescendant(ViewMatchers.withId(R.id.my_site_card_toolbar_more)),
361+
362+
ViewMatchers.hasDescendant(
363+
Matchers.allOf(
364+
ViewMatchers.withText(R.string.dashboard_pages_card_create_another_page_button),
365+
ViewMatchers.withId(R.id.link_label),
366+
)
367+
)
368+
)
369+
)
370+
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
371+
372+
return this
373+
}
374+
375+
fun assertPagesCardHasPage(pageTitle: String): MySitesPage {
376+
Espresso.onView(
377+
Matchers.allOf(
378+
ViewMatchers.withId(R.id.dashboard_card_pages),
379+
380+
ViewMatchers.hasDescendant(
381+
Matchers.allOf(
382+
ViewMatchers.withText(pageTitle),
383+
ViewMatchers.withId(R.id.title),
384+
)
385+
)
329386
)
330387
)
331388
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
13+
fun assertPagesScreenLoaded(): PagesScreen {
14+
WPSupportUtils.waitForElementToBeDisplayed(pagesListScreenNavbar)
15+
return this
16+
}
17+
18+
fun assertPagesScreenHasPage(pageTitle: String): PagesScreen {
19+
Espresso.onView(
20+
Matchers.allOf(
21+
ViewMatchers.withId(R.id.page_list_layout),
22+
23+
ViewMatchers.hasDescendant(
24+
Matchers.allOf(
25+
ViewMatchers.withText(pageTitle),
26+
ViewMatchers.withId(R.id.page_title),
27+
)
28+
)
29+
)
30+
)
31+
.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed()))
32+
33+
return this
34+
}
35+
36+
companion object {
37+
var pagesListScreenNavbar: ViewInteraction = Espresso.onView(
38+
Matchers.allOf(
39+
ViewMatchers.withId(R.id.toolbar),
40+
ViewMatchers.hasDescendant(ViewMatchers.withText(R.string.pages)),
41+
)
42+
)
43+
}
44+
}

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)