// Comms' export on iPhone (chat CONTRACT.md "Export"), over Chat Dev's invented people (-chat-warm-seed YES; the // seed answers `chat.export` with an invented zip in the contract's shape, the real file being the core's own, // tested in `chat_app::tests::export`): You → Export → Export all chats, and Export chat on a person's page and on a // group's page, each hand the file to the share sheet. import XCTest final class ChatExportTests: XCTestCase { private let asha = "11111111-1111-4111-8111-0000000000a1" private let hillTrip = "11111111-1111-4111-8111-0000000000b1" override func setUp() { continueAfterFailure = false } @MainActor private func launched(_ extra: [String]) -> XCUIApplication { let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES"] + extra app.launch() return app } @MainActor private func id(_ app: XCUIApplication, _ identifier: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: identifier).firstMatch } /// The share sheet rose holding a file named `name`; then it is closed. @MainActor private func shared(_ app: XCUIApplication, _ name: String, file: StaticString = #filePath, line: UInt = #line) { let sheet = app.otherElements["ActivityListView"] XCTAssertTrue(sheet.waitForExistence(timeout: 15), "the share sheet rose", file: file, line: line) let named = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@", name)).firstMatch XCTAssertTrue(named.waitForExistence(timeout: 10), "it holds \(name)", file: file, line: line) // The sheet stands half up, with no Close: a tap above it puts it away, a swipe down if it still stands. app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.12)).tap() if !sheet.waitForNonExistence(timeout: 3), sheet.exists { sheet.swipeDown(velocity: .fast) } XCTAssertTrue(sheet.waitForNonExistence(timeout: 10), "the share sheet closed", file: file, line: line) } // RULE: You → Export (right after Look) opens its page, which says what it makes; Export all chats shares the zip. @MainActor func testExportAllChatsFromYou() { let app = launched(["-chat-warm-place", "you"]) let row = id(app, "you-row-export") XCTAssertTrue(row.waitForExistence(timeout: 30), "Export stands in You") XCTAssertTrue(row.label.hasPrefix("Export, Your chats as text"), "it says what it makes: \(row.label)") let look = id(app, "you-row-look") if look.exists { XCTAssertLessThan(look.frame.minY, row.frame.minY, "after Look") } XCTAssertLessThan(row.frame.minY, id(app, "you-row-sync").frame.minY, "before Sync") row.tap() XCTAssertTrue(id(app, "you-export-page").waitForExistence(timeout: 10), "its page opens") XCTAssertTrue(app.staticTexts["Your chats as text, with their pictures and files."].exists, "what it makes") id(app, "you-export-all").tap() shared(app, "Comms chats") id(app, "you-export-page-back").tap() XCTAssertTrue(row.waitForExistence(timeout: 10), "Back returns to You") } // RULE: Export chat stands on a person's page above Mute and shares that chat's zip. @MainActor func testExportChatFromAPersonsPage() { let app = launched(["-chat-warm-open", asha, "-chat-warm-person", "YES"]) let export = app.buttons["chat-person-export"] XCTAssertTrue(export.waitForExistence(timeout: 30), "Export chat stands on the person's page") XCTAssertEqual(export.label, "Export chat") XCTAssertLessThan(export.frame.minY, app.buttons["chat-person-mute"].frame.minY, "above Mute") export.tap() shared(app, "Chat") } // RULE: Export chat stands on a group's page above Mute and shares that chat's zip. @MainActor func testExportChatFromAGroupsPage() { let app = launched(["-chat-warm-open", hillTrip, "-chat-warm-person", "YES"]) let export = app.buttons["chat-group-export"] XCTAssertTrue(export.waitForExistence(timeout: 30), "Export chat stands on the group's page") for _ in 0..<6 where !export.isHittable { app.swipeUp(velocity: .slow) } let mute = app.buttons["chat-group-mute"] if mute.exists { XCTAssertLessThan(export.frame.minY, mute.frame.minY, "above Mute") } export.tap() shared(app, "Chat") } }