krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

App/UITests/AccessibilityAuditTests.swift

v1.0.0
moonrise/App/UITests/AccessibilityAuditTests.swift history · blame · raw

49 lines · 1754 bytes

 1import XCTest
 2
 3/// Runs Xcode's accessibility audit on each main screen and prints every issue.
 4/// Issues are recorded, not failed, so one run reports everything.
 5final class AccessibilityAuditTests: XCTestCase {
 6    var app: XCUIApplication!
 7    var issues: [String] = []
 8
 9    override func setUp() {
10        continueAfterFailure = true
11        app = XCUIApplication()
12        app.launchArguments += ["-onboarded", "YES", "-locationMode", "city", "-nightMode", "off"]
13        app.launch()
14    }
15
16    private func audit(_ screen: String, _ types: XCUIAccessibilityAuditType = .all) {
17        try? app.performAccessibilityAudit(for: types) { issue in
18            let label = issue.element?.label ?? ""
19            let id = issue.element?.identifier ?? ""
20            let line = "[\(screen)] \(issue.auditType): \(issue.compactDescription) — element: '\(label)' \(id)"
21            self.issues.append(line)
22            print("A11Y " + line)
23            return true
24        }
25    }
26
27    private func tab(_ name: String) {
28        app.tabBars.buttons[name].firstMatch.tap()
29        sleep(3)
30    }
31
32    func testAuditAllScreens() {
33        sleep(3)
34        audit("Sky")
35        app.buttons["Settings"].tap(); sleep(1)
36        audit("Settings")
37        app.buttons["Done"].tap(); sleep(1)
38        tab("System"); audit("System")
39        tab("Sun"); audit("Sun")
40        tab("Launches"); audit("Launches")
41        tab("Library"); audit("Library")
42        app.staticTexts["Planets"].firstMatch.tap(); sleep(1)
43        app.staticTexts["Saturn"].firstMatch.tap(); sleep(2)
44        audit("Library page: Saturn")
45        print("ACCESSIBILITY-AUDIT-BEGIN")
46        issues.forEach { print($0) }
47        print("ACCESSIBILITY-AUDIT-END \(issues.count) issues")
48    }
49}