// Every Chat panel rises whole (owner, Chat build 13 on a real iPhone): on You, // Blocked and Change picture rose under the Chats / Calls / You pill, only the // title showing. Each panel here is opened over Chat Dev's invented people and // its LAST control must be hittable: on the phone's own size, home indicator // and all, nothing over it. import XCTest final class ChatWarmPanelsTests: XCTestCase { private let asha = "11111111-1111-4111-8111-0000000000a1" private let hillTrip = "11111111-1111-4111-8111-0000000000b1" private let ravi = "11111111-1111-4111-8111-0000000000d1" private func launched(_ extra: [String]) -> XCUIApplication { let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES"] + extra app.launch() return app } /// A finger put down on `element` (a panel's row) and pulled down 320 points quickly, as a person closes a panel. private func pullDown(_ element: XCUIElement) { let start = element.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) start.press(forDuration: 0.01, thenDragTo: start.withOffset(CGVector(dx: 0, dy: 320)), withVelocity: .fast, thenHoldForDuration: 0) } /// The panel's last button or line stands where a finger can reach it, and the pill is not over it. private func assertWhole(_ app: XCUIApplication, _ panel: String, last: XCUIElement? = nil, _ line: UInt = #line) { let sheet = app.descendants(matching: .any)[panel].firstMatch XCTAssertTrue(sheet.waitForExistence(timeout: 5), "\(panel) rose", line: line) let end = last ?? sheet.descendants(matching: .any) .matching(NSPredicate(format: "elementType == %d OR elementType == %d", XCUIElement.ElementType.button.rawValue, XCUIElement.ElementType.staticText.rawValue)) .allElementsBoundByIndex.last guard let end else { return XCTFail("\(panel) has no control", line: line) } XCTAssertTrue(end.waitForExistence(timeout: 3), "\(panel)'s last control stands", line: line) // A panel rises with an animation: give it the moment it takes. let hittable = NSPredicate(format: "isHittable == true") let waited = XCTWaiter.wait(for: [XCTNSPredicateExpectation(predicate: hittable, object: end)], timeout: 3) XCTAssertEqual(waited, .completed, "\(panel)'s last control (\(end.identifier) \(end.label)) is hittable: " + String(app.debugDescription.prefix(3000)), line: line) XCTAssertLessThanOrEqual(end.frame.maxY, app.windows.firstMatch.frame.maxY, "\(panel) ends on the screen", line: line) let pill = app.buttons["chat-place-you"] XCTAssertFalse(pill.exists && pill.isHittable, "the pill steps away while \(panel) stands", line: line) } // RULE: on You's Privacy, Blocked people rises whole above the home indicator, no pill under it. func testYousBlockedRisesWhole() { let app = launched(["-chat-warm-place", "you", "-chat-warm-you", "privacy"]) let blocked = app.buttons["you-blocked"] XCTAssertTrue(blocked.waitForExistence(timeout: 30)) blocked.tap() assertWhole(app, "you-blocked-sheet") } // RULE: on You's Profile, Change picture's choices rise whole. func testYoursPictureChoicesRiseWhole() { let app = launched(["-chat-warm-place", "you", "-chat-warm-you", "profile"]) let picture = app.buttons["you-picture"] XCTAssertTrue(picture.waitForExistence(timeout: 30)) picture.tap() let remove = app.buttons["look-ask-remove"] XCTAssertTrue(app.buttons["look-ask-choose"].waitForExistence(timeout: 5)) assertWhole(app, "look-ask-choose", last: remove.exists ? remove : app.buttons["look-ask-choose"]) } // RULE: You's account facts stand on About alone, not among the rows. @MainActor func testYoursAccountKeepsItsFactsUnderAbout() { let top = launched(["-chat-warm-place", "you"]) XCTAssertTrue(top.descendants(matching: .any)["you-row-about"].waitForExistence(timeout: 30), String(top.debugDescription.prefix(3000))) XCTAssertEqual(top.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'settings-about-'")).count, 0) top.terminate() SettingsPartsUI.assertFactsUnderAbout(launched(["-chat-warm-place", "you", "-chat-warm-you", "about"])) } // RULE: Share a report's preview rises whole, Close and Share in the window. @MainActor func testYoursReportRisesWhole() { let app = launched(["-chat-warm-place", "you", "-chat-warm-you", "help"]) let share = app.descendants(matching: .any)["settings-share-report"] XCTAssertTrue(share.waitForExistence(timeout: 30)) SettingsPartsUI.reach(app, share) share.tap() assertWhole(app, "settings-report-preview", last: app.buttons["settings-report-share"]) } // RULE: Delete's ask on the Chats list rises whole above the pill's place. func testChatsDeleteAskRisesWhole() throws { let app = launched([]) let row = app.cells.firstMatch XCTAssertTrue(row.waitForExistence(timeout: 30)) // Delete is the long press's (Comms 28: a swipe left archives). row.press(forDuration: 1.0) let delete = app.buttons.matching(NSPredicate(format: "label == 'Delete'")).firstMatch guard delete.waitForExistence(timeout: 3) else { throw XCTSkip("the first row offers no Delete") } delete.tap() assertWhole(app, "look-ask-keep", last: app.buttons["look-ask-keep"]) } // RULE: a person's Mute and Block's ask rise whole, and a pull down closes Mute. func testAPersonsPanelsRiseWhole() { let app = launched(["-chat-warm-open", asha, "-chat-warm-person", "YES"]) let mute = app.buttons["chat-person-mute"] XCTAssertTrue(mute.waitForExistence(timeout: 30)) mute.tap() assertWhole(app, "chat-person-mute-always", last: app.buttons["chat-person-mute-always"]) pullDown(app.buttons["chat-person-mute-always"]) XCTAssertTrue(app.buttons["chat-person-mute-always"].waitForNonExistence(timeout: 5), "a pull down closes it") app.buttons["chat-person-block"].tap() assertWhole(app, "look-ask-keep", last: app.buttons["look-ask-keep"]) } // RULE: a group's member choices, Rename and Leave's ask rise whole, and a pull down closes Rename. func testAGroupsPanelsRiseWhole() { let app = launched(["-chat-warm-open", hillTrip, "-chat-warm-person", "YES"]) let member = app.buttons["chat-group-member-+15550100121"] XCTAssertTrue(member.waitForExistence(timeout: 30)) member.tap() assertWhole(app, "look-ask-keep", last: app.buttons["look-ask-keep"]) app.buttons["look-ask-keep"].tap() app.buttons["chat-group-rename"].tap() assertWhole(app, "chat-name-save", last: app.buttons["chat-name-save"]) pullDown(app.buttons["chat-name-save"]) XCTAssertTrue(app.buttons["chat-name-save"].waitForNonExistence(timeout: 5), "a pull down closes it") let leave = app.buttons["chat-group-leave"] leave.swipeUp() leave.tap() assertWhole(app, "look-ask-keep", last: app.buttons["look-ask-keep"]) } // RULE: in a conversation, the attachment sheet and the invite rise whole. func testAConversationsPanelsRiseWhole() { let app = launched(["-chat-warm-open", asha]) let plus = app.buttons["chat-attach"] XCTAssertTrue(plus.waitForExistence(timeout: 30)) plus.tap() assertWhole(app, "chat-attach-sheet", last: app.buttons["chat-attach-file"]) app.terminate() let notYet = launched(["-chat-warm-open", ravi]) let invite = notYet.buttons["chat-reach-invite"] XCTAssertTrue(invite.waitForExistence(timeout: 30)) invite.tap() assertWhole(notYet, "chat-invite-share", last: notYet.buttons["chat-invite-share"]) } }