// Comms 28 fixes 2 (owner, 24 Nov 2026): a document in a chat opens in a reader inside Comms with Share. A web link // goes to Cotton Sites when it is on the phone, else Safari's sheet inside Comms, never the browser (COMMS WITHOUT // MAIL, 26 Nov 2026: `chat.link`). Over Comms Dev's invented data (-chat-warm-seed YES): Kabir's chat holds a PDF from // WhatsApp and words with a link. import XCTest final class ChatDocumentTests: XCTestCase { private let kabir = "11111111-1111-4111-8111-0000000000h1" private static let largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"] override func setUp() { continueAfterFailure = false XCUIDevice.shared.orientation = .portrait } private func keep(_ name: String) { let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) shot.name = name shot.lifetime = .keepAlways add(shot) } @MainActor private func opened(_ extra: [String]) -> XCUIApplication { let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-open", kabir] + extra app.launch() _ = ShellCard.refuse(app).waitForExistence(timeout: 6) return app } @MainActor private func reads(_ extra: [String], _ shots: String) { let app = opened(extra) let document = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS 'Garden plan.pdf'")).firstMatch XCTAssertTrue(document.waitForExistence(timeout: 30), "Kabir's PDF stands in his chat") keep("document-\(shots)-chat") document.tap() // Quick Look, inside Comms: the document's own words, Share, and its close back to the chat. let share = app.buttons["Share"].firstMatch XCTAssertTrue(share.waitForExistence(timeout: 15), "the reader offers Share") XCTAssertTrue(app.staticTexts["Garden plan"].waitForExistence(timeout: 10) || app.otherElements["QLPreviewControllerView"].exists || app.navigationBars.firstMatch.exists, "the reader shows the document") XCTAssertEqual(app.state, .runningForeground, "read inside Comms") keep("document-\(shots)-reader") // Quick Look's own close: Done before iOS 26, Close (its cross) since. let done = app.buttons.matching(NSPredicate(format: "label IN {'Done', 'Close'}")).firstMatch XCTAssertTrue(done.waitForExistence(timeout: 5), "the reader closes") done.tap() XCTAssertTrue(document.waitForExistence(timeout: 10), "back in the chat") } // RULE (owner, Comms 28 fixes 2): a document in a chat opens in a reader with Share. @MainActor func testADocumentOpensInAReaderWithShare() { reads([], "default") } @MainActor func testADocumentOpensInAReaderWithShareAtTheLargestText() { reads(Self.largestText, "largest") } // RULE (COMMS WITHOUT MAIL, sites CONTRACT row 8): a web link goes to Cotton Sites (Comms Dev hands it to Sites // Dev) when Sites is on the phone; else it reads in Safari's sheet inside Comms. Never the browser. @MainActor func testALinkGoesToSitesOrSafarisSheet() { let app = opened([]) let link = app.links.matching(NSPredicate(format: "label CONTAINS 'example.com/seeds' OR identifier CONTAINS 'example.com/seeds'")).firstMatch let words = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS 'example.com/seeds'")).firstMatch XCTAssertTrue(words.waitForExistence(timeout: 30), "Kabir's words with a link stand in his chat") if link.exists { link.tap() } else { words.tap() } let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari") let sites = XCUIApplication(bundleIdentifier: "com.cottondb.sites.dev") let done = app.buttons["Done"].firstMatch let handed = sites.wait(for: .runningForeground, timeout: 8) if handed { keep("link-in-sites") XCTAssertNotEqual(safari.state, .runningForeground, "never the browser") return } XCTAssertTrue(done.waitForExistence(timeout: 15), "without Sites, Safari's sheet over Comms, with Done") XCTAssertNotEqual(safari.state, .runningForeground, "it never leaves for the browser") XCTAssertEqual(app.state, .runningForeground) keep("link-inside") done.tap() XCTAssertTrue(words.waitForExistence(timeout: 10), "Done, back in the chat") } }