Files
Reflect/Tests iOS/NotesTests.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

72 lines
2.4 KiB
Swift

//
// NotesTests.swift
// Tests iOS
//
// Notes add/edit and emoji support tests.
//
import XCTest
final class NotesTests: BaseUITestCase {
override var seedFixture: String? { "single_mood" }
// MARK: - Helpers
/// Opens the note editor from the entry detail screen.
private func openNoteEditor() -> NoteEditorScreen {
let noteButton = app.element(UITestID.EntryDetail.noteButton)
let noteArea = app.element(UITestID.EntryDetail.noteArea)
if noteArea.waitForExistence(timeout: defaultTimeout) {
noteArea.forceTap()
} else {
noteButton.waitForExistenceOrFail(timeout: defaultTimeout, message: "Neither note area nor note button found")
noteButton.forceTap()
}
let noteEditor = NoteEditorScreen(app: app)
noteEditor.assertVisible()
return noteEditor
}
// MARK: - Tests
/// TC-026 / TC-132: Add a note to an existing entry and verify it is saved.
func testAddNote_ToExistingEntry() {
app.firstEntryRow.waitForExistenceOrFail(timeout: navigationTimeout, message: "No entry row found")
app.firstEntryRow.forceTap()
let detailScreen = EntryDetailScreen(app: app)
detailScreen.assertVisible()
let noteEditor = openNoteEditor()
noteEditor.clearAndTypeNote("Had a great day today!")
noteEditor.save()
noteEditor.assertDismissed()
// Verify the note text is visible in the detail view
let noteText = app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Had a great day today!")).firstMatch
noteText.waitForExistenceOrFail(timeout: navigationTimeout, message: "Saved note text should be visible in entry detail")
detailScreen.dismiss()
detailScreen.assertDismissed()
}
/// TC-135: Add a note with special characters and verify save completes.
func testAddNote_WithSpecialCharacters() {
app.firstEntryRow.waitForExistenceOrFail(timeout: navigationTimeout, message: "No entry row found")
app.firstEntryRow.forceTap()
let detailScreen = EntryDetailScreen(app: app)
detailScreen.assertVisible()
let noteEditor = openNoteEditor()
noteEditor.clearAndTypeNote("Feeling amazing! #100")
noteEditor.save()
noteEditor.assertDismissed()
detailScreen.dismiss()
detailScreen.assertDismissed()
}
}