Cotton code
159 lines · 9.7 KB · SwiftRaw
// Chat Dev's pages over invented people (-chat-warm-seed YES, the people's// answers from Fixtures/chat-warm-people.json): a person's page from// chat.contact, a group's page from chat.group.info, New chat with "Find// people I know", You, and Calls.import XCTestfinal class ChatWarmPagesTests: XCTestCase {    private let asha = "11111111-1111-4111-8111-0000000000a1"    private let hillTrip = "11111111-1111-4111-8111-0000000000b1"    /// You's Profile, where the name is edited.    private static let profile = ["-chat-warm-place", "you", "-chat-warm-you", "profile"]    private func launched(_ extra: [String]) -> XCUIApplication {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES"] + extra        app.launch()        return app    }    // RULE: a person's page shows what is between you, mutes for a time from the core's lengths, and asks before Block.    func testAPersonsPageMutesForATimeAndAsksBeforeBlocking() {        let app = launched(["-chat-warm-open", asha, "-chat-warm-person", "YES"])        XCTAssertTrue(app.staticTexts["Calls themselves Asha"].waitForExistence(timeout: 30))        XCTAssertTrue(app.staticTexts["Voice messages"].exists, "the counts between you")        app.buttons["chat-person-mute"].tap()        XCTAssertTrue(app.staticTexts["Mute notifications"].waitForExistence(timeout: 5))        XCTAssertTrue(app.buttons["chat-person-mute-For 8 hours"].exists, "the core's lengths")        XCTAssertTrue(app.buttons["chat-person-mute-always"].exists, "until turned back on")    }    // RULE: Block asks first, in the core's words, with Block and Keep.    func testBlockAsksFirst() {        let app = launched(["-chat-warm-open", asha, "-chat-warm-person", "YES"])        let block = app.buttons["chat-person-block"]        XCTAssertTrue(block.waitForExistence(timeout: 30))        block.tap()        XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH 'Block Asha Verma?'")).firstMatch.waitForExistence(timeout: 5))        XCTAssertTrue(app.buttons["Keep"].exists)    }    // RULE: a group's header opens the group's page: members with admins marked, and who is no longer in it.    func testAGroupsPageListsItsMembers() {        let app = launched(["-chat-warm-open", hillTrip, "-chat-warm-person", "YES"])        XCTAssertTrue(app.staticTexts["4 members"].waitForExistence(timeout: 30))        XCTAssertTrue(app.buttons["chat-group-member-+15550100121"].exists)        XCTAssertTrue(app.staticTexts["Dinesh Kumar"].exists, "who left")        XCTAssertTrue(app.buttons["chat-group-add"].exists, "can.add")    }    // RULE (DISCOVERY OFF 1, 27 Nov 2026): New chat has no "Find people I know"; it offers a number, New group and the people known on Cotton here.    func testNewChatFindsNobodyByTheirNumber() {        let app = launched(["-chat-warm-new", "YES"])        XCTAssertTrue(app.buttons["chat-new-group"].waitForExistence(timeout: 30))        XCTAssertFalse(app.buttons["chat-new-find"].exists, "no Find people I know")    }    // RULE: You's card opens Profile: your name as others see it, and no "people can find me" switch (DISCOVERY OFF 1).    func testYouShowsTheProfile() {        let app = launched(["-chat-warm-place", "you"])        let card = app.buttons["you-card"]        XCTAssertTrue(card.waitForExistence(timeout: 30))        card.tap()        XCTAssertTrue(app.textFields["you-name"].waitForExistence(timeout: 10))        // The profile is read after the page stands: its name lands a moment later.        let named = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value == 'Kavi Rao'"), object: app.textFields["you-name"])        XCTAssertEqual(XCTWaiter.wait(for: [named], timeout: 8), .completed, "the name: \(app.textFields["you-name"].value ?? "none")")        XCTAssertFalse(app.switches["you-findable"].exists)    }    // RULE (owner's iPhone, Chat build 14: the copy made again after the update): while chat.profile is refused, You keeps the name and number it last read, never an empty name asking for one.    func testYouKeepsTheRememberedNameWhileTheProfileIsRefused() {        let first = launched(Self.profile)        XCTAssertTrue(first.textFields["you-name"].waitForExistence(timeout: 30))        XCTAssertEqual(first.textFields["you-name"].value as? String, "Kavi Rao", "read once, so remembered")        first.terminate()        let app = launched(Self.profile + ["-chat-warm-refuse", "chat.profile"])        let field = app.textFields["you-name"]        XCTAssertTrue(field.waitForExistence(timeout: 30))        let named = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value == 'Kavi Rao'"), object: field)        XCTAssertEqual(XCTWaiter.wait(for: [named], timeout: 8), .completed, "the remembered name, not the hint (\(field.value ?? "none")): " + String(app.debugDescription.prefix(2000)))        XCTAssertTrue(app.staticTexts["+15550100100"].exists, "the remembered number")        XCTAssertFalse(app.staticTexts["How people see you"].exists, "no hint asking for a name")    }    // RULE (owner's iPhone, Comms build 19: blank beside the picture, then filled): You draws the name and number it last read on its first frame, while chat.profile is still out.    func testYouDrawsTheRememberedProfileOnTheFirstFrame() {        let first = launched(Self.profile)        let read = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value == 'Kavi Rao'"), object: first.textFields["you-name"])        XCTAssertEqual(XCTWaiter.wait(for: [read], timeout: 30), .completed, "read once, so remembered")        first.terminate()        // On You's card at once, while chat.profile answers three seconds late.        let top = launched(["-chat-warm-place", "you", "-chat-warm-slow", "chat.profile"])        let card = top.buttons["you-card"]        XCTAssertTrue(card.waitForExistence(timeout: 30))        XCTAssertTrue(card.label.hasPrefix("Kavi Rao"), "the remembered name on the card as You first stands: \(card.label)")        XCTAssertTrue(card.label.contains("+15550100100"), "and the remembered number")        top.terminate()        let app = launched(Self.profile + ["-chat-warm-slow", "chat.profile"])        let field = app.textFields["you-name"]        XCTAssertTrue(field.waitForExistence(timeout: 30))        // Asked at once: chat.profile answers three seconds late.        XCTAssertEqual(field.value as? String, "Kavi Rao", "the remembered name as You first stands")        keepShot("fb-you-first-remembered")        XCTAssertTrue(app.staticTexts["+15550100100"].exists, "the remembered number as You first stands")    }    // RULE: with nothing remembered yet, You draws the signed-in number at once and the name as soon as it is known; never an empty profile.    func testWithNothingRememberedYouDrawsTheNumberAtOnce() {        let app = launched(Self.profile + ["-chat-warm-slow", "chat.profile", "-chat.you.remembered", "none"])        let field = app.textFields["you-name"]        XCTAssertTrue(field.waitForExistence(timeout: 30))        XCTAssertTrue(app.staticTexts["+15550100100"].exists, "the signed-in number as You first stands: " + String(app.debugDescription.prefix(2000)))        keepShot("fb-you-first-number")        let named = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value == 'Kavi Rao'"), object: field)        XCTAssertEqual(XCTWaiter.wait(for: [named], timeout: 10), .completed, "the name once the profile answers")        keepShot("fb-you-named")        XCTAssertTrue(app.staticTexts["+15550100100"].exists)        app.terminate()        let privacy = launched(["-chat-warm-place", "you", "-chat-warm-you", "privacy"])        XCTAssertTrue(privacy.staticTexts["Comms never shows when you were last here."].waitForExistence(timeout: 30), "the app's name in You's words")        keepShot("fb-words-you")    }    // RULE (as Android's YouSyncLineTest, 24369c4bf0): You's Sync row, and the Sync page, say how sync stands in the core's own glance.    func testYouSaysHowSyncStands() {        let app = launched(["-chat-warm-place", "you"])        let row = app.buttons["you-row-sync"]        XCTAssertTrue(row.waitForExistence(timeout: 30), String(app.debugDescription.prefix(3000)))        // shell.account's glances (the boot kit's account.tile lines).        let glances = ["Signed out", "Syncing your data…", "Not syncing", "Not synced yet", "Syncing…", "Synced just now", "Signed in", "Loading your data…"]        let glance = String(row.label.dropFirst("Sync, ".count))        XCTAssertTrue(glances.contains(glance) || glance.hasPrefix("Synced at ") || glance.hasSuffix("waiting to sync"), "the core's glance, said as it says it: \(row.label)")        row.tap()        let state = app.staticTexts["you-sync-state"]        XCTAssertTrue(state.waitForExistence(timeout: 10))        XCTAssertEqual(state.label, glance, "the page says what the row said")    }    // RULE: the plus beside the writing box opens the attachment sheet: Photos and videos, and File.    func testThePlusOpensTheAttachmentSheet() {        let app = launched(["-chat-warm-open", asha])        let plus = app.buttons["chat-attach"]        XCTAssertTrue(plus.waitForExistence(timeout: 30))        plus.tap()        XCTAssertTrue(app.buttons["chat-attach-photo"].waitForExistence(timeout: 5), String(app.debugDescription.prefix(4000)))        XCTAssertTrue(app.buttons["chat-attach-file"].exists)    }    // RULE: Calls lists the log newest first, a missed call in its own words.    func testCallsListsTheLog() {        let app = launched(["-chat-warm-place", "calls"])        XCTAssertTrue(app.buttons.matching(identifier: "chat-call-row").firstMatch.waitForExistence(timeout: 30))        XCTAssertTrue(app.buttons.matching(NSPredicate(format: "label CONTAINS 'Missed voice call'")).firstMatch.exists)    }}