Skip to content

Commit 267faeb

Browse files
authored
Stats Traffic: Update UI Tests (#22703)
2 parents b74685a + 6a131ba commit 267faeb

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

API-Mocks/WordPressMocks/src/main/assets/mocks/mappings/wpcom/feature_flags.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"dashboard_card_activity_log": true,
1515
"dashboard_card_domain": false,
1616
"dashboard_card_free_to_paid_plans": true,
17-
"dashboard_card_pages": true
17+
"dashboard_card_pages": true,
18+
"stats_traffic_tab": true
1819
}
1920
}
2021
}

WordPress/UITests/Tests/StatsTests.swift

+18-13
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ class StatsTests: XCTestCase {
3737
.assertStatsAreLoaded(insightsStats)
3838
}
3939

40-
func testYearsStatsLoadProperly() throws {
40+
func testTrafficYearsStatsLoadProperly() throws {
4141
let yearsStats: [String] = [
42-
"9,148",
43-
"+7,933 (653%)",
42+
"Views 9,148",
43+
"Visitors 4,216",
44+
"Likes 1,351",
45+
"Comments 0",
4446
"United States, 60",
4547
"Canada, 44",
4648
"Germany, 15",
@@ -49,19 +51,22 @@ class StatsTests: XCTestCase {
4951
"India, 121"
5052
]
5153

52-
let currentYear = Calendar.current.component(.year, from: Date())
53-
let yearsChartBars: [String] = [
54-
"Views, \(currentYear): 9148",
55-
"Visitors, \(currentYear): 4216",
56-
"Views, \(currentYear - 1): 1215",
57-
"Visitors, \(currentYear - 1): 632",
58-
"Views, \(currentYear - 2): 788",
59-
"Visitors, \(currentYear - 2): 465"
54+
let viewsYearsChartBars: [String] = [
55+
" J: 1218.0",
56+
" F: 1233.0"
57+
]
58+
59+
let visitorsYearsChartBars: [String] = [
60+
" J: 623.0",
61+
" F: 655.0"
6062
]
6163

6264
try StatsScreen()
63-
.switchTo(mode: "years")
65+
.switchTo(mode: "traffic")
66+
.selectByYearPeriod()
6467
.assertStatsAreLoaded(yearsStats)
65-
.assertChartIsLoaded(yearsChartBars)
68+
.assertChartIsLoaded(viewsYearsChartBars)
69+
.selectVisitorsTab()
70+
.assertChartIsLoaded(visitorsYearsChartBars)
6671
}
6772
}

WordPress/UITestsFoundation/Screens/StatsScreen.swift

+28
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ public class StatsScreen: ScreenObject {
77
$0.buttons["dismiss-customize-insights-cell"]
88
}
99

10+
private let byDayButtonGetter: (XCUIApplication) -> XCUIElement = {
11+
$0.buttons["By day"]
12+
}
13+
14+
private let visitorsButtonGetter: (XCUIApplication) -> XCUIElement = {
15+
$0.buttons["visitors"]
16+
}
17+
18+
private let byYearButtonGetter: (XCUIApplication) -> XCUIElement = {
19+
$0.buttons["By year"]
20+
}
21+
1022
private let statsDashboardGetter: (XCUIApplication) -> XCUIElement = {
1123
$0.otherElements["stats-dashboard"]
1224
}
1325

1426
var dismissCustomizeInsightsButton: XCUIElement { dismissCustomizeInsightsButtonGetter(app) }
27+
var byDayButton: XCUIElement { byDayButtonGetter(app) }
28+
var byYearButton: XCUIElement { byYearButtonGetter(app) }
29+
var visitorsButton: XCUIElement { visitorsButtonGetter(app) }
1530
var statsDashboard: XCUIElement { statsDashboardGetter(app) }
1631

1732
public init(app: XCUIApplication = XCUIApplication()) throws {
@@ -41,6 +56,19 @@ public class StatsScreen: ScreenObject {
4156
return true
4257
}
4358

59+
@discardableResult
60+
public func selectByYearPeriod() -> Self {
61+
byDayButton.tap()
62+
byYearButton.tap()
63+
return self
64+
}
65+
66+
@discardableResult
67+
public func selectVisitorsTab() -> Self {
68+
visitorsButton.tap()
69+
return self
70+
}
71+
4472
@discardableResult
4573
public func assertStatsAreLoaded(_ elements: [String]) -> Self {
4674
XCTAssert(verifyStatsLoaded(elements))

0 commit comments

Comments
 (0)