SPB Git

Repository Public License

SmokeUITests.swift 10.4 KB 226 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Arcade9// File             : UITests/SmokeUITests.swift10// Description      : UI smoke tests — launch, lobby tabs, and for each game:11//                    start, pause, resume, restart, quit, finish a session and12//                    find the progress saved after relaunch.13// Module           : UITests14// Repository       : https://git.spboucher.ai/orix-arcade15// Created          : 2026-11-2116// Last Modified    : 2026-11-2117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : Proprietary, all rights reserved (see license file)83// License File     : LICENSE84// Maintainer       : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import XCTest9293@MainActor94final class SmokeUITests: XCTestCase {95    private let base = ["-ORIXSkipIntro", "YES", "-ORIXMute", "YES"]9697    override func setUp() async throws {98        continueAfterFailure = false99    }100101    @discardableResult102    private func launch(save: String, reset: Bool, _ extra: [String] = []) -> XCUIApplication {103        let app = XCUIApplication()104        app.launchArguments = base + ["-ORIXSaveName", save] + (reset ? ["-ORIXReset", "YES"] : []) + extra105        app.launch()106        return app107    }108109    private func tap(_ element: XCUIElement, timeout: TimeInterval = 10, file: StaticString = #filePath, line: UInt = #line) {110        XCTAssertTrue(element.waitForExistence(timeout: timeout), "missing \(element)", file: file, line: line)111        element.tap()112    }113114    /// Saves a real simulator capture for the documentation (best effort; ignored when the folder is not writable).115    private func capture(_ name: String) {116        let folder = URL(fileURLWithPath: "/tmp/orix-arcade-shots")117        try? FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)118        try? XCUIScreen.main.screenshot().pngRepresentation.write(to: folder.appendingPathComponent("\(name).png"))119    }120121    private func unlockedAward(_ app: XCUIApplication, _ title: String) -> XCUIElement {122        app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@ AND label CONTAINS 'Unlocked'", title)).firstMatch123    }124125    /// Pause → resume → pause → restart → pause → quit, from a running game screen.126    private func exercisePauseMenu(_ app: XCUIApplication, name: String) {127        tap(app.buttons["pauseButton"])128        XCTAssertTrue(app.buttons["resumeButton"].waitForExistence(timeout: 5))129        capture("pause-\(name)")130        tap(app.buttons["resumeButton"])131        tap(app.buttons["pauseButton"])132        tap(app.buttons["restartButton"])133        tap(app.buttons["pauseButton"])134        tap(app.buttons["quitButton"])135        XCTAssertTrue(app.buttons["card-dominoCity"].waitForExistence(timeout: 10), "quit returns to the lobby")136    }137138    func testLobbyShowsThreeGamesAndTabs() {139        let app = launch(save: "ui-lobby", reset: true)140        XCTAssertTrue(app.buttons["card-dominoCity"].waitForExistence(timeout: 15))141        XCTAssertTrue(app.buttons["card-digToCore"].exists)142        XCTAssertTrue(app.buttons["card-trafficMayhem"].exists)143        tap(app.buttons["tab-awards"])144        XCTAssertTrue(app.staticTexts["Awards"].waitForExistence(timeout: 5))145        XCTAssertFalse(unlockedAward(app, "Insert Coin").exists, "nothing is unlocked on a fresh save")146        tap(app.buttons["tab-settings"])147        XCTAssertTrue(app.staticTexts["Settings"].waitForExistence(timeout: 5))148        tap(app.buttons["tab-arcade"])149        XCTAssertTrue(app.buttons["card-dominoCity"].waitForExistence(timeout: 5))150    }151152    func testFirstLaunchShowsSplashThenWelcome() {153        let app = XCUIApplication()154        app.launchArguments = ["-ORIXSaveName", "ui-first", "-ORIXReset", "YES", "-ORIXMute", "YES"]155        app.launch()156        tap(app.buttons["welcomeDismiss"], timeout: 15)157        XCTAssertTrue(app.buttons["card-dominoCity"].exists)158    }159160    func testDominoCityPauseFlowAndSavedProgress() {161        var app = launch(save: "ui-domino", reset: true)162        tap(app.buttons["card-dominoCity"], timeout: 15)163        XCTAssertFalse(app.buttons["domino-level-2"].waitForExistence(timeout: 5) && app.buttons["domino-level-2"].isEnabled, "level 2 starts locked")164        tap(app.buttons["domino-level-1"])165        exercisePauseMenu(app, name: "domino-city")166167        // The built-in bot plays the reference solution of level 1; the result must be saved.168        app = launch(save: "ui-domino", reset: false, ["-ORIXGame", "dominoCity", "-ORIXLevel", "1", "-ORIXAutoplay", "YES"])169        sleep(25)170        app = launch(save: "ui-domino", reset: false)171        tap(app.buttons["card-dominoCity"], timeout: 15)172        let second = app.buttons["domino-level-2"]173        XCTAssertTrue(second.waitForExistence(timeout: 10))174        XCTAssertTrue(second.isEnabled, "clearing level 1 unlocks level 2 and survives a relaunch")175        tap(app.buttons["domino-back"])176        XCTAssertTrue(app.buttons["card-dominoCity"].waitForExistence(timeout: 10))177    }178179    func testDigToCorePauseFlowFinishAndSavedProgress() {180        var app = launch(save: "ui-dig", reset: true)181        tap(app.buttons["card-digToCore"], timeout: 15)182        tap(app.buttons["dig-dive"])183        exercisePauseMenu(app, name: "dig-to-core")184185        // Bot dives for a while, then we surface (two taps: ask, confirm) and bank the haul.186        app = launch(save: "ui-dig", reset: false, ["-ORIXGame", "digToCore", "-ORIXDive", "YES", "-ORIXAutoplay", "YES", "-ORIXSeed", "7"])187        sleep(12)188        tap(app.buttons["dig-surface"])189        tap(app.buttons["dig-surface"])190        XCTAssertTrue(app.staticTexts["resultsTitle"].waitForExistence(timeout: 20), "the run summary appears")191        tap(app.buttons["resultsExit"])192        XCTAssertTrue(app.buttons["card-digToCore"].waitForExistence(timeout: 10))193194        app = launch(save: "ui-dig", reset: false, ["-ORIXTab", "awards"])195        XCTAssertTrue(unlockedAward(app, "Insert Coin").waitForExistence(timeout: 10), "the finished dive is saved after relaunch")196    }197198    func testTrafficMayhemPauseFlowFinishAndSavedProgress() {199        var app = launch(save: "ui-traffic", reset: true)200        tap(app.buttons["card-trafficMayhem"], timeout: 15)201        tap(app.buttons["traffic-start"])202        exercisePauseMenu(app, name: "traffic-mayhem")203204        // A full 60-second Rush played by the bot must end on the results card and save a score.205        app = launch(save: "ui-traffic", reset: false, ["-ORIXGame", "trafficMayhem", "-ORIXLayout", "0", "-ORIXMode", "rush", "-ORIXAutoplay", "YES", "-ORIXSeed", "3"])206        XCTAssertTrue(app.staticTexts["resultsTitle"].waitForExistence(timeout: 100), "Rush ends with a result")207        tap(app.buttons["resultsPrimary"])208        tap(app.buttons["pauseButton"])209        tap(app.buttons["quitButton"])210211        app = launch(save: "ui-traffic", reset: false, ["-ORIXTab", "awards"])212        XCTAssertTrue(unlockedAward(app, "Insert Coin").waitForExistence(timeout: 10), "the finished run is saved after relaunch")213    }214215    func testInterruptedGameOffersJumpBackIn() {216        var app = launch(save: "ui-resume", reset: true)217        tap(app.buttons["card-trafficMayhem"], timeout: 15)218        XCTAssertTrue(app.buttons["traffic-start"].waitForExistence(timeout: 10))219        sleep(1)220        app.terminate()221        app = launch(save: "ui-resume", reset: false)222        tap(app.buttons["resumeBanner"], timeout: 15)223        XCTAssertTrue(app.buttons["traffic-start"].waitForExistence(timeout: 10))224    }225}226
Files main
Menu

Theme