Cotton code
86 lines · 5.4 KB · SwiftRaw
// A group call on the iPhone (chat/CONTRACT.md "Group calls", "The screen"), over the core's own screens for invented// calls (`-chat-warm-call group|group8|group-notes`, Fixtures/chat-group-call.json written by cotton-core// `write_group_call_seed`): a tile per person in the core's grid, who talks and who is muted, the privacy line and what// a tap on it says, the notes mark, and the red button labelled Leave; all in the window at the largest text.import XCTestfinal class ChatGroupCallTests: XCTestCase {    private func launched(_ state: String, large: Bool = false) -> XCUIApplication {        let app = XCUIApplication()        app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-call", state]        if large { app.launchArguments += ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"] }        app.launch()        return app    }    private func tiles(_ app: XCUIApplication) -> XCUIElementQuery {        app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'chat-call-tile-' AND NOT (identifier IN {'chat-call-tile-name', 'chat-call-tile-muted', 'chat-call-tile-speaking'})"))    }    private func assertInWindow(_ element: XCUIElement, _ app: XCUIApplication, _ what: String, file: StaticString = #filePath, line: UInt = #line) {        let window = app.windows.firstMatch.frame        XCTAssertTrue(element.exists, "\(what) stands", file: file, line: line)        XCTAssertTrue(window.contains(element.frame), "\(what) is in the window: \(element.frame) in \(window)", file: file, line: line)    }    // RULE: four people on video: a tile each in two by two, you last; Asha talks, Ravi is muted, Meera is still rung.    func testATileForEachPersonInTheGrid() {        let app = launched("group")        XCTAssertTrue(app.descendants(matching: .any)["chat-call-tiles"].waitForExistence(timeout: 30), "the group's tiles stand")        XCTAssertEqual(tiles(app).count, 4, "one tile each: \(tiles(app).allElementsBoundByIndex.map { $0.identifier })")        let you = app.descendants(matching: .any)["chat-call-tile-you"]        let asha = app.descendants(matching: .any)["chat-call-tile-m1"]        let meera = app.descendants(matching: .any)["chat-call-tile-m3"]        XCTAssertTrue(you.exists && asha.exists && meera.exists)        XCTAssertGreaterThan(you.frame.minY, asha.frame.minY, "you last, in the grid's second row")        XCTAssertEqual(asha.frame.width, you.frame.width, accuracy: 1, "two columns of one width")        XCTAssertTrue(asha.descendants(matching: .any)["chat-call-tile-speaking"].exists, "Asha talks: her tile rings")        XCTAssertTrue(app.descendants(matching: .any)["chat-call-tile-m2"].descendants(matching: .any)["chat-call-tile-muted"].exists, "Ravi is muted")        XCTAssertTrue(meera.staticTexts["Meera Example · Ringing…"].exists, "Meera is still rung")        XCTAssertEqual(app.buttons["chat-call-end"].label, "Leave", "the red button leaves")    }    // RULE: the screen says the call is protected in transit, and a tap says what that means; never end to end.    func testThePrivacyLineSaysWhatProtectsIt() {        let app = launched("group")        let privacy = app.buttons["chat-call-privacy"]        XCTAssertTrue(privacy.waitForExistence(timeout: 30))        XCTAssertTrue(privacy.label.hasPrefix("Protected in transit"), privacy.label)        XCTAssertFalse(app.descendants(matching: .any)["chat-call-privacy-detail"].exists)        privacy.tap()        XCTAssertTrue(app.descendants(matching: .any)["chat-call-privacy-detail"].waitForExistence(timeout: 5), "a tap says more")        XCTAssertFalse(privacy.label.lowercased().contains("end to end") && !privacy.label.lowercased().contains("not end to end"), privacy.label)    }    // RULE: someone taking notes: the mark stands on the screen naming them, and their tile carries it.    func testTheNotesMarkStands() {        let app = launched("group-notes")        let mark = app.descendants(matching: .any)["chat-call-notes"]        XCTAssertTrue(mark.waitForExistence(timeout: 30))        XCTAssertEqual(mark.label, "Asha Example is taking notes")    }    // RULE: Take notes refused because someone cannot show the mark is said on the screen, in the core's words; the    // iPhone offers no Take notes of its own until it records them.    func testARefusedTakeNotesIsSaid() {        let app = launched("group-notice")        let notice = app.descendants(matching: .any)["chat-call-notice"]        XCTAssertTrue(notice.waitForExistence(timeout: 30))        XCTAssertEqual(notice.label, "Notes can't be taken: Ravi Example's Comms needs updating.")        XCTAssertFalse(app.buttons["chat-call-notes"].exists, "no Take notes on the iPhone yet")    }    // RULE: eight on a call: two by four, every tile, the controls and Leave in the window, at the largest text too.    func testEightFitAtTheLargestText() {        for large in [false, true] {            let app = launched("group8", large: large)            XCTAssertTrue(app.descendants(matching: .any)["chat-call-tiles"].waitForExistence(timeout: 30))            XCTAssertEqual(tiles(app).count, 8)            for tile in tiles(app).allElementsBoundByIndex { assertInWindow(tile, app, tile.identifier) }            assertInWindow(app.buttons["chat-call-end"], app, "Leave")            assertInWindow(app.buttons["chat-call-mute"], app, "Mute")            app.terminate()        }    }}