// Comms Dev over invented chats (-chat-warm-seed YES, the core's own// chat.list answers): the Unread filter lists only unread chats, Mark as// unread (a row's hold) puts a chat there, and opening it clears it (owner,// Comms build 19: "Waiting on you" becomes Unread).import XCTestfinalclassChatUnreadTests: XCTestCase {privatelet ravi = "11111111-1111-4111-8111-0000000000d1"privatelet asha = "11111111-1111-4111-8111-0000000000a1"privatelet hillTrip = "11111111-1111-4111-8111-0000000000b1"privatelet meera = "11111111-1111-4111-8111-0000000000e1"privatefunc launched() -> XCUIApplication {let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES"] app.launch()return app }privatefunc row(_ app: XCUIApplication, _ thread: String) -> XCUIElement { app.descendants(matching: .any)["chat-row-\(thread)"].firstMatch }// RULE: the filters are All, Unread and Groups; Unread lists only the chats with something unread.func testTheUnreadFilterListsOnlyUnreadChats() {let app = launched()let unread = app.buttons["chat-filter-unread"] XCTAssertTrue(unread.waitForExistence(timeout: 30), "the Unread filter stands") XCTAssertFalse(app.buttons["chat-filter-waiting"].exists, "Waiting on you is gone") unread.tap() XCTAssertTrue(row(app, asha).waitForExistence(timeout: 5)) XCTAssertTrue(row(app, meera).exists) XCTAssertFalse(row(app, ravi).exists, "a read chat is not listed") XCTAssertFalse(row(app, hillTrip).exists, "a read group is not listed") keepShot("fb-unread-filter") }// RULE: Mark as unread, from a row's hold, puts a read chat under Unread; opening it clears the mark.func testMarkAsUnreadPutsAChatUnderUnreadAndOpeningItClearsIt() {let app = launched()let hill = row(app, hillTrip) XCTAssertTrue(hill.waitForExistence(timeout: 30)) hill.press(forDuration: 1.0)let mark = app.buttons["Mark as unread"] XCTAssertTrue(mark.waitForExistence(timeout: 5), "the hold offers Mark as unread: " + String(app.debugDescription.prefix(3000))) keepShot("fb-unread-hold-menu") mark.tap() app.buttons["chat-filter-unread"].tap() XCTAssertTrue(row(app, hillTrip).waitForExistence(timeout: 5), "marked, it is under Unread") XCTAssertTrue(row(app, hillTrip).label.contains("Unread"), "it says so: \(row(app, hillTrip).label)") keepShot("fb-unread-marked") row(app, hillTrip).tap()let back = app.descendants(matching: .any)["chat-back"].firstMatch XCTAssertTrue(back.waitForExistence(timeout: 10), "the chat opened") back.tap()let gone = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == false"), object: row(app, hillTrip)) XCTAssertEqual(XCTWaiter.wait(for: [gone], timeout: 8), .completed, "opened, it is read and leaves Unread") app.buttons["chat-filter-all"].tap() XCTAssertTrue(row(app, hillTrip).waitForExistence(timeout: 5)) XCTAssertFalse(row(app, hillTrip).label.contains("Unread"), "the mark is cleared: \(row(app, hillTrip).label)") }}