// // EntryDetailScreen.swift // Tests iOS // // Screen object for the Entry Detail sheet (edit mood, notes, delete). // 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) } func moodButton(for mood: MoodChoice) -> XCUIElement { app.buttons["mood_button_\(mood.rawValue)"] } // MARK: - Actions 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, 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(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 alert.waitForExistenceOrFail(timeout: navigationTimeout, message: "Delete confirmation alert should appear", file: file, line: line) 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 @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 = #filePath, line: UInt = #line) { sheet.waitForNonExistence(timeout: navigationTimeout, message: "Entry Detail sheet should be dismissed", file: file, line: line) } }