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:
Trey T
2026-03-24 17:00:30 -05:00
parent 2ef1c1ec51
commit d97db4910e
70 changed files with 1609 additions and 1874 deletions

View File

@@ -10,88 +10,59 @@ import XCTest
struct DayScreen {
let app: XCUIApplication
// MARK: - Mood Buttons (via accessibilityIdentifier)
private let defaultTimeout: TimeInterval = 2
private let navigationTimeout: TimeInterval = 5
var greatButton: XCUIElement { app.buttons["mood_button_great"] }
var goodButton: XCUIElement { app.buttons["mood_button_good"] }
var averageButton: XCUIElement { app.buttons["mood_button_average"] }
var badButton: XCUIElement { app.buttons["mood_button_bad"] }
var horribleButton: XCUIElement { app.buttons["mood_button_horrible"] }
// MARK: - Elements
/// The mood header container
var moodHeader: XCUIElement { app.element(UITestID.Day.moodHeader) }
// MARK: - Entry List
func moodButton(for mood: MoodChoice) -> XCUIElement {
app.buttons["mood_button_\(mood.rawValue)"]
}
/// Find an entry row by its raw identifier date payload (yyyyMMdd).
func entryRow(dateString: String) -> XCUIElement {
app.element("\(UITestID.Day.entryRowPrefix)\(dateString)")
}
var anyEntryRow: XCUIElement {
app.firstEntryRow
}
var anyEntryRow: XCUIElement { app.firstEntryRow }
// MARK: - Actions
/// Tap a mood button by mood name. Waits for the celebration animation to complete.
func logMood(_ mood: MoodChoice, file: StaticString = #file, line: UInt = #line) {
let button = moodButton(for: mood)
guard button.waitForExistence(timeout: 5) else {
XCTFail("Mood button '\(mood.rawValue)' not found", file: file, line: line)
return
}
button.tapWhenReady(timeout: 5, file: file, line: line)
// Wait for the celebration animation to finish and entry to appear.
// The mood header disappears after logging today's mood.
// Give extra time for animation + data save.
_ = moodHeader.waitForDisappearance(timeout: 8)
@discardableResult
func logMood(_ mood: MoodChoice, file: StaticString = #filePath, line: UInt = #line) -> DayScreen {
moodButton(for: mood)
.waitUntilHittableOrFail(timeout: defaultTimeout, message: "Mood button '\(mood.rawValue)' not hittable", file: file, line: line)
.forceTap(file: file, line: line)
moodHeader.waitForNonExistence(timeout: navigationTimeout, message: "Mood header should disappear after logging", file: file, line: line)
return self
}
// MARK: - Assertions
func assertMoodHeaderVisible(file: StaticString = #file, line: UInt = #line) {
XCTAssertTrue(
moodHeader.waitForExistence(timeout: 5),
"Mood voting header should be visible",
file: file, line: line
)
}
func assertMoodHeaderHidden(file: StaticString = #file, line: UInt = #line) {
// After logging, the header should either disappear or the buttons should not be hittable
let hidden = moodHeader.waitForDisappearance(timeout: 8)
XCTAssertTrue(hidden, "Mood header should be hidden after logging today's mood", file: file, line: line)
}
func assertEntryExists(dateString: String, file: StaticString = #file, line: UInt = #line) {
let row = entryRow(dateString: dateString)
XCTAssertTrue(
row.waitForExistence(timeout: 5),
"Entry row for \(dateString) should exist",
file: file, line: line
)
}
func assertAnyEntryExists(file: StaticString = #file, line: UInt = #line) {
XCTAssertTrue(
anyEntryRow.waitForExistence(timeout: 5),
"At least one entry row should exist",
file: file, line: line
)
}
// MARK: - Private
private func moodButton(for mood: MoodChoice) -> XCUIElement {
switch mood {
case .great: return greatButton
case .good: return goodButton
case .average: return averageButton
case .bad: return badButton
case .horrible: return horribleButton
@discardableResult
func assertVisible(file: StaticString = #filePath, line: UInt = #line) -> DayScreen {
// Day view shows mood header (empty state) OR entry rows (has data) either proves it loaded
let hasHeader = moodHeader.waitForExistence(timeout: navigationTimeout)
let hasEntry = !hasHeader && anyEntryRow.waitForExistence(timeout: defaultTimeout)
if !hasHeader && !hasEntry {
XCTFail("Day screen should show mood header or entry list", file: file, line: line)
}
return self
}
func assertMoodHeaderHidden(file: StaticString = #filePath, line: UInt = #line) {
moodHeader.waitForNonExistence(timeout: navigationTimeout, message: "Mood header should be hidden after logging", file: file, line: line)
}
func assertEntryExists(dateString: String, file: StaticString = #filePath, line: UInt = #line) {
entryRow(dateString: dateString)
.waitForExistenceOrFail(timeout: defaultTimeout, message: "Entry row for \(dateString) should exist", file: file, line: line)
}
func assertAnyEntryExists(file: StaticString = #filePath, line: UInt = #line) {
anyEntryRow
.waitForExistenceOrFail(timeout: defaultTimeout, message: "At least one entry row should exist", file: file, line: line)
}
}