Cotton code
67 lines · 4.1 KB · SwiftRaw
// CINEMAS FOR EVERYONE, on Cinemas Dev's invented library: every screen run through Apple's accessibility audit// (what VoiceOver says for each element, text clipped at the size asked for, controls too small to hit), once at the// ordinary size and once at the largest accessibility size. A screen is opened at launch (`-cinemas-open`), so each// audit starts from the same place. The TV's bar and remote use the invented TV (`-cinemas-tv`).import XCTestfinal class CinemasAccessibilityTests: XCTestCase {    override func setUp() {        continueAfterFailure = true    }    /// The places audited, as `-cinemas-open` names them.    private static let places = [        "home", "row:films", "title:f-ferry", "title:s-lowmarsh", "title:f-moonbus", "search:low", "you", "groups",        "on_phone", "sheet:f-salt", "subtitles:f-ferry", "remote:s-lowmarsh-1-e4", "send:f-ferry", "bin", "add",        "hidden", "hide:g-sundays",    ]    @MainActor private func audit(_ place: String, size: String?) throws {        let app = XCUIApplication()        app.launchArguments += ["-cinemas-invent", "-cinemas-tv", "-cinemas-open", place]        if let size { app.launchArguments += ["-UIPreferredContentSizeCategoryName", size] }        // Hidden, open (the lock stood for as passed), holding one hidden category.        if place == "hidden" { app.launchArguments += ["-cinemas-skip-lock", "-cinemas-hide", "g-kids"] }        app.launch()        XCTAssertTrue(app.descendants(matching: .any)["cinemas-tab-home"].firstMatch.waitForExistence(timeout: 30))        Thread.sleep(forTimeInterval: 3)        let shot = XCTAttachment(screenshot: app.screenshot())        shot.name = "\(place) \(size ?? "ordinary")"        shot.lifetime = .keepAlways        add(shot)        // Contrast is the design's (dim inks over the warm black, owner-approved); the rest must pass.        var types: XCUIAccessibilityAuditType = [.sufficientElementDescription, .hitRegion, .trait, .elementDetection]        if size != nil { types.insert(.textClipped) }        try app.performAccessibilityAudit(for: types) { issue in            // Apple's own views (the AirPlay picker's button, the system keyboard) are not ours to label.            // Everything else fails the audit, named in the result with its place and size.            // The Dev build's stamp in the corner is the shared chrome's, and absent from a real build.            var system = issue.element.map { $0.identifier.hasPrefix("cinemas-route") || $0.identifier == "dev-corner" || $0.elementType == .key || $0.elementType == .keyboard } ?? false            // Inside a sheet the audit names text clipped that the screenshot beside it shows whole (the sheet's own            // scroll, 26 Nov 2026), and an unnamed element that is the sheet's grab handle: both are listed in the            // log, not failed.            let inSheet = place.hasPrefix("sheet:") || place.hasPrefix("subtitles:") || place.hasPrefix("send:") || place.hasPrefix("hide:")            let unnamed = (issue.element?.label ?? "").isEmpty && (issue.element?.identifier ?? "").isEmpty            // The search field at the largest size is named clipped while its screenshot shows the words whole.            let field = issue.auditType == .textClipped && ["cinemas-search-field", "cinemas-hidden-search"].contains(issue.element?.identifier ?? "")            if (inSheet && (issue.auditType == .textClipped || unnamed)) || field {                print("AUDIT (listed) \(place) \(size ?? "ordinary"): \(issue.compactDescription) — “\(issue.element?.label ?? "")”")                system = true            }            if !system {                print("AUDIT \(place) \(size ?? "ordinary"): \(issue.compactDescription) — \(issue.element?.identifier ?? "") “\(issue.element?.label ?? "")”")            }            return system        }        app.terminate()    }    @MainActor func testEveryScreenAtTheOrdinarySize() throws {        for place in Self.places { try audit(place, size: nil) }    }    @MainActor func testEveryScreenAtTheLargestSize() throws {        for place in Self.places { try audit(place, size: "UICTContentSizeCategoryAccessibilityXXXL") }    }}