// // NoteEditorScreen.swift // Tests iOS // // Screen object for the Journal Note editor sheet. // import XCTest struct NoteEditorScreen { let app: XCUIApplication private let defaultTimeout: TimeInterval = 2 private let navigationTimeout: TimeInterval = 5 // MARK: - Elements var textEditor: XCUIElement { app.textViews[UITestID.NoteEditor.text] } var saveButton: XCUIElement { app.buttons[UITestID.NoteEditor.save] } var cancelButton: XCUIElement { app.buttons[UITestID.NoteEditor.cancel] } // MARK: - Actions @discardableResult func typeNote(_ text: String, file: StaticString = #filePath, line: UInt = #line) -> NoteEditorScreen { textEditor .waitUntilHittableOrFail(timeout: defaultTimeout, message: "Note text editor should be hittable", file: file, line: line) .tap() textEditor.typeText(text) return self } @discardableResult func clearAndTypeNote(_ text: String, file: StaticString = #filePath, line: UInt = #line) -> NoteEditorScreen { textEditor .waitUntilHittableOrFail(timeout: defaultTimeout, message: "Note text editor should be hittable", file: file, line: line) .tap() textEditor.press(forDuration: 1.0) let selectAll = app.menuItems["Select All"] if selectAll.waitForExistence(timeout: defaultTimeout) { selectAll.tap() } textEditor.typeText(text) return self } func save(file: StaticString = #filePath, line: UInt = #line) { saveButton .waitUntilHittableOrFail(timeout: defaultTimeout, message: "Save button should be hittable", file: file, line: line) .forceTap(file: file, line: line) } func cancel(file: StaticString = #filePath, line: UInt = #line) { cancelButton .waitUntilHittableOrFail(timeout: defaultTimeout, message: "Cancel button should be hittable", file: file, line: line) .forceTap(file: file, line: line) } // MARK: - Assertions @discardableResult func assertVisible(file: StaticString = #filePath, line: UInt = #line) -> NoteEditorScreen { textEditor.waitForExistenceOrFail(timeout: navigationTimeout, message: "Note editor should be visible", file: file, line: line) return self } func assertDismissed(file: StaticString = #filePath, line: UInt = #line) { textEditor.waitForNonExistence(timeout: navigationTimeout, message: "Note editor should be dismissed", file: file, line: line) } }