| 1 | import XCTest |
| 2 | |
| 3 | final class ShareUITests: XCTestCase { |
| 4 | override func setUp() { continueAfterFailure = false } |
| 5 | @MainActor func testRealShareComposeAndSignedOut() throws { |
| 6 | for mode in ["compose", "signed-out", "large"] { |
| 7 | let app = XCUIApplication() |
| 8 | app.launchEnvironment["EQUIPO_SHARE_FIXTURE"] = mode |
| 9 | app.launch() |
| 10 | XCTAssertTrue(app.buttons["Send to Equipo"].waitForExistence(timeout: 10)) |
| 11 | XCTAssertTrue(app.buttons["Send to Equipo"].isEnabled) |
| 12 | app.buttons["Send to Equipo"].tap() |
| 13 | let activity = app.cells["Oficina Equipo"].firstMatch |
| 14 | if !activity.waitForExistence(timeout: 3), app.cells["More"].exists { app.cells["More"].tap() } |
| 15 | XCTAssertTrue(activity.waitForExistence(timeout: 8), app.debugDescription) |
| 16 | activity.tap() |
| 17 | if mode != "signed-out" { |
| 18 | XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "share-message").firstMatch.waitForExistence(timeout: 10), app.debugDescription) |
| 19 | XCTAssertTrue(app.staticTexts[mode == "large" ? "large.jpg" : "Home.png"].waitForExistence(timeout: 10), app.debugDescription) |
| 20 | let message = app.textFields["share-message"] |
| 21 | let imported = NSPredicate(format: "value == %@", "The sign-in button is cut off on my phone.") |
| 22 | XCTAssertEqual(XCTWaiter.wait(for: [XCTNSPredicateExpectation(predicate: imported, object: message)], timeout: 10), .completed, app.debugDescription) |
| 23 | XCTAssertTrue(app.buttons["share-send"].isEnabled) |
| 24 | } else { |
| 25 | XCTAssertTrue(app.staticTexts["Open Equipo and sign in, then share this again."].waitForExistence(timeout: 10), app.debugDescription) |
| 26 | } |
| 27 | capture("iphone-share-" + mode) |
| 28 | if app.buttons["Cancel"].exists { app.buttons["Cancel"].firstMatch.tap() } |
| 29 | app.terminate() |
| 30 | } |
| 31 | } |
| 32 | @MainActor func testScreenshotExplanationAndChip() throws { |
| 33 | for mode in ["permission", "chip"] { |
| 34 | let app = XCUIApplication() |
| 35 | if mode == "permission" { app.resetAuthorizationStatus(for: .photos) } |
| 36 | app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent" |
| 37 | app.launchEnvironment["EQUIPO_SCREENSHOT_FIXTURE"] = mode |
| 38 | app.launch() |
| 39 | XCTAssertTrue(app.buttons["Attach"].waitForExistence(timeout: 10)) |
| 40 | let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") |
| 41 | let deny = springboard.buttons.matching(NSPredicate(format: "label MATCHES %@", "Don.t Allow")).firstMatch |
| 42 | XCTAssertFalse(deny.waitForExistence(timeout: 2)) |
| 43 | if mode == "permission" { |
| 44 | XCTAssertFalse(app.staticTexts["Let Equipo offer recent screenshots?"].exists) |
| 45 | app.buttons["Attach"].tap() |
| 46 | XCTAssertTrue(app.staticTexts["Let Equipo offer recent screenshots?"].waitForExistence(timeout: 5)) |
| 47 | } else { |
| 48 | XCTAssertTrue(app.buttons["Add the screenshot you just took"].waitForExistence(timeout: 5)) |
| 49 | } |
| 50 | XCTAssertFalse(deny.waitForExistence(timeout: 2)) |
| 51 | capture("iphone-screenshot-" + mode) |
| 52 | if mode == "permission" { |
| 53 | app.buttons["Choose screenshots"].tap() |
| 54 | XCTAssertTrue(deny.waitForExistence(timeout: 5)) |
| 55 | deny.tap() |
| 56 | } |
| 57 | if mode == "chip" { |
| 58 | app.buttons["Dismiss"].tap() |
| 59 | XCTAssertFalse(app.buttons["Add the screenshot you just took"].exists) |
| 60 | } |
| 61 | app.terminate() |
| 62 | } |
| 63 | } |
| 64 | @MainActor private func capture(_ name: String) { |
| 65 | let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) |
| 66 | attachment.name = name; attachment.lifetime = .keepAlways; add(attachment) |
| 67 | } |
| 68 | } |
| 69 | |