Cotton code
78 lines · 3.9 KB · SwiftRaw
// Replies and reactions on a WhatsApp chat (FEEDBACK-3; CONTRACT.md// "Replies and reactions", 09864bc836). Coming in, both land as the link// brings them: over Chat Dev's invented chats (-chat-warm-seed YES, the// core's own answers from write_chat_warm_fixture), in the Book club, a// WhatsApp group, the person's answer quotes Divya's question by her name and// words, Farid's laugh and the person's own heart stand under her question// (his own marked), and Divya's like under his answer. Each is said with its// message. Going out (Reply and React through the Mac) waits for the core to// offer them in a bubble's actions. Shots wa-react-*.import XCTestfinal class ChatWhatsAppReactTests: XCTestCase {    private let book = "11111111-1111-4111-8111-0000000000g1"    private static let largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"]    override func setUp() {        continueAfterFailure = false        XCUIDevice.shared.orientation = .portrait    }    override func tearDown() {        XCUIDevice.shared.appearance = .light    }    private func keep(_ name: String) {        let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())        shot.name = name        shot.lifetime = .keepAlways        add(shot)    }    @MainActor private func bubble(_ id: String, in app: XCUIApplication) -> XCUIElement {        app.descendants(matching: .any)["chat-bubble-\(id)"].firstMatch    }    @MainActor private func walk(_ extra: [String], _ shots: String) {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-open", book] + extra        app.launch()        let table = app.tables["chat-thread"]        XCTAssertTrue(table.waitForExistence(timeout: 30), "the Book club opened")        // His answer, quoting Divya's question by her name and words, with her like under it.        let answer = bubble("m-g4", in: app)        XCTAssertTrue(answer.waitForExistence(timeout: 10), "his answer stands")        for _ in 0..<6 where !answer.isHittable { table.swipeDown() }        let said = answer.label        XCTAssertTrue(said.contains("Replying to Divya Kapoor, Next month: the lighthouse book?"), "the quote names her and her words: \(said)")        XCTAssertTrue(said.contains("Thursday works for me"), said)        XCTAssertTrue(said.contains("👍 1"), "Divya's like stands under it: \(said)")        if let quote = said.range(of: "Replying to"), let words = said.range(of: "Thursday works") {            XCTAssertLessThan(quote.lowerBound, words.lowerBound, "the quote is read before the words")        }        keep("wa-react-\(shots)-reply")        // Divya's question, Farid's laugh and his own heart under it.        let question = bubble("m-g1", in: app)        for _ in 0..<6 where !(question.exists && question.isHittable) { table.swipeDown() }        XCTAssertTrue(question.isHittable, "Divya's question in reach")        XCTAssertTrue(question.label.contains("😂 1") && question.label.contains("❤️ 1"), "both reactions stand under it: \(question.label)")        keep("wa-react-\(shots)-reactions")        // Esha's picture went, and Farid's surprise at it with it.        XCTAssertEqual(app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@", "😮")).count, 0, "a deleted message's reactions go with it")    }    // RULE (owner, FEEDBACK-3): a WhatsApp reply shows its quote and WhatsApp reactions stand under their messages, said with them.    @MainActor func testWhatsAppRepliesAndReactionsStand() { walk([], "default") }    // RULE: the same at the largest text.    @MainActor func testWhatsAppRepliesAndReactionsStandAtTheLargestText() { walk(Self.largestText, "largest") }    // RULE: the same at night.    @MainActor func testWhatsAppRepliesAndReactionsStandAtNight() {        XCUIDevice.shared.appearance = .dark        walk([], "dark")    }}