// Disappearing messages on a WhatsApp chat, his own copy only (FEEDBACK-2// B.2, CONTRACT.md "Disappearing messages on a WhatsApp chat"), over Chat Dev's// invented chats (-chat-warm-seed YES: the core's own answers on a copy linked// through an invented Mac, written by write_chat_warm_fixture). Tara's chat// came from WhatsApp: her page has the row near the top, Off; its sheet offers// the four lengths and the core's note, "Only your copy in Cotton. WhatsApp// keeps its own."; 7 days chosen stands on the row, in the header and as the// chat's line, and Off clears it. The phone only draws what the core answers.// At the default text size and the largest.import XCTestfinalclassChatWhatsAppTimerTests: XCTestCase {privatelet tara = "11111111-1111-4111-8111-0000000000f1"privatestaticlet largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"]privatelet ownCopy = "Only your copy in Cotton. WhatsApp keeps its own."overridefunc setUp() { continueAfterFailure = false XCUIDevice.shared.orientation = .portrait }privatefunc keep(_ name: String) {let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) shot.name = name shot.lifetime = .keepAlways add(shot) } @MainActor privatefunc element(_ id: String, in app: XCUIApplication) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }/// Scrolls the page until `element` can be touched: up (toward the foot) or down (back to the top). @MainActor privatefunc reach(_ element: XCUIElement, in app: XCUIApplication, up: Bool = true, _ what: String) {for _ in0..<8where !(element.exists && element.isHittable) { if up { app.swipeUp() } else { app.swipeDown() } } XCTAssertTrue(element.exists && element.isHittable, "\(what) can be reached") } @MainActor privatefunc says(_ row: XCUIElement, _ length: String) {let said = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label BEGINSWITH %@ AND label ENDSWITH %@", "Disappearing messages", length), object: row) XCTAssertEqual(XCTWaiter.wait(for: [said], timeout: 8), .completed, "the row says \(length): \(row.label)") } @MainActor privatefunc choose(_ seconds: Int, from row: XCUIElement, in app: XCUIApplication, _ shot: String? = nil) { row.tap() XCTAssertTrue(element("chat-timer-sheet", in: app).waitForExistence(timeout: 5), "its sheet opens")for length in [0, 86_400, 604_800, 7_776_000] { XCTAssertTrue(app.buttons["chat-timer-\(length)"].exists, "\(length) is offered") }let note = app.staticTexts["chat-timer-note"] XCTAssertTrue(note.exists, "the core's note") XCTAssertTrue(note.label.contains(ownCopy), "it says it is his own copy only: \(note.label)")iflet shot { keep(shot) }let chosen = app.buttons["chat-timer-\(seconds)"] reach(chosen, in: app, "the length") chosen.tap() XCTAssertTrue(element("chat-timer-sheet", in: app).waitForNonExistence(timeout: 5), "the sheet goes") } @MainActor privatefunc backToTheChat(_ app: XCUIApplication) {let back = app.buttons["chat-person-back"] reach(back, in: app, up: false, "Back") back.tap() XCTAssertTrue(app.tables["chat-thread"].waitForExistence(timeout: 10), "the chat") } @MainActor privatefunc walk(_ extra: [String], _ shots: String) {let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-open", tara, "-chat-warm-person", "YES"] + extra app.launch()let row = app.buttons["chat-timer"] XCTAssertTrue(row.waitForExistence(timeout: 30), "Disappearing messages on Tara's page")Thread.sleep(forTimeInterval: 1.5) reach(row, in: app, up: false, "Disappearing messages") says(row, "Off") keep("wa-timer-\(shots)-row") choose(604_800, from: row, in: app, "wa-timer-\(shots)-sheet") says(row, "7 days") backToTheChat(app)let header = app.buttons["chat-person"] XCTAssertTrue(header.label.contains("7 days"), "the header says it: \(header.label)") XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "You turned on disappearing messages")).firstMatch.waitForExistence(timeout: 10),"the line in his copy of the chat") keep("wa-timer-\(shots)-on") header.tap() XCTAssertTrue(row.waitForExistence(timeout: 10), "her page again") reach(row, in: app, up: false, "Disappearing messages") choose(0, from: row, in: app) says(row, "Off") backToTheChat(app) XCTAssertFalse(app.buttons["chat-person"].label.contains("7 days"), "the header no longer says it") }// RULE: a WhatsApp chat's page has Disappearing messages, Off by default; its sheet says it is his own copy only;// a length chosen stands on the row, in the header and as the chat's line; Off clears it. @MainActor func testAWhatsAppChatsTimerIsHisOwnCopyOnly() { walk([], "default") } @MainActor func testAWhatsAppChatsTimerIsHisOwnCopyOnlyAtTheLargestText() { walk(Self.largestText, "largest") } @MainActor func testAWhatsAppChatsTimerIsHisOwnCopyOnlyAtNight() { XCUIDevice.shared.appearance = .darkdefer { XCUIDevice.shared.appearance = .light } walk([], "night") }}