Cotton code
98 lines · 5.2 KB · SwiftRaw
// A WhatsApp poll drawn as a poll (FEEDBACK-3 "polls shown"; CONTRACT.md// "Polls shown", the core's bubble.poll 9dea975162; Android e69a6d5152). Over// Chat Dev's invented chats (-chat-warm-seed YES, the core's own answers from// write_chat_warm_fixture): in the Book club, Divya's poll "Which book next?",// one choice each; Divya and the person chose the lighthouse, Esha the bees.// The card reads as one line in the core's words (his own choice said as// his), a tap opens Votes with who chose what by the chat's names ("You"// first), and Farid's vote arriving later (-chat-warm-vote, the core's answer// once the link's change lands) moves the counts in the chat and in Votes// while it is open. Shots poll-*.import XCTestfinal class ChatPollTests: 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 walk(_ extra: [String], _ shots: String) {        let app = XCUIApplication()        // Farid's vote arrives a while after the chat opens.        app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-open", book, "-chat-warm-vote", "25"] + extra        app.launch()        let table = app.tables["chat-thread"]        XCTAssertTrue(table.waitForExistence(timeout: 30), "the Book club opened")        let poll = app.descendants(matching: .any)["chat-bubble-m-g7"].firstMatch        for _ in 0..<8 where !(poll.exists && poll.isHittable) { table.swipeDown() }        XCTAssertTrue(poll.isHittable, "the poll in reach")        // The card, read as one line: the question, how many may be chosen, each option with its count, his own said        // as his, the total.        let said = poll.label        for part in ["Divya Kapoor", "Poll: Which book next?", "Select one", "The lighthouse one, 2 votes, your choice",                     "The one about bees, 1 vote", "Short stories, for a change, No votes", "3 votes"] {            XCTAssertTrue(said.contains(part), "\"\(part)\" in \(said)")        }        XCTAssertFalse(said.contains("The one about bees, 1 vote, your choice"), "only his own is his: \(said)")        keep("poll-\(shots)-card")        // A tap opens Votes: who chose what, "You" first.        poll.tap()        let votes = app.descendants(matching: .any)["chat-poll-votes"].firstMatch        XCTAssertTrue(votes.waitForExistence(timeout: 5), "Votes opened")        let lighthouse = app.descendants(matching: .any)["chat-poll-votes-0"].firstMatch        XCTAssertTrue(lighthouse.waitForExistence(timeout: 5))        XCTAssertTrue(lighthouse.label.contains("You") && lighthouse.label.contains("Divya Kapoor"), lighthouse.label)        if let you = lighthouse.label.range(of: "You"), let divya = lighthouse.label.range(of: "Divya") {            XCTAssertLessThan(you.lowerBound, divya.lowerBound, "You first: \(lighthouse.label)")        }        XCTAssertTrue(app.descendants(matching: .any)["chat-poll-votes-1"].firstMatch.label.contains("Esha Pillai"))        let stories = app.descendants(matching: .any)["chat-poll-votes-2"].firstMatch        XCTAssertFalse(stories.label.contains("Farid"), "nobody chose short stories yet: \(stories.label)")        keep("poll-\(shots)-votes")        // Farid's vote arrives while Votes is open: it follows.        let farid = NSPredicate(format: "label CONTAINS %@", "Farid Khan")        expectation(for: farid, evaluatedWith: stories)        waitForExpectations(timeout: 40)        XCTAssertTrue(stories.label.contains("1 vote"), stories.label)        keep("poll-\(shots)-votes-after")        // And the card under it: the counts moved.        // A tap just above the panel puts it away (at the largest text the panel stands nearly to the top).        let top = app.descendants(matching: .any)["chat-poll-votes"].firstMatch.frame.minY        app.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: app.frame.midX, dy: max(top - 40, 64))).tap()        XCTAssertTrue(votes.waitForNonExistence(timeout: 5), "Votes closed")        let after = poll.label        XCTAssertTrue(after.contains("Short stories, for a change, 1 vote") && after.contains("4 votes"), "the card follows the vote: \(after)")        keep("poll-\(shots)-card-after")    }    // RULE (owner, FEEDBACK-3): a WhatsApp poll stands as a poll, opens its Votes, and follows the votes arriving.    @MainActor func testAPollStandsAndFollowsItsVotes() { walk([], "default") }    // RULE: the same at the largest text.    @MainActor func testAPollStandsAndFollowsItsVotesAtTheLargestText() { walk(Self.largestText, "largest") }    // RULE: the same at night.    @MainActor func testAPollStandsAndFollowsItsVotesAtNight() {        XCUIDevice.shared.appearance = .dark        walk([], "dark")    }}