import XCTest final class ShareUITests: XCTestCase { override func setUp() { continueAfterFailure = false } @MainActor func testRealShareComposeAndSignedOut() throws { for mode in ["compose", "signed-out", "large"] { let app = XCUIApplication() app.launchEnvironment["EQUIPO_SHARE_FIXTURE"] = mode app.launch() XCTAssertTrue(app.buttons["Send to Equipo"].waitForExistence(timeout: 10)) XCTAssertTrue(app.buttons["Send to Equipo"].isEnabled) app.buttons["Send to Equipo"].tap() let activity = app.cells["Oficina Equipo"].firstMatch if !activity.waitForExistence(timeout: 3), app.cells["More"].exists { app.cells["More"].tap() } XCTAssertTrue(activity.waitForExistence(timeout: 8), app.debugDescription) activity.tap() if mode != "signed-out" { XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "share-message").firstMatch.waitForExistence(timeout: 10), app.debugDescription) XCTAssertTrue(app.staticTexts[mode == "large" ? "large.jpg" : "Home.png"].waitForExistence(timeout: 10), app.debugDescription) let message = app.textFields["share-message"] let imported = NSPredicate(format: "value == %@", "The sign-in button is cut off on my phone.") XCTAssertEqual(XCTWaiter.wait(for: [XCTNSPredicateExpectation(predicate: imported, object: message)], timeout: 10), .completed, app.debugDescription) XCTAssertTrue(app.buttons["share-send"].isEnabled) } else { XCTAssertTrue(app.staticTexts["Open Equipo and sign in, then share this again."].waitForExistence(timeout: 10), app.debugDescription) } capture("iphone-share-" + mode) if app.buttons["Cancel"].exists { app.buttons["Cancel"].firstMatch.tap() } app.terminate() } } @MainActor func testScreenshotExplanationAndChip() throws { for mode in ["permission", "chip"] { let app = XCUIApplication() if mode == "permission" { app.resetAuthorizationStatus(for: .photos) } app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" app.launchEnvironment["EQUIPO_SCREENSHOT_FIXTURE"] = mode app.launch() XCTAssertTrue(app.buttons["Attach"].waitForExistence(timeout: 10)) let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let deny = springboard.buttons.matching(NSPredicate(format: "label MATCHES %@", "Don.t Allow")).firstMatch XCTAssertFalse(deny.waitForExistence(timeout: 2)) if mode == "permission" { XCTAssertFalse(app.staticTexts["Let Equipo offer recent screenshots?"].exists) app.buttons["Attach"].tap() XCTAssertTrue(app.staticTexts["Let Equipo offer recent screenshots?"].waitForExistence(timeout: 5)) } else { XCTAssertTrue(app.buttons["Add the screenshot you just took"].waitForExistence(timeout: 5)) } XCTAssertFalse(deny.waitForExistence(timeout: 2)) capture("iphone-screenshot-" + mode) if mode == "permission" { app.buttons["Choose screenshots"].tap() XCTAssertTrue(deny.waitForExistence(timeout: 5)) deny.tap() } if mode == "chip" { app.buttons["Dismiss"].tap() XCTAssertFalse(app.buttons["Add the screenshot you just took"].exists) } app.terminate() } } @MainActor private func capture(_ name: String) { let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) attachment.name = name; attachment.lifetime = .keepAlways; add(attachment) } }