Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions WooCommerce/UITestsFoundation/Screens/MyStore/MyStoreScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,46 @@ public final class MyStoreScreen: ScreenObject {
topBannerCloseButton.tap()
return self
}

func tapTimeframeTab(timeframe: String) -> MyStoreScreen {
app.cells.staticTexts[timeframe].tap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT of using the parent cell identifier instead? Example for This Month:

Screenshot 2022-12-05 at 15 15 28

This will make the test less dependent on the localization during tab selection (you will still have a human-readable interval mentioned in the assertion of the chart hint text).

Suggested change
func tapTimeframeTab(timeframe: String) -> MyStoreScreen {
app.cells.staticTexts[timeframe].tap()
func tapTimeframeTab(timeframeID: String) -> MyStoreScreen {
app.cells[timeframeID].tap()

The respective values for IDs to use in calling functions would be:

  • period-data-today-tab
  • period-data-thisWeek-tab
  • period-data-thisMonth-tab
  • period-data-thisYear-tab

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yup i agree with your point, this is updated in 27a1d7c

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this @jostnes!


return self
}

public func goToThisWeekTab() -> MyStoreScreen {
return tapTimeframeTab(timeframe: "This Week")
}

public func goToThisMonthTab() -> MyStoreScreen {
return tapTimeframeTab(timeframe: "This Month")
}

public func goToThisYearTab() -> MyStoreScreen {
return tapTimeframeTab(timeframe: "This Year")
}

func verifyStatsForTimeframeLoaded(timeframe: String) -> MyStoreScreen {
let textPredicate = NSPredicate(format: "label MATCHES %@", "Store revenue chart \(timeframe)")
XCTAssertTrue(app.images.containing(textPredicate).element.exists, "\(timeframe) chart not displayed")

return self
}
Comment on lines +49 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT of extending this asserting function with one more check: making sure that the tab of interest is selected? Example of This Year tab being selected:

SCR-20221205-lqg

(For this you'll also need to provide the second argument with cell ID):

Suggested change
func verifyStatsForTimeframeLoaded(timeframe: String) -> MyStoreScreen {
let textPredicate = NSPredicate(format: "label MATCHES %@", "Store revenue chart \(timeframe)")
XCTAssertTrue(app.images.containing(textPredicate).element.exists, "\(timeframe) chart not displayed")
return self
}
func verifyStatsForTimeframeLoaded(timeframe: String, timeframeID: String) -> MyStoreScreen {
let textPredicate = NSPredicate(format: "label MATCHES %@", "Store revenue chart \(timeframe)")
XCTAssertTrue(app.images.containing(textPredicate).element.exists, "\(timeframe) chart not displayed")
XCTAssertTrue(app.cells[timeframeID].isSelected, "\(timeframeID) cell not selected")
return self
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm leaving this as is, for now. thinking of a scenario where the tab is not selected (e.g. if tap didn't work), the image wouldn't change too so i think that extra check isn't necessary for this test to work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally 👍 to leave it with no changes, just wanted to extend my thoughts about the reason for proposal: as you say, the test will still fail if tab selection did not work, because of incorrect chart name. My proposal was more about increasing the test coverage (e.g. checking for one field in the person details page VS checking for all fields). Also, it would cover a totally made up scenario, when tab switch animation did not work, but the screen itself is updated with correct chart and data. (just my thoughts behind it, let's leave it as it is now).


public func verifyTodayStatsLoaded() -> MyStoreScreen {
return verifyStatsForTimeframeLoaded(timeframe: "Today")
}

public func verifyThisWeekStatsLoaded() -> MyStoreScreen {
return verifyStatsForTimeframeLoaded(timeframe: "This Week")
}

public func verifyThisMonthStatsLoaded() -> MyStoreScreen {
return verifyStatsForTimeframeLoaded(timeframe: "This Month")
}

@discardableResult
public func verifyThisYearStatsLoaded() -> MyStoreScreen {
return verifyStatsForTimeframeLoaded(timeframe: "This Year")
}
}
2 changes: 1 addition & 1 deletion WooCommerce/WooCommerceUITests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The following flows are covered/planned to be covered by UI tests. Tests that ar
- [ ] Log in with Apple
- [ ] Log in with Google
2. My Store
- [ ] Stats Today, This Week, This Month, This Year load
- [x] Stats Today, This Week, This Month, This Year load
- [ ] Tap chart on stats
3. Orders
- [x] Orders list loads
Expand Down
15 changes: 8 additions & 7 deletions WooCommerce/WooCommerceUITests/Tests/StatsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import XCTest
final class StatsTests: XCTestCase {

override func setUpWithError() throws {
try skipTillImplemented()
continueAfterFailure = false

// UI tests must launch the application that they test.
Expand All @@ -15,12 +14,14 @@ final class StatsTests: XCTestCase {
try LoginFlow.logInWithWPcom()
}

func skipped_test_load_stats_screen() throws {
func test_load_stats_screen() throws {
try TabNavComponent().goToMyStoreScreen()
}

func skipTillImplemented(file: StaticString = #file, line: UInt = #line) throws {
try XCTSkipIf(true,
"Skipping until test is properly implemented", file: file, line: line)
.verifyTodayStatsLoaded()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might look redundant (and it most probably is), but I had an idea of also adding a function that selects the Today tab, and calling it before checking the Today stats.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm leaving this as is too, i think not adding that extra tap ensures that upon signing in the merchant would land on the expected tab (Today) instead of other tabs

.goToThisWeekTab()
.verifyThisWeekStatsLoaded()
.goToThisMonthTab()
.verifyThisMonthStatsLoaded()
.goToThisYearTab()
.verifyThisYearStatsLoaded()
}
}