// 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 XCTest final class ChatWhatsAppTimerTests: XCTestCase { private let tara = "11111111-1111-4111-8111-0000000000f1" private static let largestText = ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"] private let ownCopy = "Only your copy in Cotton. WhatsApp keeps its own." override func setUp() { continueAfterFailure = false XCUIDevice.shared.orientation = .portrait } private func keep(_ name: String) { let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) shot.name = name shot.lifetime = .keepAlways add(shot) } @MainActor private func 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 private func reach(_ element: XCUIElement, in app: XCUIApplication, up: Bool = true, _ what: String) { for _ in 0..<8 where !(element.exists && element.isHittable) { if up { app.swipeUp() } else { app.swipeDown() } } XCTAssertTrue(element.exists && element.isHittable, "\(what) can be reached") } @MainActor private func 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 private func 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)") if let 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 private func 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 private func 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 = .dark defer { XCUIDevice.shared.appearance = .light } walk([], "night") } }