Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : MacLustr SMS Gateway9// File : ios/MacLustrSMS/UITests/FlowTests.swift10// Description : Parcours réels sur simulateur contre la pile locale11// (Scripts/dev-stack.sh) : vrai serveur, vraie base,12// téléphone SIMULÉ. Aucun SMS réel n'est envoyé ; ces tests13// ne prouvent rien sur le réseau cellulaire.14// Module : ios15// Repository : https://git.spboucher.ai/maclustr-sms16// Project Website : https://sms.spboucher.ai17// Created : 2026-11-3018// Last Modified : 2026-12-0119//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: admin@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : None specified (no license file in this repository)85// Maintainer : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import XCTest9394@MainActor95final class FlowTests: XCTestCase {96 var app: XCUIApplication!97 static let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() // ios/98 static let shots = root.deletingLastPathComponent().appendingPathComponent("docs/captures/ios")99100 override func setUp() async throws {101 continueAfterFailure = false102 let token = try String(contentsOf: Self.root.appendingPathComponent("build/dev-session.txt"), encoding: .utf8)103 app = XCUIApplication()104 app.launchArguments = ["-serverURL", "http://localhost:8781", "-sessionToken", token, "-uiTesting", "YES"]105 app.launch()106 XCTAssertTrue(app.buttons["sendButton"].waitForExistence(timeout: 15), "le composeur doit s'afficher (session injectée)")107 }108 func shot(_ name: String) {109 try? FileManager.default.createDirectory(at: Self.shots, withIntermediateDirectories: true)110 try? XCUIScreen.main.screenshot().pngRepresentation.write(to: Self.shots.appendingPathComponent(name + (ProcessInfo.processInfo.environment["SHOT_SUFFIX"] ?? "") + ".png"))111 }112 func el(_ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }113 func compose(to: String, text: String) {114 let r = app.textFields["recipientField"]; r.tap(); r.typeText(to)115 let e = el("messageEditor"); e.tap(); e.typeText(text)116 }117 func dismissKeyboard() { let b = app.buttons["keyboardDone"]; if b.waitForExistence(timeout: 3) { b.tap() } }118 func reveal(_ e: XCUIElement) { var n = 0; while !e.isHittable && n < 8 { app.swipeUp(); n += 1 }; XCTAssertTrue(e.isHittable, "élément introuvable à l'écran") }119 func waitLabel(_ id: String, contains s: String, timeout: TimeInterval = 20) -> Bool {120 let p = NSPredicate(format: "label CONTAINS[c] %@", s)121 return app.descendants(matching: .any).matching(identifier: id).matching(p).firstMatch.waitForExistence(timeout: timeout)122 }123124 func testComposeConfirmAndTrackUntilDelivered() {125 shot("01-composer-vide")126 compose(to: "4185550123", text: "Bonjour, votre rendez-vous est confirmé demain à 10 h. À bientôt !")127 XCTAssertTrue(waitLabel("recipientValidation", contains: "+14185550123"))128 XCTAssertTrue(waitLabel("segmentSummary", contains: "1 segment"))129 dismissKeyboard()130 XCTAssertTrue(el("preview").exists)131 shot("02-composer-apercu")132 app.buttons["sendButton"].tap()133 XCTAssertTrue(app.buttons["confirmSendButton"].waitForExistence(timeout: 5))134 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'vrai SMS'")).firstMatch.exists)135 shot("03-confirmation")136 app.buttons["confirmSendButton"].tap()137 XCTAssertTrue(app.staticTexts["trackingStatus"].waitForExistence(timeout: 10))138 // le téléphone simulé rapporte accepté → remis au modem → remis au réseau → livré ; la vue suit par le flux temps réel139 XCTAssertTrue(waitLabel("trackingStatus", contains: "Livré"), "le suivi doit atteindre « Livré » sans rechargement manuel")140 XCTAssertTrue(el("timeline").exists)141 shot("04-suivi-livre")142 app.navigationBars.buttons.firstMatch.tap()143 // le composeur est remis à zéro après l'envoi (pas de second envoi possible par inadvertance)144 XCTAssertFalse(app.buttons["sendButton"].isEnabled)145 app.tabBars.buttons["Historique"].tap()146 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'rendez-vous est confirmé'")).firstMatch.waitForExistence(timeout: 10))147 shot("05-historique")148 }149150 func testRecipientNotAllowedThenAllowed() {151 compose(to: "4185550177", text: "Essai hors liste")152 dismissKeyboard()153 app.buttons["sendButton"].tap()154 app.buttons["confirmSendButton"].tap()155 XCTAssertTrue(app.buttons["allowRecipientButton"].waitForExistence(timeout: 10), "le refus recipient_not_allowed doit proposer d'autoriser le numéro")156 shot("06-destinataire-hors-liste")157 app.buttons["allowRecipientButton"].tap()158 XCTAssertTrue(app.buttons["confirmSendButton"].waitForExistence(timeout: 10), "après autorisation, retour à la confirmation (jamais d'envoi sans nouveau geste)")159 app.buttons["confirmSendButton"].tap()160 XCTAssertTrue(waitLabel("trackingStatus", contains: "Livré"))161 }162163 func testUnicodeSwitchIsFlaggedAndCanBeSimplified() {164 compose(to: "4185550123", text: String(repeating: "a", count: 80) + " L’été — bientôt")165 XCTAssertTrue(waitLabel("segmentSummary", contains: "Unicode"))166 XCTAssertTrue(waitLabel("segmentSummary", contains: "2 segments"))167 dismissKeyboard()168 XCTAssertTrue(app.buttons["simplifyButton"].waitForExistence(timeout: 5))169 shot("07-bascule-unicode")170 app.buttons["simplifyButton"].tap()171 XCTAssertTrue(waitLabel("segmentSummary", contains: "GSM"))172 XCTAssertTrue(waitLabel("segmentSummary", contains: "1 segment"))173 }174175 func testTemplateGalleryTypedVariablesBlockUntilFilled() {176 app.buttons["templatesButton"].tap()177 let card = el("template-Rendez-vous-rdv.confirmation")178 XCTAssertTrue(card.waitForExistence(timeout: 5), "la galerie doit proposer les modèles de départ par catégorie")179 XCTAssertTrue(el("category-Immobilier").exists && el("category-Facturation").exists)180 shot("08-galerie-modeles")181 el("category-Immobilier").tap()182 XCTAssertTrue(el("template-Immobilier-immo.visite-confirmation").waitForExistence(timeout: 5))183 XCTAssertFalse(card.exists, "le filtre de catégorie masque les autres modèles")184 shot("08b-galerie-immobilier")185 el("category-Tous").tap()186 // favori : le modèle remonte dans la section Favoris187 el("fav-rdv.confirmation").firstMatch.tap()188 XCTAssertTrue(el("template-fav-rdv.confirmation").waitForExistence(timeout: 5))189 el("template-fav-rdv.confirmation").tap()190 let r = app.textFields["recipientField"]; XCTAssertTrue(r.waitForExistence(timeout: 5)); r.tap(); r.typeText("4185550123")191 dismissKeyboard()192 XCTAssertFalse(app.buttons["sendButton"].isEnabled, "un modèle ne part jamais avec une variable vide")193 for (v, value) in [("prénom", "Marie"), ("date", "jeudi 3 decembre"), ("heure", "10 h 30"), ("marque", "Lou-Ka")] { let f = app.textFields["variable-\(v)"]; reveal(f); f.tap(); f.typeText(value); dismissKeyboard() }194 XCTAssertTrue(app.buttons["sendButton"].isEnabled)195 XCTAssertTrue(waitLabel("preview", contains: "Bonjour Marie, votre rendez-vous est confirmé le jeudi 3 decembre à 10 h 30. Au plaisir de vous voir! Lou-Ka"))196 XCTAssertTrue(waitLabel("segmentSummary", contains: "1 segment"))197 XCTAssertTrue(waitLabel("segmentSummary", contains: "GSM"), "le modèle rempli tient en un segment GSM")198 shot("09-variables-remplies")199 // le sélecteur d'heure remplit la variable au format du Québec200 let pick = el("picker-heure"); reveal(pick); pick.tap()201 XCTAssertTrue(app.pickerWheels.firstMatch.waitForExistence(timeout: 5))202 app.pickerWheels.element(boundBy: 0).adjust(toPickerWheelValue: "14")203 app.pickerWheels.element(boundBy: 1).adjust(toPickerWheelValue: "15")204 XCTAssertTrue(waitLabel("preview", contains: "14 h 15"), "l'heure choisie au sélecteur s'écrit « 14 h 15 »")205 shot("09b-selecteur-heure")206 }207208 func testSubmittedWithoutDeliveryReportIsAClearSuccess() {209 // Ce destinataire simule un opérateur qui ne renvoie jamais d'accusé (cas réel) : le message reste « remis au réseau ».210 compose(to: "4185550155", text: "Votre commande est disponible.")211 dismissKeyboard()212 app.buttons["sendButton"].tap()213 app.buttons["confirmSendButton"].tap()214 XCTAssertTrue(waitLabel("trackingHeadline", contains: "Envoyé — remis au réseau", timeout: 15), "sans accusé, « remis au réseau » doit s'afficher comme un succès net")215 XCTAssertTrue(waitLabel("trackingStatus", contains: "Remis au réseau"))216 XCTAssertFalse(el("trackingSpinner").exists, "aucun indicateur d'attente une fois le SMS parti")217 shot("12-suivi-remis-au-reseau")218 XCTAssertTrue(waitLabel("receiptLine", contains: "Accusé de livraison"))219 XCTAssertFalse(app.staticTexts["Livré"].exists, "jamais « Livré » sans rapport de l'opérateur")220 shot("12-suivi-remis-au-reseau")221 XCTAssertTrue(waitLabel("receiptLine", contains: "non reçu", timeout: 45), "après 30 s sans accusé, l'étape l'indique au lieu d'attendre indéfiniment")222 shot("13-suivi-sans-accuse")223 app.navigationBars.buttons.firstMatch.tap()224 app.tabBars.buttons["Réglages"].tap()225 XCTAssertTrue(waitLabel("liveStatus", contains: "connecté"), "le flux temps réel doit rester connecté sur un service calme (plus de 30 s)")226 shot("14-reglages")227 }228229 func testKillSwitchBlocksSendingThenRelease() {230 app.tabBars.buttons["Passerelle"].tap()231 XCTAssertTrue(waitLabel("deviceState", contains: "Disponible"))232 shot("10-passerelle")233 let kill = app.buttons["killSwitchButton"]234 reveal(kill)235 kill.tap()236 app.buttons["Tout arrêter"].firstMatch.tap()237 app.swipeDown(); app.swipeDown()238 XCTAssertTrue(el("killBanner").waitForExistence(timeout: 10))239 shot("11-arret-urgence")240 app.tabBars.buttons["Composer"].tap()241 compose(to: "4185550123", text: "Ne doit pas partir")242 dismissKeyboard()243 XCTAssertTrue(el("sendBlocker").waitForExistence(timeout: 5))244 XCTAssertFalse(app.buttons["sendButton"].isEnabled, "aucun envoi possible pendant l'arrêt d'urgence")245 app.tabBars.buttons["Passerelle"].tap()246 reveal(kill)247 kill.tap()248 app.buttons["Lever l'arrêt"].firstMatch.tap()249 app.tabBars.buttons["Composer"].tap()250 XCTAssertTrue(app.buttons["sendButton"].waitForExistence(timeout: 5))251 let enabled = NSPredicate(format: "isEnabled == true")252 expectation(for: enabled, evaluatedWith: app.buttons["sendButton"])253 waitForExpectations(timeout: 10)254 }255}256