Cotton code
42 lines · 2.0 KB · SwiftRaw
// Chat Dev on a simulator with invented chats (-chat-warm-seed YES, the// core's own answers over invented people) and one conversation of 5,000// invented messages (-chat-warm-long 5000), paged as the core pages: the// list opens a chat, and flings through the 5,000 are measured for hitches// (XCTest's scroll deceleration metric).import XCTestfinal class ChatWarmScrollTests: XCTestCase {    private func launched(_ extra: [String] = []) -> XCUIApplication {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES"] + extra        app.launch()        return app    }    // RULE: the Chats list stands with its filters, and a row opens its conversation.    func testTheListOpensAConversation() {        let app = launched()        XCTAssertTrue(app.buttons["chat-filter-unread"].waitForExistence(timeout: 30), "the filters stand")        let row = app.cells.firstMatch        XCTAssertTrue(row.waitForExistence(timeout: 5))        row.tap()        XCTAssertTrue(app.tables["chat-thread"].waitForExistence(timeout: 5), "the conversation opened")    }    // RULE: 5,000 messages scroll: three fast flings back through them, measured for hitches    // (the hitch time ratio, ms a second, is read from the result; under 5 is Apple's "good").    func testFiveThousandMessagesScrollSmoothly() {        let app = launched(["-chat-warm-long", "5000", "-chat-warm-open", "chat-warm-long"])        let thread = app.tables["chat-thread"]        XCTAssertTrue(thread.waitForExistence(timeout: 30), "the long conversation opened")        let options = XCTMeasureOptions()        options.iterationCount = 3        measure(metrics: [XCTOSSignpostMetric.scrollDecelerationMetric], options: options) {            // The table is flipped (newest at the foot): a swipe down reads back into older pages.            thread.swipeDown(velocity: .fast)            thread.swipeDown(velocity: .fast)            thread.swipeDown(velocity: .fast)        }    }}