import XCTest /// Runs against the production composer with the debug fake transport. final class AttachmentSourceUITests: XCTestCase { @MainActor func testMenuPresentsPrivatePhotosPicker() throws { let app = XCUIApplication() app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launch() XCTAssertTrue(app.buttons["Attach"].waitForExistence(timeout: 10)) XCTAssertGreaterThanOrEqual(app.buttons["Attach"].frame.width, 44) XCTAssertGreaterThanOrEqual(app.buttons["Attach"].frame.height, 44) app.buttons["Attach"].tap() if app.buttons["Not now"].waitForExistence(timeout: 2) { app.buttons["Not now"].tap() app.buttons["Attach"].tap() } XCTAssertTrue(app.buttons["Photos"].waitForExistence(timeout: 5)) XCTAssertTrue(app.buttons["Files"].exists) XCTAssertTrue(app.buttons["Paste"].exists) capture("iphone-add-menu") app.buttons["Photos"].tap() XCTAssertTrue(app.navigationBars["Photos"].waitForExistence(timeout: 10)) capture("iphone-photos-picker") } @MainActor func testComposerAppearances() throws { for mode in ["light", "dark"] { let app = XCUIApplication() app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launchEnvironment["EQUIPO_FIXTURE_DARK"] = mode == "dark" ? "1" : "0" app.launch() let field = app.textFields.firstMatch XCTAssertTrue(field.waitForExistence(timeout: 10)) capture("iphone-" + mode + "-keyboard-down") field.tap() field.typeText("Please fix the sign-in button.") XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5)) capture("iphone-" + mode + "-keyboard-up") app.terminate() } } @MainActor func testConversationDragDismissesKeyboard() throws { let app = XCUIApplication() app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launch() let field = app.textFields.firstMatch XCTAssertTrue(field.waitForExistence(timeout: 10)) field.tap() field.typeText("Please fix the sign-in button.") XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5)) let message = app.staticTexts["You said: Home’s sign-in button is cut off on my phone."] message.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) .press(forDuration: 0.01, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.99)), withVelocity: .fast, thenHoldForDuration: 0) XCTAssertTrue(app.keyboards.firstMatch.waitForNonExistence(timeout: 5)) XCTAssertEqual(field.value as? String, "Please fix the sign-in button.") field.tap() XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5)) app.scrollViews["conversation-scroll"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) .press(forDuration: 0.01, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.99)), withVelocity: .fast, thenHoldForDuration: 0) XCTAssertTrue(app.keyboards.firstMatch.waitForNonExistence(timeout: 5)) } /// The real phone tabs: the composer sits directly above the keyboard, /// and reading (a scroll, a tap on the conversation) puts it away. @MainActor func testKeyboardKeepsComposerAboveItInTabs() throws { for mode in ["light", "dark"] { let app = XCUIApplication() app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launchEnvironment["EQUIPO_FIXTURE_TABS"] = "1" app.launchEnvironment["EQUIPO_FIXTURE_DARK"] = mode == "dark" ? "1" : "0" app.launch() let field = app.textFields.firstMatch XCTAssertTrue(field.waitForExistence(timeout: 10)) field.tap() field.typeText("Please fix the sign-in button.") let keyboard = app.keyboards.firstMatch XCTAssertTrue(keyboard.waitForExistence(timeout: 5)) Thread.sleep(forTimeInterval: 0.6) XCTAssertTrue(field.isHittable, "the composer is hidden behind the keyboard") XCTAssertLessThanOrEqual(field.frame.maxY, keyboard.frame.minY + 1, "the composer is not above the keyboard: \(field.frame) vs \(keyboard.frame)") XCTAssertGreaterThan(field.frame.maxY, keyboard.frame.minY - 120, "the composer is not directly above the keyboard: \(field.frame) vs \(keyboard.frame)") capture("keyboard-" + mode + "-up") app.scrollViews["conversation-scroll"].swipeDown() XCTAssertTrue(keyboard.waitForNonExistence(timeout: 5), "a scroll of the conversation keeps the keyboard") XCTAssertEqual(field.value as? String, "Please fix the sign-in button.") capture("keyboard-" + mode + "-scrolled") app.terminate() } } @MainActor func testTapOnConversationDismissesKeyboardButSendKeepsIt() throws { let app = XCUIApplication() app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launchEnvironment["EQUIPO_FIXTURE_TABS"] = "1" app.launch() let field = app.textFields.firstMatch XCTAssertTrue(field.waitForExistence(timeout: 10)) field.tap() let keyboard = app.keyboards.firstMatch XCTAssertTrue(keyboard.waitForExistence(timeout: 5)) app.scrollViews["conversation-scroll"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.15)).tap() XCTAssertTrue(keyboard.waitForNonExistence(timeout: 5), "a tap on the conversation keeps the keyboard") field.tap() XCTAssertTrue(keyboard.waitForExistence(timeout: 5)) field.typeText("Again") app.buttons["Send"].tap() Thread.sleep(forTimeInterval: 0.5) XCTAssertTrue(keyboard.exists, "Send keeps the keyboard for a follow-up") XCTAssertTrue(field.isHittable, "the composer is above the keyboard after Send") } /// Paul's path: type, open a task link in a Coordinator message, come /// back. The keyboard is down; tapping the field brings it back with the /// composer directly above it. Then the same from the task's own reply. @MainActor func testTaskLinkAndBackLeavesKeyboardDown() throws { for mode in ["light", "dark"] { let app = XCUIApplication() app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launchEnvironment["EQUIPO_FIXTURE_TABS"] = "1" app.launchEnvironment["EQUIPO_FIXTURE_DARK"] = mode == "dark" ? "1" : "0" app.launch() let field = app.textFields["Message"] XCTAssertTrue(field.waitForExistence(timeout: 10)) field.tap(); field.typeText("Looking") let keyboard = app.keyboards.firstMatch XCTAssertTrue(keyboard.waitForExistence(timeout: 5)) // The link is inside the Coordinator's sentence: tap its words. let message = app.staticTexts["I started Fix the sign-in button."] XCTAssertTrue(message.waitForExistence(timeout: 5)) message.coordinate(withNormalizedOffset: CGVector(dx: 0.7, dy: 0.5)).tap() XCTAssertTrue(keyboard.waitForNonExistence(timeout: 5), "opening a task keeps the keyboard") let back = app.navigationBars.buttons["Conversation"] XCTAssertTrue(back.waitForExistence(timeout: 5)) let reply = app.textFields["Reply"] if reply.waitForExistence(timeout: 3) { reply.tap() XCTAssertTrue(keyboard.waitForExistence(timeout: 5)) } capture("keyboard-" + mode + "-task") back.tap() XCTAssertTrue(field.waitForExistence(timeout: 5)) Thread.sleep(forTimeInterval: 1) if keyboard.exists { XCTAssertLessThanOrEqual(field.frame.maxY, keyboard.frame.minY + 1, "back with the keyboard up and the composer behind it") } XCTAssertFalse(keyboard.exists, "coming back to the conversation brings the keyboard back") capture("keyboard-" + mode + "-back") field.tap() XCTAssertTrue(keyboard.waitForExistence(timeout: 5)) Thread.sleep(forTimeInterval: 0.6) XCTAssertLessThanOrEqual(field.frame.maxY, keyboard.frame.minY + 1, "the composer is not above the keyboard after coming back") XCTAssertTrue(field.isHittable) app.terminate() } } @MainActor private func capture(_ name: String) { let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) attachment.name = name; attachment.lifetime = .keepAlways; add(attachment) } }