// // NoteEditTests.swift // Tests iOS // // TC-133: Edit an existing note. // TC-134: Long note (>1000 characters). // import XCTest final class NoteEditTests: 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 } /// Opens the first entry row and returns the detail screen. private func openFirstEntryDetail() -> EntryDetailScreen { app.firstEntryRow.waitForExistenceOrFail(timeout: navigationTimeout, message: "No entry row found") app.firstEntryRow.forceTap() let detail = EntryDetailScreen(app: app) detail.assertVisible() return detail } /// Adds a note with the given text and saves it. private func addNote(_ text: String) -> EntryDetailScreen { let detail = openFirstEntryDetail() let editor = openNoteEditor() editor.clearAndTypeNote(text) editor.save() editor.assertDismissed() return detail } // MARK: - Tests /// TC-133: Edit an existing note -- add note, reopen, change text, verify new text. func testEditNote_ExistingEntry() { let detail = addNote("Original note text") // Verify initial note is visible let originalText = app.staticTexts.matching( NSPredicate(format: "label CONTAINS %@", "Original note text") ).firstMatch originalText.waitForExistenceOrFail(timeout: navigationTimeout, message: "Original note should be visible") // Reopen and edit the note let editor = openNoteEditor() editor.clearAndTypeNote("Updated note text") editor.save() editor.assertDismissed() // Verify edited note is shown let updatedText = app.staticTexts.matching( NSPredicate(format: "label CONTAINS %@", "Updated note text") ).firstMatch updatedText.waitForExistenceOrFail(timeout: navigationTimeout, message: "Updated note text should be visible after editing") detail.dismiss() detail.assertDismissed() } /// TC-134: Add a long note (>1000 characters) and verify it saves. func testLongNote_Over1000Characters() { let longText = String(repeating: "This is a test note. ", count: 55) // ~1155 chars let detail = addNote(longText) // Verify some portion of the note is visible let noteSnippet = app.staticTexts.matching( NSPredicate(format: "label CONTAINS %@", "This is a test note") ).firstMatch noteSnippet.waitForExistenceOrFail(timeout: navigationTimeout, message: "Long note text should be visible after saving") detail.dismiss() detail.assertDismissed() } }