Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Calc9// File : UITests/ORIXCalcUITests.swift10// Description : End-to-end UI tests on the real app: arithmetic on the11// keypad, environment switching, history persistence,12// accessibility audit.13// Module : UITests14// Repository : https://git.spboucher.ai/orix-calc15// Created : 2026-11-2016// Last Modified : 2026-11-2017//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 XCTest9293final class ORIXCalcUITests: XCTestCase {94 override func setUp() { continueAfterFailure = false }9596 private func launch(mode: String = "standard", _ extra: [String] = []) -> XCUIApplication {97 let app = XCUIApplication()98 app.launchArguments = ["-ORIXInMemory", "1", "-ORIXMode", mode] + extra99 app.launch()100 return app101 }102 private func tap(_ app: XCUIApplication, _ keys: String...) {103 for k in keys { app.buttons["key." + k].firstMatch.tap() }104 }105106 @MainActor func testStandardArithmetic() {107 let app = launch()108 tap(app, "2", "5", "*", "4", "=")109 let result = app.staticTexts["calc.result"]110 XCTAssertTrue(result.waitForExistence(timeout: 5))111 XCTAssertEqual(result.label, "Result: 100")112 // continue from the answer, then a percentage113 tap(app, "+", "1", "0", "%", "=")114 XCTAssertTrue(app.staticTexts["Result: 110"].waitForExistence(timeout: 5))115 }116117 @MainActor func testDivisionByZeroShowsAnError() {118 let app = launch()119 tap(app, "1", "/", "0", "=")120 XCTAssertTrue(app.descendants(matching: .any)["calc.error"].waitForExistence(timeout: 5))121 }122123 @MainActor func testEveryEnvironmentOpens() {124 let app = launch()125 for mode in ["scientific", "financial", "graph", "math", "statistics", "convert", "workspace", "standard"] {126 let chip = app.buttons["mode." + mode].firstMatch127 XCTAssertTrue(chip.waitForExistence(timeout: 5), "missing switcher for \(mode)")128 chip.tap()129 XCTAssertTrue(chip.isSelected, "\(mode) did not become active")130 XCTAssertFalse(app.staticTexts["is not included in this build"].exists)131 }132 }133134 @MainActor func testHistoryIsSharedAndReusable() {135 let app = launch()136 tap(app, "6", "*", "7", "=")137 XCTAssertTrue(app.staticTexts["Result: 42"].waitForExistence(timeout: 5))138 app.buttons["shell.history"].firstMatch.tap()139 XCTAssertTrue(app.staticTexts["42"].firstMatch.waitForExistence(timeout: 5))140 }141142 /// History and variables must survive a relaunch (real on-disk store, cleaned up afterwards).143 @MainActor func testHistoryPersistsAcrossRelaunch() {144 let app = XCUIApplication()145 app.launchArguments = ["-ORIXMode", "standard"]146 app.launch()147 // The clear key is "AC" on an empty display and "C" otherwise.148 let clear = app.buttons["key.ac"].firstMatch.waitForExistence(timeout: 5) ? "ac" : "c"149 tap(app, clear, "9", "*", "9", "=")150 XCTAssertTrue(app.staticTexts["Result: 81"].waitForExistence(timeout: 5))151 app.terminate()152 app.launch()153 app.buttons["shell.history"].firstMatch.tap()154 XCTAssertTrue(app.staticTexts["81"].firstMatch.waitForExistence(timeout: 5), "the result was not in the history after relaunch")155 }156157 /// Every environment renders its worked example without an error banner taking over the screen.158 @MainActor func testDemoOfEveryEnvironmentLoads() {159 for mode in ["financial", "graph", "math", "statistics", "convert", "workspace"] {160 let app = launch(mode: mode, ["-ORIXDemo", "1"])161 XCTAssertTrue(app.buttons["mode." + mode].firstMatch.waitForExistence(timeout: 8))162 XCTAssertTrue(app.buttons["mode." + mode].firstMatch.isSelected)163 XCTAssertEqual(app.state, .runningForeground, "\(mode) crashed in demo mode")164 let shot = XCTAttachment(screenshot: app.screenshot())165 shot.name = "demo-" + mode166 shot.lifetime = .keepAlways167 add(shot)168 app.terminate()169 }170 }171172 @MainActor func testScientificExactAngle() {173 let app = launch(mode: "scientific")174 tap(app, "fn:sin", "3", "0", ")", "=")175 XCTAssertTrue(app.staticTexts["Result: 0.5"].waitForExistence(timeout: 5))176 }177178 @MainActor func testAccessibilityAuditOfTheCalculator() throws {179 let app = launch()180 try app.performAccessibilityAudit(for: [.dynamicType, .sufficientElementDescription, .hitRegion]) { issue in181 // Decorative separators inside the display are not interactive elements.182 guard let element = issue.element else { return true }183 // Keypad keys and the display are sized by the layout, like every hardware-style calculator: they do not follow184 // Dynamic Type. Keys expose the system Large Content Viewer instead, and the display scales to fit its value.185 if issue.auditType == .dynamicType {186 let id = element.identifier187 return id.hasPrefix("key.") || id.hasPrefix("calc.") || id.hasPrefix("mode.") || id.hasPrefix("shell.")188 }189 return false190 }191 }192}193