Cotton code
66 lines · 3.4 KB · SwiftRaw
// Comms on iPhone, the foot of the person's own message (owner, Comms build// 19, 22 Nov 2026: at the largest text "Read" and "5:30" were drawn on top of// each other). Over invented chats (-chat-warm-seed YES), Ravi's chat ends on// a message of the person's that says Read; Chat Dev's probe// (-chat-warm-meta YES) shows where its Read and its time are drawn. They// never meet, and at rest the time stays past the screen's edge, in the// column a pull to the left shows; at the default text size and the largest.// Shots fb-meta-*.import XCTestfinal class ChatMetaTests: XCTestCase {    private let ravi = "11111111-1111-4111-8111-0000000000d1"    private static let largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"]    override func setUp() {        continueAfterFailure = false        XCUIDevice.shared.orientation = .portrait    }    private func keep(_ name: String) {        let screen = XCUIScreen.main.screenshot()        let shot = XCTAttachment(screenshot: screen)        shot.name = name        shot.lifetime = .keepAlways        add(shot)        keepShot(screen, name)    }    @MainActor private func walk(_ extra: [String], _ shots: String) {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-meta", "YES", "-chat-warm-open", ravi] + extra        app.launch()        let probe = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'chat-meta-'")).firstMatch        XCTAssertTrue(probe.waitForExistence(timeout: 30), "Ravi's chat ends on a message of the person's with its state under it")        // 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)        Thread.sleep(forTimeInterval: 1)        keep("fb-meta-\(shots)-rest")        // `state x y w h|time x y w h`, in the window.        let said = probe.value as? String ?? ""        let frames = Dictionary(uniqueKeysWithValues: said.split(separator: "|").compactMap { part -> (String, CGRect)? in            let n = part.split(separator: " ")            guard n.count == 5, let x = Double(n[1]), let y = Double(n[2]), let w = Double(n[3]), let h = Double(n[4]) else { return nil }            return (String(n[0]), CGRect(x: x, y: y, width: w, height: h))        })        let s = frames["state"] ?? .null, t = frames["time"] ?? .null, screen = app.windows.firstMatch.frame        XCTAssertFalse(s.isNull || s.width < 1, "the state line is drawn (\(said))")        XCTAssertFalse(t.isNull || t.width < 1, "the time is drawn (\(said))")        let over = s.intersection(t)        XCTAssertTrue(over.isNull || over.width < 0.5 || over.height < 0.5, "the state (\(s)) and the time (\(t)) are drawn apart")        XCTAssertLessThanOrEqual(s.maxX, screen.maxX, "the state line is on the screen (\(s))")        XCTAssertGreaterThanOrEqual(t.minX, screen.maxX - 0.5, "at rest the time (\(t)) stays past the screen's edge (\(screen.maxX))")    }    // RULE (owner, Comms build 19): a message's Read and its time never draw over each other.    @MainActor func testTheStateAndTheTimeStandApart() {        walk([], "default")    }    // RULE: the same at the largest text, where the time is widest.    @MainActor func testTheStateAndTheTimeStandApartAtTheLargestText() {        walk(Self.largestText, "largest")    }}