Cotton code
59 lines · 3.7 KB · SwiftRaw
// The report a shake opens, as every app with a look of its own draws it// (owner, 22 Nov 2026): the one question "What looks wrong?", one field, the// small line saying the screen and the log go with it, Cancel and Send, and// nothing else to fill in or choose. Opened by `-report-sheet-open YES` (a// development build only: the root shakes once the file is open), since a// simulator test has no shake to send. Nothing is ever sent from here.import XCTestenum ReportSheetUI {    /// The launch argument that opens the report once the app has its file.    static let open = ["-report-sheet-open", "YES"]    @MainActor static func id(_ app: XCUIApplication, _ identifier: String) -> XCUIElement {        app.descendants(matching: .any).matching(identifier: identifier).firstMatch    }    /// The report stands with its one question, one field and Send, nothing    /// else to fill in or choose, and the small line; Send wakes once    /// something is written. Cancel then closes it, sending nothing.    @MainActor static func assertMinimal(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let sheet = id(app, "report-sheet")        XCTAssertTrue(sheet.waitForExistence(timeout: 90), "the report came up", file: file, line: line)        let title = id(app, "report-title")        XCTAssertTrue(title.waitForExistence(timeout: 5), "the question stands", file: file, line: line)        XCTAssertEqual(title.label, "What looks wrong?", "the one question", file: file, line: line)        XCTAssertFalse(app.staticTexts["Report a problem"].exists, "no kicker over the question", file: file, line: line)        let fields = sheet.textFields.count + sheet.textViews.count + sheet.secureTextFields.count        XCTAssertEqual(fields, 1, "one field", file: file, line: line)        for (kind, count) in [("picker", sheet.pickers.count + sheet.pickerWheels.count), ("switch", sheet.switches.count),                              ("segmented control", sheet.segmentedControls.count), ("slider", sheet.sliders.count),                              ("stepper", sheet.steppers.count), ("picture", sheet.images.count)] {            XCTAssertEqual(count, 0, "no \(kind) on the report", file: file, line: line)        }        XCTAssertFalse(id(app, "report-snapshot").exists, "the picture goes without being shown", file: file, line: line)        XCTAssertFalse(id(app, "report-dictate").exists, "no microphone of the app's own: the keyboard's dictation", file: file, line: line)        let buttons = sheet.buttons.allElementsBoundByIndex.map(\.identifier).sorted()        XCTAssertEqual(buttons, ["report-cancel", "report-send"], "Cancel and Send, no other choice", file: file, line: line)        let goes = id(app, "report-goes-with")        XCTAssertTrue(goes.exists, "the small line stands", file: file, line: line)        XCTAssertTrue(            ["The screen you were on and the app's recent log go with it.", "The app's recent log goes with it."].contains(goes.label),            "the small line says what goes with it: \(goes.label)", file: file, line: line)        let send = id(app, "report-send")        XCTAssertTrue(send.exists, "Send stands", file: file, line: line)        XCTAssertFalse(send.isEnabled, "Send sleeps while nothing is written", file: file, line: line)        let field = id(app, "report-note")        field.tap()        field.typeText("The second row shows yesterday")        XCTAssertTrue(send.isEnabled, "Send wakes once something is written", file: file, line: line)        let cancel = id(app, "report-cancel")        cancel.tap()        XCTAssertTrue(sheet.waitForNonExistence(timeout: 5), "Cancel closes it, sending nothing", file: file, line: line)    }}