Files
Reflect/Tests iOS/Screens/DayScreen.swift
Trey T d97db4910e 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>
2026-03-24 17:00:30 -05:00

73 lines
2.7 KiB
Swift

//
// DayScreen.swift
// Tests iOS
//
// Screen object for the Day (main) view mood logging and entry list.
//
import XCTest
struct DayScreen {
let app: XCUIApplication
private let defaultTimeout: TimeInterval = 2
private let navigationTimeout: TimeInterval = 5
// MARK: - Elements
var moodHeader: XCUIElement { app.element(UITestID.Day.moodHeader) }
func moodButton(for mood: MoodChoice) -> XCUIElement {
app.buttons["mood_button_\(mood.rawValue)"]
}
func entryRow(dateString: String) -> XCUIElement {
app.element("\(UITestID.Day.entryRowPrefix)\(dateString)")
}
var anyEntryRow: XCUIElement { app.firstEntryRow }
// MARK: - Actions
@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
@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)
}
}
/// Represents the 5 selectable mood values for test code.
enum MoodChoice: String {
case great, good, average, bad, horrible
}