Stabilize iOS UI test foundation and fix flaky suites

This commit is contained in:
Trey t
2026-02-17 22:24:08 -06:00
parent c28d7a59eb
commit 56ac783219
38 changed files with 543 additions and 585 deletions

View File

@@ -12,9 +12,9 @@ struct EntryDetailScreen {
// MARK: - Elements
var navigationTitle: XCUIElement { app.navigationBars["Entry Details"] }
var doneButton: XCUIElement { app.buttons["entry_detail_done"] }
var deleteButton: XCUIElement { app.buttons["entry_detail_delete"] }
var sheet: XCUIElement { app.element(UITestID.EntryDetail.sheet) }
var doneButton: XCUIElement { app.element(UITestID.EntryDetail.doneButton) }
var deleteButton: XCUIElement { app.element(UITestID.EntryDetail.deleteButton) }
var moodGrid: XCUIElement { app.otherElements["entry_detail_mood_grid"] }
/// Mood buttons inside the detail sheet's mood grid.
@@ -27,32 +27,39 @@ struct EntryDetailScreen {
func dismiss() {
let button = doneButton
_ = button.waitForExistence(timeout: 5)
button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
button.tapWhenReady(timeout: 5)
}
func selectMood(_ mood: MoodChoice) {
let button = moodButton(for: mood)
_ = button.waitForExistence(timeout: 5)
button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
button.tapWhenReady(timeout: 5)
}
func deleteEntry() {
let button = deleteButton
_ = button.waitForExistence(timeout: 5)
button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
// Confirm the delete alert
let deleteAlert = app.alerts["Delete Entry"]
let confirmButton = deleteAlert.buttons["Delete"]
_ = confirmButton.waitForExistence(timeout: 5)
confirmButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
button.tapWhenReady(timeout: 5)
let alert = app.alerts.firstMatch
guard alert.waitForExistence(timeout: 5) else { return }
let deleteButton = alert.buttons.matching(NSPredicate(format: "label CONTAINS[cd] %@", "Delete")).firstMatch
if deleteButton.waitForExistence(timeout: 2) {
deleteButton.tapWhenReady()
return
}
// Fallback: destructive action is usually the last button.
let fallback = alert.buttons.element(boundBy: max(alert.buttons.count - 1, 0))
if fallback.exists {
fallback.tapWhenReady()
}
}
// MARK: - Assertions
func assertVisible(file: StaticString = #file, line: UInt = #line) {
XCTAssertTrue(
navigationTitle.waitForExistence(timeout: 5),
sheet.waitForExistence(timeout: 5),
"Entry Detail sheet should be visible",
file: file, line: line
)
@@ -60,7 +67,7 @@ struct EntryDetailScreen {
func assertDismissed(file: StaticString = #file, line: UInt = #line) {
XCTAssertTrue(
navigationTitle.waitForDisappearance(timeout: 5),
sheet.waitForDisappearance(timeout: 5),
"Entry Detail sheet should be dismissed",
file: file, line: line
)