Cotton code
75 lines · 4.0 KB · SwiftRaw
// A chat opens on its newest message, whole and clear of the writing box (chat-warm-ios, 24 Nov 2026: Tara's// WhatsApp chat opened a little short of it: the newest bubble's foot, a poll's Retry line, stood under the box and// the jump arrow showed; not seen again at 5bff5f9861, whose fixture no longer has the poll newest). Over Chat Dev's// invented chats (-chat-warm-seed YES): Tara's with a vote not sent and with changes not sent, at the default text// size and the largest, and Asha's, a plain chat: the lowest thing drawn stands above the box, with no jump arrow.import XCTestfinal class ChatOpensAtNewestTests: XCTestCase {    private let tara = "11111111-1111-4111-8111-0000000000f1"    private let asha = "11111111-1111-4111-8111-0000000000a1"    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(_ thread: String, _ extra: [String]) -> XCUIApplication {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-open", thread] + extra        app.launch()        XCTAssertTrue(app.descendants(matching: .any)["chat-composer"].firstMatch.waitForExistence(timeout: 30), "the chat opened")        // The card of a device asking to be let in can come down a few seconds in: let the page settle.        _ = ShellCard.refuse(app).waitForExistence(timeout: 6)        Thread.sleep(forTimeInterval: 1.5)        return app    }    /// The newest item's foot stands above the writing box, untouched, and no jump arrow shows.    @MainActor private func clear(_ newest: XCUIElement, in app: XCUIApplication, _ shot: String) {        XCTAssertTrue(newest.waitForExistence(timeout: 10), "the newest item stands")        let box = app.descendants(matching: .any)["chat-composer"].firstMatch        keep(shot)        XCTAssertLessThanOrEqual(newest.frame.maxY, box.frame.minY + 1, "the newest item's foot is clear of the writing box")        XCTAssertFalse(app.buttons["chat-jump"].exists && app.buttons["chat-jump"].isHittable, "no jump arrow: the chat stands at its newest")    }    /// The lowest thing the chat draws: a bubble, or a line under one (Retry, a state).    @MainActor private func lowest(in app: XCUIApplication) -> XCUIElement {        let drawn = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'chat-bubble-' OR identifier BEGINSWITH 'chat-retry-'"))        XCTAssertTrue(drawn.firstMatch.waitForExistence(timeout: 10))        let all = drawn.allElementsBoundByIndex.filter { $0.exists && $0.frame.height > 0 }        return all.max { $0.frame.maxY < $1.frame.maxY } ?? drawn.firstMatch    }    @MainActor private func tara(_ mode: [String], _ extra: [String], _ shot: String) {        let app = opened(tara, mode + extra)        clear(lowest(in: app), in: app, shot)    }    @MainActor func testTarasChatWithAVoteNotSentOpensOnItsNewestWhole() { tara(["-chat-warm-wa-vote", "failed"], [], "newest-tara-vote") }    @MainActor func testTarasChatWithAVoteNotSentOpensOnItsNewestWholeAtTheLargestText() {        tara(["-chat-warm-wa-vote", "failed"], Self.largestText, "newest-tara-vote-largest")    }    @MainActor func testTarasChatWithChangesNotSentOpensOnItsNewestWhole() { tara(["-chat-warm-wa-changes", "failed"], [], "newest-tara-changes") }    @MainActor func testTarasChatWithChangesNotSentOpensOnItsNewestWholeAtTheLargestText() {        tara(["-chat-warm-wa-changes", "failed"], Self.largestText, "newest-tara-changes-largest")    }    @MainActor func testAPlainChatOpensOnItsNewestWhole() {        let app = opened(asha, [])        clear(lowest(in: app), in: app, "newest-asha")    }}