SPB Git

Repository Public License

ORIXAudioUITests.swift 11.9 KB 207 lines swift

1//2//  ORIX Audio3//  File: UITests/ORIXAudioUITests.swift4//  Description: End-to-end UI tests: first launch, recording flow, library, workstation panels, editor, actions, settings, appearance.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//9import XCTest1011final class ORIXAudioUITests: XCTestCase {12    static let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent()13    static func fixture(_ name: String) -> String { root.appendingPathComponent("Tests/Fixtures/\(name)").path }1415    override func setUp() { continueAfterFailure = false }1617    /// Each test starts with an empty in-memory library. `input` feeds the capture pipeline from a file (DEBUG builds only).18    func launch(_ extra: [String] = [], skipWelcome: Bool = true) -> XCUIApplication {19        let app = XCUIApplication()20        app.launchArguments = ["-ORIXUITesting"] + (skipWelcome ? ["-ORIXSkipWelcome"] : []) + extra + ["-AppleLanguages", "(en)", "-AppleLocale", "en_CA"]21        app.launch()22        return app23    }2425    /// Any element whose accessibility label contains the text (metric tiles combine label, value and unit into one element).26    func element(_ app: XCUIApplication, containing text: String) -> XCUIElement {27        app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@", text)).firstMatch28    }2930    func tab(_ app: XCUIApplication, _ name: String) {31        let button = app.tabBars.buttons[name].firstMatch32        if button.waitForExistence(timeout: 5) { button.tap() } else { app.buttons[name].firstMatch.tap() }33    }3435    func testFirstLaunchShowsWelcomeThenRecorder() {36        let app = launch(skipWelcome: false)37        XCTAssertTrue(app.staticTexts["Hear Everything. Understand More."].waitForExistence(timeout: 10))38        XCTAssertTrue(app.staticTexts["Record responsibly"].exists)39        app.buttons["welcomeContinue"].tap()40        XCTAssertTrue(app.buttons["recordButton"].waitForExistence(timeout: 5))41        XCTAssertTrue(app.staticTexts["Ready"].exists)42    }4344    func testRecordPauseMarkStopOpensTheRecording() {45        let app = launch(["-ORIXInput", Self.fixture("speech-en.m4a")], skipWelcome: false)46        app.buttons["welcomeContinue"].tap()47        app.buttons["recordButton"].tap()48        // First recording: the consent reminder must appear.49        let consent = app.alerts["Before you record"]50        XCTAssertTrue(consent.waitForExistence(timeout: 5))51        consent.buttons["I understand"].tap()52        XCTAssertTrue(app.staticTexts["Recording"].waitForExistence(timeout: 8))53        XCTAssertTrue(app.staticTexts["Continues when the screen is locked"].exists)54        sleep(2)55        app.buttons["markerButton"].tap()56        app.buttons["pauseButton"].tap()57        XCTAssertTrue(app.staticTexts["Paused"].waitForExistence(timeout: 3))58        let frozen = app.staticTexts["recordingTimer"].label59        sleep(1)60        XCTAssertEqual(app.staticTexts["recordingTimer"].label, frozen, "the timer must not advance while paused")61        app.buttons["pauseButton"].tap()62        XCTAssertTrue(app.staticTexts["Recording"].waitForExistence(timeout: 3))63        sleep(1)64        app.buttons["recordButton"].tap()65        // After saving, the app opens the new recording in the workstation.66        XCTAssertTrue(app.buttons["playButton"].waitForExistence(timeout: 20))67        XCTAssertTrue(app.buttons["panel-analysis"].exists)68        app.buttons["panel-overview"].tap()69        XCTAssertTrue(element(app, containing: "AAC-LC").waitForExistence(timeout: 5))      // the Voice preset really produced AAC70        XCTAssertTrue(element(app, containing: "Lossy").exists)71        XCTAssertTrue(app.textFields["Label"].firstMatch.waitForExistence(timeout: 3))   // the marker was kept72        app.buttons["playButton"].tap()73        sleep(1)74        app.buttons["playButton"].tap()75    }7677    func testLibrarySearchFavouriteAndTrash() {78        let app = launch(["-ORIXImport", "\(Self.fixture("speech-en.m4a")),\(Self.fixture("tone.mp3")),\(Self.fixture("clip.mp4"))", "-ORIXSection", "library"])79        XCTAssertTrue(app.staticTexts["speech-en"].waitForExistence(timeout: 20))80        XCTAssertTrue(app.staticTexts["tone"].exists && app.staticTexts["clip"].exists)                 // audio, MP3 and a video's audio track81        let search = app.searchFields.firstMatch82        search.tap(); search.typeText("tone")83        XCTAssertTrue(app.staticTexts["tone"].waitForExistence(timeout: 5))84        XCTAssertFalse(app.staticTexts["speech-en"].exists)85        search.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 4))86        let row = app.staticTexts["clip"]87        XCTAssertTrue(row.waitForExistence(timeout: 5))88        row.press(forDuration: 1.0)89        XCTAssertTrue(app.buttons["Delete"].firstMatch.waitForExistence(timeout: 5))90        app.buttons["Delete"].firstMatch.tap()91        XCTAssertFalse(app.staticTexts["clip"].waitForExistence(timeout: 2))92        app.buttons["Recently Deleted"].firstMatch.tap()93        XCTAssertTrue(app.staticTexts["clip"].waitForExistence(timeout: 5))                              // recoverable from the trash94    }9596    func testWorkstationPanelsAndAnalysis() {97        let app = launch(["-ORIXImport", Self.fixture("speech-en.m4a"), "-ORIXOpen", "speech"])98        XCTAssertTrue(app.buttons["playButton"].waitForExistence(timeout: 20))99        // Left to right (a right swipe on the chips would trigger the navigation back gesture).100        app.buttons["panel-spectrum"].tap()101        XCTAssertTrue(app.scrollViews["panelContent-spectrum"].waitForExistence(timeout: 5))102        app.buttons["panel-spectrogram"].tap()103        XCTAssertTrue(app.scrollViews["panelContent-spectrogram"].waitForExistence(timeout: 5))104        app.buttons["panel-spectrogram"].swipeLeft()105        app.buttons["panel-analysis"].tap()106        XCTAssertTrue(element(app, containing: "Sample peak").waitForExistence(timeout: 30))              // analysis ran automatically107        XCTAssertTrue(element(app, containing: "No issues found").exists)108        app.buttons["panel-transcript"].tap()109        XCTAssertTrue(app.buttons["transcribeButton"].waitForExistence(timeout: 5))110        app.buttons["panel-notes"].tap()111        XCTAssertTrue(app.staticTexts["Transcript needed"].waitForExistence(timeout: 5))                 // notes are never offered without a transcript112        app.buttons["exportMenu"].tap()113        XCTAssertTrue(app.buttons["WAV · PCM 24-bit"].waitForExistence(timeout: 5))114        XCTAssertTrue(app.buttons["M4A · Apple Lossless"].exists)115        XCTAssertFalse(app.buttons["MP3"].exists)116    }117118    func testEditorDeleteSelectionUndoAndSaveAsNew() {119        let app = launch(["-ORIXImport", Self.fixture("speech-en.m4a"), "-ORIXOpen", "speech"])120        XCTAssertTrue(app.buttons["editButton"].waitForExistence(timeout: 20))121        app.buttons["editButton"].tap()122        let waveform = app.otherElements["Waveform"].firstMatch123        XCTAssertTrue(waveform.waitForExistence(timeout: 10))124        let save = app.buttons["saveEditButton"]125        XCTAssertFalse(save.isEnabled)                                                                   // nothing to save yet126        sleep(2)127        let start = waveform.coordinate(withNormalizedOffset: CGVector(dx: 0.3, dy: 0.5)), end = waveform.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.5))128        start.press(forDuration: 0.1, thenDragTo: end)129        let delete = app.buttons["Delete selection"]130        XCTAssertTrue(delete.waitForExistence(timeout: 5))131        XCTAssertTrue(delete.isEnabled)132        delete.tap()133        XCTAssertTrue(app.buttons["Undo"].waitForExistence(timeout: 5))134        sleep(2)135        XCTAssertTrue(app.buttons["Undo"].isEnabled)136        XCTAssertTrue(save.isEnabled)137        save.tap()138        app.buttons["WAV · PCM 16-bit"].firstMatch.tap()139        // The editor closes and the new recording opens.140        XCTAssertTrue(app.buttons["playButton"].waitForExistence(timeout: 30))141        app.buttons["panel-overview"].tap()142        XCTAssertTrue(element(app, containing: "Linear PCM").waitForExistence(timeout: 10))143        XCTAssertTrue(element(app, containing: "Lossless").exists)144    }145146    func testActionsRunOnARecording() {147        let app = launch(["-ORIXImport", Self.fixture("tone.mp3"), "-ORIXSection", "actions"])148        XCTAssertTrue(app.staticTexts["Archive as lossless"].waitForExistence(timeout: 20))149        app.buttons["Run Archive as lossless"].tap()150        let cell = app.staticTexts["tone"]151        XCTAssertTrue(cell.waitForExistence(timeout: 10))152        cell.tap()153        app.buttons["Run on 1"].tap()154        XCTAssertTrue(app.staticTexts["Finished"].waitForExistence(timeout: 60))155        app.staticTexts["Finished"].tap()156        XCTAssertTrue(app.staticTexts["1 new recordings added to the library"].waitForExistence(timeout: 5))157        XCTAssertTrue(app.buttons["Share 1 exported files"].exists)158    }159160    func testSettingsAndPrivacyScreens() {161        let app = launch(["-ORIXSection", "settings"])162        XCTAssertTrue(app.staticTexts["Default quality"].waitForExistence(timeout: 10))163        XCTAssertTrue(app.staticTexts["Apple Foundation Models"].exists || app.staticTexts["Summaries and questions"].exists)164        app.swipeUp()165        app.buttons["Privacy"].firstMatch.tap()166        XCTAssertTrue(app.staticTexts["No account, no sign-in."].waitForExistence(timeout: 5))167        XCTAssertTrue(app.staticTexts["No hidden or covert recording."].exists)168    }169170    /// Apple's automated accessibility audit on the main screens. Issues are printed with a recognisable prefix and fail the test.171    @MainActor func testAccessibilityAudit() throws {172        final class Box: @unchecked Sendable { var lines: [String] = [] }173        let found = Box()174        let screens: [(String, [String], String)] = [175            ("recorder", [], "recordButton"), ("library", ["-ORIXSection", "library"], "importMenu"),176            ("workstation", ["-ORIXOpen", "speech"], "playButton"), ("analysis", ["-ORIXOpen", "speech", "-ORIXPanel", "analysis"], "playButton"),177            ("actions", ["-ORIXSection", "actions"], ""), ("settings", ["-ORIXSection", "settings"], ""),178        ]179        for (screen, arguments, anchor) in screens {180            let app = launch(["-ORIXImport", Self.fixture("speech-en.m4a")] + arguments)181            if anchor.isEmpty { sleep(4) } else { XCTAssertTrue(app.buttons[anchor].waitForExistence(timeout: 20), screen) }182            sleep(2)183            try app.performAccessibilityAudit(for: [.contrast, .elementDetection, .hitRegion, .sufficientElementDescription, .dynamicType, .textClipped, .trait]) { issue in184                let line = "A11Y[\(screen)] \(issue.compactDescription) — \(issue.element?.label ?? issue.element?.identifier ?? "?")"185                found.lines.append(line); print(line)186                return true187            }188            app.terminate()189        }190        // The full list goes into the accessibility report. Structural problems (missing or unreadable labels, undersized191        // controls, wrong traits) fail the test; contrast and Dynamic Type findings are reviewed by hand because the audit192        // also flags text sitting under the translucent tab bar and deliberate single-line numeric readouts.193        let report = found.lines.sorted().joined(separator: "\n") + "\n"194        try? report.write(to: Self.root.appendingPathComponent("docs/reports/accessibility-audit.txt"), atomically: true, encoding: .utf8)195        let structural = found.lines.filter { $0.contains("Hit area") || $0.contains("not human-readable") || $0.contains("no description") || $0.contains("Element") }196        XCTAssertTrue(structural.isEmpty, structural.joined(separator: "\n"))197    }198199    func testFrenchCanadianLocalization() {200        let app = XCUIApplication()201        app.launchArguments = ["-ORIXUITesting", "-ORIXSkipWelcome", "-AppleLanguages", "(fr-CA)", "-AppleLocale", "fr_CA"]202        app.launch()203        XCTAssertTrue(app.staticTexts["Prêt"].waitForExistence(timeout: 10))204        XCTAssertTrue(app.buttons["Démarrer l’enregistrement"].exists)205    }206}207
Files main
Menu

Theme