Cotton code
78 lines · 3.9 KB · SwiftRaw
// Comms on iPhone: words with the pictures one attaches (owner, Comms build// 19, 22 Nov 2026: there was no way to write text with them). Over invented// chats (-chat-warm-seed YES), Photos and videos hands over an invented// picture (-chat-warm-pick YES): it waits in the writing box, what is written// is its caption, Send sends both, and the caption stands under the picture// in the bubble. Shots fb-caption-*.import XCTestfinal class ChatCaptionTests: XCTestCase {    private let asha = "11111111-1111-4111-8111-0000000000a1"    private static let largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"]    private let caption = "Lunch by the invented lake"    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 walk(_ extra: [String], _ shots: String) {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-pick", "YES", "-chat-warm-open", asha] + extra        app.launch()        let plus = app.buttons["chat-attach"]        XCTAssertTrue(plus.waitForExistence(timeout: 30), "the conversation opened")        // The card of a device asking to be let in can come down a few seconds in and move things: wait for it.        _ = ShellCard.refuse(app).waitForExistence(timeout: 6)        plus.tap()        let photos = app.buttons["chat-attach-photo"]        XCTAssertTrue(photos.waitForExistence(timeout: 5))        photos.tap()        // The picture waits in the writing box, the field takes the keyboard, and Send is live with nothing written.        let waiting = app.descendants(matching: .any)["chat-attached"].firstMatch        XCTAssertTrue(waiting.waitForExistence(timeout: 10), "the picked picture waits in the writing box")        XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10), "the field takes the keyboard for the caption")        let send = app.buttons["chat-composer-send"]        XCTAssertTrue(send.isEnabled, "Send is live with a picture waiting")        let box = app.descendants(matching: .any)["chat-composer"].firstMatch        XCTAssertGreaterThanOrEqual(waiting.frame.minY, box.frame.minY - 80, "the picture stands in the writing box, over the field")        keep("fb-caption-\(shots)-picked")        let field = app.textViews["chat-composer-text"]        field.typeText(caption)        keep("fb-caption-\(shots)-written")        send.tap()        // Sent: the box is empty again, and the bubble is the picture with its caption under it.        let bubble = app.descendants(matching: .any)["chat-bubble-seed-sent-1"].firstMatch        XCTAssertTrue(bubble.waitForExistence(timeout: 10), "the picture landed")        XCTAssertFalse(waiting.exists, "nothing waits in the box after Send")        let said = bubble.label        let photo = said.range(of: "Photo"), words = said.range(of: caption)        XCTAssertNotNil(photo, "the bubble is a picture: \(said)")        XCTAssertNotNil(words, "the bubble carries the caption: \(said)")        if let photo, let words { XCTAssertLessThan(photo.lowerBound, words.lowerBound, "the caption is read after the picture: \(said)") }        XCTAssertLessThanOrEqual(bubble.frame.maxY, box.frame.minY, "the sent picture stands above the writing box")        Thread.sleep(forTimeInterval: 1)        keep("fb-caption-\(shots)-sent")    }    // RULE (owner, Comms build 19): a picked picture waits in the writing box for a caption, and Send sends both.    @MainActor func testAPictureGoesWithItsCaption() {        walk([], "default")    }    // RULE: the same at the largest text.    @MainActor func testAPictureGoesWithItsCaptionAtTheLargestText() {        walk(Self.largestText, "largest")    }}