SPB Git

Repository Public License

ORIXAlarmUITests.swift 5.3 KB 100 lines swift

1// ORIX Alarm2// File: UITests/ORIXAlarmUITests.swift3// Description: End-to-end interface tests against the in-memory alarm service: onboarding, alarm creation, permission denial, tabs, a full simulated wake (mission, confirmation, statistics) and the emergency exit.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import XCTest89@MainActor10final class ORIXAlarmUITests: XCTestCase {11    override func setUp() async throws { continueAfterFailure = false }1213    private func launch(_ extra: [String] = [], onboarding: Bool = false) -> XCUIApplication {14        let app = XCUIApplication()15        app.launchArguments = ["-ORIXUITest", "YES", "-ORIXReset", "YES"] + (onboarding ? [] : ["-ORIXSkipOnboarding", "YES"]) + extra16        app.launch()17        return app18    }19    private func element(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: id).firstMatch }2021    func testOnboardingThenCreateAlarmShowsVerifiedSchedule() {22        let app = launch(onboarding: true)23        let start = app.buttons["onboarding.continue"]24        XCTAssertTrue(start.waitForExistence(timeout: 60))25        start.tap()26        XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: 20))27        app.tabBars.buttons["Alarms"].tap()28        let add = element(app, "alarms.addFirst").exists ? element(app, "alarms.addFirst") : element(app, "alarms.add")29        XCTAssertTrue(add.waitForExistence(timeout: 10))30        add.tap()31        let save = app.buttons["editor.save"]32        XCTAssertTrue(save.waitForExistence(timeout: 15))33        save.tap()34        XCTAssertTrue(element(app, "alarms.row.0").waitForExistence(timeout: 15), "the saved alarm is listed")35        XCTAssertTrue(app.staticTexts["Scheduled"].waitForExistence(timeout: 5), "the system status is shown as verified")36    }3738    func testDeniedPermissionNeverLooksScheduled() {39        let app = launch(["-ORIXDenyAlarms", "YES"])40        XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: 60))41        app.tabBars.buttons["Alarms"].tap()42        XCTAssertTrue(element(app, "authorization.banner").waitForExistence(timeout: 10))43        let add = element(app, "alarms.addFirst").exists ? element(app, "alarms.addFirst") : element(app, "alarms.add")44        add.tap()45        let save = app.buttons["editor.save"]46        XCTAssertTrue(save.waitForExistence(timeout: 15))47        save.tap()48        XCTAssertTrue(element(app, "editor.error").waitForExistence(timeout: 10), "the editor says the alarm is saved but not scheduled")49        XCTAssertFalse(app.staticTexts["Scheduled"].exists)50    }5152    func testEveryTabLoadsWithDemoData() {53        let app = launch(["-ORIXDemo", "YES"])54        XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: 60))55        for (tab, marker) in [("Alarms", "Alarms"), ("Studio", "Alarm Studio"), ("Sleep", "Sleep"), ("Insights", "Insights"), ("Today", "Today")] {56            app.tabBars.buttons[tab].tap()57            XCTAssertTrue(app.staticTexts[marker].waitForExistence(timeout: 15), "\(tab) did not load")58        }59        XCTAssertTrue(element(app, "dashboard.nextAlarm").waitForExistence(timeout: 10))60    }6162    /// The fake system rings an alarm and stops it; the app must present the mission, then the confirmation, and count one wake-up.63    func testSimulatedWakeRunsMissionConfirmationAndStatistics() throws {64        let app = launch(["-ORIXSimulateWake", "YES"])65        let question = app.staticTexts["math.question"]66        XCTAssertTrue(question.waitForExistence(timeout: 90), "the wake mission was not presented after the alarm was stopped")67        let prompt = try XCTUnwrap(question.value as? String)68        let answer = try XCTUnwrap(Solver.solve(prompt), "cannot solve: \(prompt)")69        if answer < 0 { app.buttons["math.key.negative"].tap() }70        for digit in String(abs(answer)) { app.buttons["math.key.\(digit)"].tap() }71        app.buttons["math.submit"].tap()72        let confirm = app.buttons["mission.confirmWake"]73        XCTAssertTrue(confirm.waitForExistence(timeout: 15), "the wake confirmation was not requested")74        confirm.tap()75        XCTAssertTrue(app.staticTexts["mission.summaryTitle"].waitForExistence(timeout: 10))76        app.buttons["mission.done"].tap()77        app.tabBars.buttons["Insights"].tap()78        XCTAssertTrue(app.staticTexts["Wake confirmations"].waitForExistence(timeout: 15))79        // Relaunch without reset: the finished occurrence must not be proposed again.80        app.terminate()81        app.launchArguments = ["-ORIXUITest", "YES", "-ORIXSkipOnboarding", "YES"]82        app.launch()83        XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: 60))84        XCTAssertFalse(app.staticTexts["math.question"].waitForExistence(timeout: 5))85    }8687    func testEmergencyExitIsAlwaysAvailable() {88        let app = launch(["-ORIXSimulateWake", "YES"])89        XCTAssertTrue(app.staticTexts["math.question"].waitForExistence(timeout: 90))90        app.buttons["mission.options"].tap()91        app.buttons["Emergency exit"].tap()92        let confirm = app.buttons["Use emergency exit"]93        XCTAssertTrue(confirm.waitForExistence(timeout: 5))94        confirm.tap()95        let title = app.staticTexts["mission.summaryTitle"]96        XCTAssertTrue(title.waitForExistence(timeout: 10))97        XCTAssertEqual(title.label, "Mission skipped")98    }99}100
Files main
Menu

Theme