Rewrite all UI tests following fail-fast TEST_RULES patterns
Rewrote 60+ test files to follow honeydue-style test guidelines:
- defaultTimeout=2s, navigationTimeout=5s — fail fast, no long waits
- No coordinate taps (except onboarding paged TabView swipes)
- No sleep(), no retry loops
- No guard...else { return } silent passes — XCTFail everywhere
- All elements by accessibility ID via UITestID constants
- Screen objects for all navigation/actions/assertions
- One logical assertion per test method
Added missing accessibility identifiers to app views:
- MonthView.swift: added AccessibilityID.MonthView.grid to ScrollView
- YearView.swift: added AccessibilityID.YearView.heatmap to ScrollView
Framework rewrites:
- BaseUITestCase: added session ID, localeArguments, extraLaunchArguments
- WaitHelpers: waitForExistenceOrFail, waitUntilHittableOrFail,
waitForNonExistence, scrollIntoView, forceTap
- All 7 screen objects rewritten with fail-fast semantics
- TEST_RULES.md added with non-negotiable rules
Known remaining issues:
- OnboardingTests: paged TabView swipes unreliable on iOS 26 simulator
- SettingsLegalLinksTests: EULA/Privacy buttons too deep in DEBUG scroll
- Customization horizontal picker scrolling needs further tuning
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,70 +10,55 @@ import XCTest
|
||||
struct EntryDetailScreen {
|
||||
let app: XCUIApplication
|
||||
|
||||
private let defaultTimeout: TimeInterval = 2
|
||||
private let navigationTimeout: TimeInterval = 5
|
||||
|
||||
// MARK: - Elements
|
||||
|
||||
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.
|
||||
/// Match by the mood_button_ identifier prefix to avoid matching entry rows.
|
||||
func moodButton(for mood: MoodChoice) -> XCUIElement {
|
||||
app.buttons["mood_button_\(mood.rawValue)"]
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
func dismiss() {
|
||||
let button = doneButton
|
||||
button.tapWhenReady(timeout: 5)
|
||||
func dismiss(file: StaticString = #filePath, line: UInt = #line) {
|
||||
doneButton
|
||||
.waitUntilHittableOrFail(timeout: defaultTimeout, message: "Done button should be hittable", file: file, line: line)
|
||||
.forceTap(file: file, line: line)
|
||||
}
|
||||
|
||||
func selectMood(_ mood: MoodChoice) {
|
||||
let button = moodButton(for: mood)
|
||||
button.tapWhenReady(timeout: 5)
|
||||
func selectMood(_ mood: MoodChoice, file: StaticString = #filePath, line: UInt = #line) {
|
||||
moodButton(for: mood)
|
||||
.waitUntilHittableOrFail(timeout: defaultTimeout, message: "Mood button '\(mood.rawValue)' should be hittable", file: file, line: line)
|
||||
.forceTap(file: file, line: line)
|
||||
}
|
||||
|
||||
func deleteEntry() {
|
||||
let button = deleteButton
|
||||
// Scroll down to reveal delete button (may be off-screen below reflection/notes/photo sections)
|
||||
if button.waitForExistence(timeout: 3) && !button.isHittable {
|
||||
sheet.swipeUp()
|
||||
}
|
||||
button.tapWhenReady(timeout: 5)
|
||||
func deleteEntry(file: StaticString = #filePath, line: UInt = #line) {
|
||||
deleteButton.scrollIntoView(in: sheet, direction: .up, maxSwipes: 3, file: file, line: line)
|
||||
deleteButton.forceTap(file: file, line: line)
|
||||
|
||||
let alert = app.alerts.firstMatch
|
||||
guard alert.waitForExistence(timeout: 5) else { return }
|
||||
alert.waitForExistenceOrFail(timeout: navigationTimeout, message: "Delete confirmation alert should appear", file: file, line: line)
|
||||
|
||||
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()
|
||||
}
|
||||
let confirmDelete = alert.buttons.matching(NSPredicate(format: "label CONTAINS[cd] %@", "Delete")).firstMatch
|
||||
confirmDelete
|
||||
.waitForExistenceOrFail(timeout: defaultTimeout, message: "Delete button in alert should exist", file: file, line: line)
|
||||
.forceTap(file: file, line: line)
|
||||
}
|
||||
|
||||
// MARK: - Assertions
|
||||
|
||||
func assertVisible(file: StaticString = #file, line: UInt = #line) {
|
||||
XCTAssertTrue(
|
||||
sheet.waitForExistence(timeout: 5),
|
||||
"Entry Detail sheet should be visible",
|
||||
file: file, line: line
|
||||
)
|
||||
@discardableResult
|
||||
func assertVisible(file: StaticString = #filePath, line: UInt = #line) -> EntryDetailScreen {
|
||||
sheet.waitForExistenceOrFail(timeout: navigationTimeout, message: "Entry Detail sheet should be visible", file: file, line: line)
|
||||
return self
|
||||
}
|
||||
|
||||
func assertDismissed(file: StaticString = #file, line: UInt = #line) {
|
||||
XCTAssertTrue(
|
||||
sheet.waitForDisappearance(timeout: 5),
|
||||
"Entry Detail sheet should be dismissed",
|
||||
file: file, line: line
|
||||
)
|
||||
func assertDismissed(file: StaticString = #filePath, line: UInt = #line) {
|
||||
sheet.waitForNonExistence(timeout: navigationTimeout, message: "Entry Detail sheet should be dismissed", file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user