Cotton code
81 lines · 3.8 KB · SwiftRaw
// Deleting a chat from the list (owner, FEEDBACK-4 B2, Comms 26: "deleting a// chat from the chat list does not make it go away"). Over Comms Dev's// invented chats (-chat-warm-seed YES, the core's own chat.list answers):// Delete asks first in the core's words, then the chat leaves the list at// once and stays gone when the list is read again; a WhatsApp chat's question// says it leaves Cotton only and stays in WhatsApp. At the default size and// the largest. The core's half (a chat stamped later than this phone's clock// never left) is 1be15501aa.import XCTestfinal class ChatDeleteChatTests: XCTestCase {    private let asha = "11111111-1111-4111-8111-0000000000a1"    private let tara = "11111111-1111-4111-8111-0000000000f1"    private static let largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"]    override func setUp() {        continueAfterFailure = false        XCUIDevice.shared.orientation = .portrait    }    private func launched(_ extra: [String]) -> XCUIApplication {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES"] + extra        app.launch()        return app    }    private func row(_ app: XCUIApplication, _ thread: String) -> XCUIElement {        app.descendants(matching: .any)["chat-row-\(thread)"].firstMatch    }    private func keep(_ name: String) {        let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())        shot.name = name        shot.lifetime = .keepAlways        add(shot)    }    /// Held, Delete chosen from its menu, the question answered Delete: the chat goes at once and stays gone.    @MainActor private func deletes(_ thread: String, _ extra: [String], asks words: [String], _ shots: String) {        let app = launched(extra)        let chat = row(app, thread)        XCTAssertTrue(chat.waitForExistence(timeout: 30), "the chat is listed")        _ = ShellCard.refuse(app).waitForExistence(timeout: 6)        chat.press(forDuration: 1.0)        let delete = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Delete'")).firstMatch        XCTAssertTrue(delete.waitForExistence(timeout: 5), "the hold offers Delete")        delete.tap()        let yes = app.buttons["look-ask-delete"]        XCTAssertTrue(yes.waitForExistence(timeout: 5), "Delete asks first")        let asked = app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH 'Delete your chat'")).firstMatch        XCTAssertTrue(asked.exists, "in the core's words")        for word in words { XCTAssertTrue(asked.label.contains(word), "the question says \"\(word)\": \(asked.label)") }        keep("delete-chat-\(shots)-ask")        yes.tap()        let gone = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == false"), object: chat)        XCTAssertEqual(XCTWaiter.wait(for: [gone], timeout: 3), .completed, "deleted, it leaves the list at once")        keep("delete-chat-\(shots)-gone")        // Read again (another place and back): still gone.        app.buttons["chat-filter-unread"].tap()        app.buttons["chat-filter-all"].tap()        Thread.sleep(forTimeInterval: 1.5)        XCTAssertFalse(row(app, thread).exists, "it stays gone when the list is read again")    }    // RULE: a deleted chat leaves the list at once and stays gone.    @MainActor func testADeletedChatLeavesAtOnceAndStaysGone() {        deletes(asha, [], asks: ["other devices"], "default")    }    @MainActor func testADeletedChatLeavesAtOnceAndStaysGoneAtTheLargestText() {        deletes(asha, Self.largestText, asks: ["other devices"], "largest")    }    // RULE: a WhatsApp chat's question says it leaves Cotton only and stays in WhatsApp.    @MainActor func testDeletingAWhatsAppChatSaysItStaysInWhatsApp() {        deletes(tara, ["-chat-warm-linked", "YES"], asks: ["from Cotton", "stays in WhatsApp"], "whatsapp")    }}