Stabilize iOS UI test foundation and fix flaky suites
This commit is contained in:
@@ -25,34 +25,15 @@ final class AppThemeTests: BaseUITestCase {
|
||||
let tabBar = TabBarScreen(app: app)
|
||||
let settingsScreen = tabBar.tapSettings()
|
||||
settingsScreen.assertVisible()
|
||||
settingsScreen.tapCustomizeTab()
|
||||
|
||||
// Tap Browse Themes button
|
||||
let browseButton = settingsScreen.browseThemesButton
|
||||
XCTAssertTrue(
|
||||
browseButton.waitForExistence(timeout: 5),
|
||||
"Browse Themes button should exist"
|
||||
)
|
||||
browseButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
|
||||
// Wait for the themes sheet to appear
|
||||
// Look for any theme card as an indicator that the sheet loaded
|
||||
let firstCard = app.descendants(matching: .any)
|
||||
.matching(identifier: "apptheme_card_zen garden")
|
||||
.firstMatch
|
||||
XCTAssertTrue(
|
||||
firstCard.waitForExistence(timeout: 5),
|
||||
"Themes sheet should appear with theme cards"
|
||||
)
|
||||
let customizeScreen = CustomizeScreen(app: app)
|
||||
XCTAssertTrue(customizeScreen.openThemePicker(), "Themes sheet should appear with theme cards")
|
||||
|
||||
// Verify all 12 theme cards are accessible (some may require scrolling)
|
||||
for theme in allThemes {
|
||||
let card = app.descendants(matching: .any)
|
||||
.matching(identifier: "apptheme_card_\(theme.lowercased())")
|
||||
.firstMatch
|
||||
if !card.exists {
|
||||
// Scroll down to find cards that are off-screen
|
||||
app.swipeUp()
|
||||
}
|
||||
let card = customizeScreen.appThemeCard(named: theme)
|
||||
if !card.exists { _ = app.swipeUntilExists(card, direction: .up, maxSwipes: 6) }
|
||||
XCTAssertTrue(
|
||||
card.waitForExistence(timeout: 3),
|
||||
"Theme card '\(theme)' should exist in the Browse Themes sheet"
|
||||
@@ -67,35 +48,28 @@ final class AppThemeTests: BaseUITestCase {
|
||||
let tabBar = TabBarScreen(app: app)
|
||||
let settingsScreen = tabBar.tapSettings()
|
||||
settingsScreen.assertVisible()
|
||||
settingsScreen.tapCustomizeTab()
|
||||
|
||||
// Open Browse Themes sheet
|
||||
let browseBtn = settingsScreen.browseThemesButton
|
||||
_ = browseBtn.waitForExistence(timeout: 5)
|
||||
browseBtn.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
|
||||
// Wait for sheet to load
|
||||
let firstCard = app.descendants(matching: .any)
|
||||
.matching(identifier: "apptheme_card_zen garden")
|
||||
.firstMatch
|
||||
_ = firstCard.waitForExistence(timeout: 5)
|
||||
let customizeScreen = CustomizeScreen(app: app)
|
||||
XCTAssertTrue(customizeScreen.openThemePicker(), "Browse Themes sheet should open")
|
||||
|
||||
// Tap a representative sample of themes: first, middle, last
|
||||
let sampled = ["Zen Garden", "Heartfelt", "Journal"]
|
||||
for theme in sampled {
|
||||
let card = app.descendants(matching: .any)
|
||||
.matching(identifier: "apptheme_card_\(theme.lowercased())")
|
||||
.firstMatch
|
||||
if !card.exists {
|
||||
app.swipeUp()
|
||||
}
|
||||
let card = customizeScreen.appThemeCard(named: theme)
|
||||
if !card.exists { _ = app.swipeUntilExists(card, direction: .up, maxSwipes: 6) }
|
||||
if card.waitForExistence(timeout: 3) {
|
||||
card.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
card.tapWhenReady(timeout: 3)
|
||||
|
||||
// A preview sheet or confirmation may appear — dismiss it
|
||||
// Look for an "Apply" or close button and tap if present
|
||||
let applyButton = app.buttons["Apply"]
|
||||
if applyButton.waitForExistence(timeout: 2) {
|
||||
applyButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
// Apply theme via stable accessibility id.
|
||||
let applyButton = app.element(UITestID.Customize.previewApplyButton)
|
||||
if applyButton.waitForExistence(timeout: 3) {
|
||||
applyButton.tapWhenReady()
|
||||
} else {
|
||||
let cancelButton = app.element(UITestID.Customize.previewCancelButton)
|
||||
if cancelButton.waitForExistence(timeout: 2) {
|
||||
cancelButton.tapWhenReady()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,9 +77,9 @@ final class AppThemeTests: BaseUITestCase {
|
||||
captureScreenshot(name: "themes_applied")
|
||||
|
||||
// Dismiss the themes sheet by swiping down or tapping Done
|
||||
let doneButton = app.buttons["Done"]
|
||||
let doneButton = app.element(UITestID.Customize.pickerDoneButton)
|
||||
if doneButton.waitForExistence(timeout: 2) {
|
||||
doneButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
doneButton.tapWhenReady()
|
||||
} else {
|
||||
// Swipe down to dismiss the sheet
|
||||
app.swipeDown()
|
||||
@@ -122,23 +96,7 @@ final class AppThemeTests: BaseUITestCase {
|
||||
|
||||
// Navigate to Day tab and verify no crash — entry row should still exist
|
||||
tabBar.tapDay()
|
||||
|
||||
// Wait for Day view to fully load after theme change.
|
||||
// Theme changes cause full view re-renders; the entry row or mood header should appear.
|
||||
let entryRow = app.descendants(matching: .any)
|
||||
.matching(NSPredicate(format: "identifier BEGINSWITH %@", "entry_row_"))
|
||||
.firstMatch
|
||||
let moodHeader = app.descendants(matching: .any)
|
||||
.matching(identifier: "mood_header")
|
||||
.firstMatch
|
||||
|
||||
// Either an entry row or the mood header should be visible (proves no crash)
|
||||
let entryVisible = entryRow.waitForExistence(timeout: 10)
|
||||
let headerVisible = moodHeader.waitForExistence(timeout: 3)
|
||||
XCTAssertTrue(
|
||||
entryVisible || headerVisible,
|
||||
"Entry row or mood header should still be visible after applying themes (no crash)"
|
||||
)
|
||||
assertDayContentVisible(timeout: 10)
|
||||
|
||||
captureScreenshot(name: "day_view_after_theme_change")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user