Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka iOS9// File : ImmoKaUITests/MainFlowUITests.swift10// Description : parcours principal — accueil, carte, filtres, fiche,11// favori, annuaire. Nécessite l'API de développement (tunnel12// http://127.0.0.1:18097).13// Module : ImmoKaUITests14// Repository : https://git.spboucher.ai/immo-ka-ios-v315// Project Website : https://www.immo-ka.com16// Created : 2026-11-2517// Last Modified : 2026-11-2818//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author : Simon-Pierre Boucher24// Position : Professor of Finance25// Institution : Université du Québec en Outaouais (UQO)26// Department : Département des sciences administratives27// Organization : SP Boucher28//29// Website : https://spboucher.ai30// Git : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General : info@spboucher.ai37// Professional : contact@spboucher.ai38// Direct : simon@spboucher.ai39// Research : research@spboucher.ai40// Development : dev@spboucher.ai41// Support : support@spboucher.ai42// Security/Admin : admin@spboucher.ai43// Notifications : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification : Public70// Distribution : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License : None specified (no license file in this repository)84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import XCTest9293final class MainFlowUITests: XCTestCase {94 private var app: XCUIApplication!9596 override func setUp() {97 continueAfterFailure = false98 app = XCUIApplication()99 app.launchArguments = ["-IKInMemory", "YES", "-AppleLanguages", "(fr-CA)"]100 }101102 private func snap(_ name: String) {103 let a = XCTAttachment(screenshot: XCUIScreen.main.screenshot())104 a.name = name105 a.lifetime = .keepAlways106 add(a)107 }108109 private func tab(_ name: String) -> XCUIElement {110 let bar = app.tabBars.buttons[name]111 return bar.exists ? bar : app.buttons[name].firstMatch112 }113114 /// Passe à un onglet. Sur un iPad étroit en portrait, la barre d'onglets du système défile et le dernier onglet115 /// peut être hors de vue : l'app est alors relancée sur cet onglet (même état : base en mémoire).116 private func go(_ name: String, launchTab: String) {117 let b = tab(name)118 if b.waitForExistence(timeout: 3), b.isHittable { b.tap(); return }119 app.terminate()120 app.launchArguments = ["-IKInMemory", "YES", "-AppleLanguages", "(fr-CA)", "-IKTab", launchTab]121 app.launch()122 }123124 func testDiscoverThenExplore() {125 app.launch()126 XCTAssertTrue(app.buttons["discover.explore"].waitForExistence(timeout: 20))127 XCTAssertTrue(app.staticTexts["Ouvrez la porte de votre prochaine maison."].waitForExistence(timeout: 20), "l'accroche de l'accueil est affichée")128 XCTAssertTrue(app.staticTexts["discover.count"].waitForExistence(timeout: 20), "le nombre de propriétés en ligne est chargé")129 snap("accueil")130 app.buttons["discover.explore"].tap()131 let counter = app.staticTexts.containing(NSPredicate(format: "label MATCHES '.*[0-9] propriétés?'")).firstMatch132 XCTAssertTrue(counter.waitForExistence(timeout: 25), "le compteur de la carte affiche un total")133 snap("explorer")134 }135136 func testFiltersNarrowTheSearch() {137 app.launchArguments += ["-IKCity", "Québec"]138 app.launch()139 XCTAssertTrue(app.buttons["explore.filters"].waitForExistence(timeout: 20))140 let counter = app.descendants(matching: .any)["explore.counter"]141 XCTAssertTrue(counter.waitForExistence(timeout: 20))142 app.buttons["explore.filters"].tap()143 let chip = app.buttons["Condo"].firstMatch144 XCTAssertTrue(chip.waitForExistence(timeout: 8))145 chip.tap()146 let apply = app.buttons["filters.apply"]147 XCTAssertTrue(apply.waitForExistence(timeout: 5))148 snap("filtres")149 apply.tap()150 XCTAssertTrue(app.buttons["explore.filters"].waitForExistence(timeout: 8))151 XCTAssertTrue(app.buttons.containing(NSPredicate(format: "label CONTAINS '1 actifs'")).firstMatch.waitForExistence(timeout: 8),152 "le bouton des filtres indique un filtre actif")153 }154155 func testListingFavoriteRoundTrip() throws {156 let uid = try XCTUnwrap(ProcessInfo.processInfo.environment["IMMOKA_TEST_UID"], "IMMOKA_TEST_UID manquant (voir Scripts/build.sh uitest)")157 app.launchArguments += ["-IKOpen", "propriete/\(uid)"]158 app.launch()159 let open = app.buttons["listing.open"]160 XCTAssertTrue(open.waitForExistence(timeout: 25), "la fiche affiche le bouton Voir l'inscription")161 snap("fiche")162 let fav = app.buttons["listing.favorite"]163 XCTAssertTrue(fav.waitForExistence(timeout: 5))164 XCTAssertEqual(fav.label, "Ajouter aux favoris")165 fav.tap()166 XCTAssertEqual(fav.label, "Retirer des favoris")167 app.swipeUp()168 app.swipeUp()169 snap("fiche-analyses")170 app.navigationBars.buttons.firstMatch.tap()171 tab("Favoris").tap()172 XCTAssertTrue(app.staticTexts["1 favori"].waitForExistence(timeout: 10))173 snap("favoris")174 }175176 func testDirectoriesAndMarket() {177 app.launchArguments += ["-IKTab", "pros"]178 app.launch()179 XCTAssertTrue(app.staticTexts["pros.summary"].waitForExistence(timeout: 25), "l'annuaire des bannières et agences est chargé")180 XCTAssertTrue(app.staticTexts["RE/MAX"].waitForExistence(timeout: 10))181 snap("courtiers")182 go("Marché", launchTab: "market")183 XCTAssertTrue(app.staticTexts["Prix demandé médian"].waitForExistence(timeout: 25), "les chiffres du marché sont chargés")184 snap("marche")185 let rates = app.buttons["market.rates"]186 // en v3, les taux suivent le portrait du marché : on fait défiler jusqu'à eux187 for _ in 0..<8 where !rates.exists { app.swipeUp() }188 XCTAssertTrue(rates.waitForExistence(timeout: 10))189 rates.tap()190 XCTAssertTrue(app.staticTexts["rates.best"].waitForExistence(timeout: 25), "le meilleur taux du jour est affiché")191 snap("taux")192 }193194 /// Calculateur natif : le versement réagit au prix saisi.195 func testCalculator() {196 app.launchArguments += ["-IKTab", "market", "-IKRoute", "calculator"]197 app.launch()198 let monthly = app.staticTexts["finance.monthly"].firstMatch199 XCTAssertTrue(monthly.waitForExistence(timeout: 20))200 // attendre le taux du jour, puis noter le versement pour 500 000 $201 sleep(3)202 let before = monthly.label203 XCTAssertTrue(before.contains("$"), "un versement est affiché : \(before)")204 let chip = app.buttons["800 k$"].firstMatch205 XCTAssertTrue(chip.waitForExistence(timeout: 5))206 chip.tap()207 sleep(1)208 XCTAssertNotEqual(monthly.label, before, "le versement change avec le prix")209 XCTAssertTrue(app.staticTexts["Droits de mutation"].exists || app.staticTexts.containing(NSPredicate(format: "label BEGINSWITH 'Droits de mutation'")).firstMatch.exists)210 snap("calculateur")211 }212213 /// Ouvre une propriété en touchant une carte de l'accueil : la maison apparaît, sa porte s'ouvre (niveau signature, première214 /// ouverture de la session) et la fiche apparaît.215 func testDoorOpensListingFromCard() {216 app.launch()217 let card = app.buttons.matching(identifier: "listing.card").firstMatch218 XCTAssertTrue(card.waitForExistence(timeout: 25), "une carte de propriété est affichée sur l'accueil")219 sleep(2) // la photo de la carte finit de se charger (vidéo de vérification)220 card.tap()221 XCTAssertTrue(app.buttons["listing.open"].waitForExistence(timeout: 15), "la fiche s'ouvre après la porte")222 snap("porte-fiche")223 }224225 /// Un toucher pendant l'animation l'interrompt : la fiche est là tout de suite, l'app reste utilisable.226 func testDoorInterruptedByTap() {227 app.launch()228 let card = app.buttons.matching(identifier: "listing.card").firstMatch229 XCTAssertTrue(card.waitForExistence(timeout: 25))230 sleep(2)231 let center = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))232 card.tap()233 center.tap() // pendant l'animation : interruption234 XCTAssertTrue(app.buttons["listing.open"].waitForExistence(timeout: 15), "la fiche s'ouvre malgré l'interruption")235 // l'app n'est pas restée bloquée sous le calque : le retour fonctionne236 app.navigationBars.buttons.firstMatch.tap()237 XCTAssertTrue(app.buttons["discover.explore"].waitForExistence(timeout: 10))238 }239240 // MARK: Parcours de la v3241242 /// Fiche v3 : prix de vente attendu et son intervalle, puis coût de possession poste par poste.243 func testListingValuationAndOwnership() throws {244 let uid = try XCTUnwrap(ProcessInfo.processInfo.environment["IMMOKA_TEST_UID"], "IMMOKA_TEST_UID manquant (voir Scripts/build.sh uitest)")245 app.launchArguments += ["-IKOpen", "propriete/\(uid)", "-IKAnchor", "analyses"]246 app.launch()247 XCTAssertTrue(app.buttons["listing.open"].waitForExistence(timeout: 25))248 XCTAssertTrue(app.staticTexts["Prix de vente attendu"].waitForExistence(timeout: 20), "la section du prix de vente attendu est affichée")249 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'ventes sur 10 se concluent entre'")).firstMatch.waitForExistence(timeout: 20),250 "l'intervalle est écrit en clair")251 snap("fiche-prix-attendu")252 app.terminate()253 app.launchArguments = ["-IKInMemory", "YES", "-AppleLanguages", "(fr-CA)", "-IKOpen", "propriete/\(uid)", "-IKAnchor", "ownership"]254 app.launch()255 XCTAssertTrue(app.staticTexts["Coût de possession"].waitForExistence(timeout: 30))256 XCTAssertTrue(app.staticTexts["Versement hypothécaire"].waitForExistence(timeout: 20), "les postes mensuels sont chargés")257 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label IN {'Estimé', 'Observé', 'Hypothèse', 'Inconnu'}")).firstMatch.exists258 || app.otherElements.containing(NSPredicate(format: "label IN {'Estimé', 'Observé', 'Hypothèse', 'Inconnu'}")).firstMatch.exists,259 "chaque poste dit d'où il vient")260 snap("fiche-cout-possession")261 }262263 /// Recherche en phrase libre : le service dit ce qu'il comprend, puis la carte applique ces critères.264 func testNaturalLanguageSearch() {265 app.launchArguments += ["-IKTab", "explore"]266 app.launch()267 let search = app.buttons["explore.search"]268 XCTAssertTrue(search.waitForExistence(timeout: 20))269 search.tap()270 let field = app.searchFields.firstMatch271 XCTAssertTrue(field.waitForExistence(timeout: 8))272 field.tap()273 field.typeText("maison 3 chambres a Gatineau sous 500000")274 let go = app.buttons["search.natural"]275 XCTAssertTrue(go.waitForExistence(timeout: 15), "le service a interprété la phrase")276 snap("recherche-phrase")277 go.tap()278 XCTAssertTrue(app.descendants(matching: .any)["explore.interpreted"].waitForExistence(timeout: 15), "les critères compris sont rappelés sous la barre")279 let counter = app.staticTexts.containing(NSPredicate(format: "label MATCHES '.*[0-9] propriétés?'")).firstMatch280 XCTAssertTrue(counter.waitForExistence(timeout: 25))281 snap("recherche-phrase-carte")282 }283284 /// Marché v3 : prix demandés et ventes réelles séparés ; quartiers ; portrait d'un lieu.285 func testMarketAndNeighborhood() {286 app.launchArguments += ["-IKTab", "market"]287 app.launch()288 XCTAssertTrue(app.staticTexts["Prix demandés"].waitForExistence(timeout: 25))289 XCTAssertTrue(app.staticTexts["Prix demandé médian"].waitForExistence(timeout: 25))290 XCTAssertTrue(app.buttons["market.place"].exists, "le lieu du marché se change")291 snap("marche-v3")292 app.terminate()293 app.launchArguments = ["-IKInMemory", "YES", "-AppleLanguages", "(fr-CA)", "-IKTab", "market", "-IKOpen", "quartier/gatineau/aylmer"]294 app.launch()295 XCTAssertTrue(app.staticTexts["Aylmer"].firstMatch.waitForExistence(timeout: 25), "le portrait du secteur est chargé")296 XCTAssertTrue(app.staticTexts["Prix demandés"].waitForExistence(timeout: 15))297 snap("quartier")298 }299300 /// Recherche de courtiers par nom (aucune coordonnée : elles restent chez la source).301 func testBrokerSearch() {302 app.launchArguments += ["-IKTab", "pros", "-IKRoute", "brokers"]303 app.launch()304 let field = app.searchFields.firstMatch305 XCTAssertTrue(field.waitForExistence(timeout: 20))306 field.tap()307 field.typeText("trem")308 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label BEGINSWITH 'Tremblay'")).firstMatch.waitForExistence(timeout: 20))309 snap("courtiers-recherche")310 }311312 /// Audit d'accessibilité d'Xcode sur les écrans principaux : éléments sans description, zones de toucher trop313 /// petites, texte coupé, contraste. `IMMOKA_AUDIT_STRICT=1` fait échouer le test à la première anomalie ;314 /// sinon les anomalies sont consignées (pièce jointe « audit ») et le test échoue seulement pour les315 /// éléments sans description, qui rendent un écran inutilisable avec VoiceOver.316 @MainActor317 func testAccessibilityAudit() throws {318 let strict = ProcessInfo.processInfo.environment["IMMOKA_AUDIT_STRICT"] == "1"319 let uid = ProcessInfo.processInfo.environment["IMMOKA_TEST_UID"]320 let report = AuditReport()321 func audit(_ screen: String) throws {322 try app.performAccessibilityAudit(for: [.sufficientElementDescription, .hitRegion, .contrast, .textClipped, .trait]) { issue in323 let el = issue.element.map { "\($0.elementType.rawValue) « \($0.label) » \($0.identifier)" } ?? "?"324 report.lines.append("\(screen) | \(issue.auditType.rawValue) | \(issue.compactDescription) | \(el)")325 if strict { return false }326 return issue.auditType != .sufficientElementDescription // ignorée (consignée), sauf description manquante327 }328 }329 defer {330 let a = XCTAttachment(string: report.lines.joined(separator: "\n")); a.name = "audit"; a.lifetime = .keepAlways; add(a)331 }332 app.launch()333 XCTAssertTrue(app.staticTexts["discover.count"].waitForExistence(timeout: 25))334 try audit("accueil")335 tab("Favoris").tap()336 XCTAssertTrue(app.staticTexts["Aucun favori pour l'instant"].waitForExistence(timeout: 10))337 try audit("favoris vides")338 tab("Courtiers").tap()339 XCTAssertTrue(app.staticTexts["pros.summary"].waitForExistence(timeout: 25))340 try audit("courtiers")341 go("Marché", launchTab: "market")342 XCTAssertTrue(app.staticTexts["Prix demandé médian"].waitForExistence(timeout: 25))343 try audit("marché")344 if let uid {345 app.terminate()346 app.launchArguments += ["-IKOpen", "propriete/\(uid)"]347 app.launch()348 XCTAssertTrue(app.buttons["listing.open"].waitForExistence(timeout: 25))349 try audit("fiche")350 }351 }352}353354/// Journal de l'audit d'accessibilité (rempli sur le fil principal par XCUITest).355private final class AuditReport: @unchecked Sendable {356 var lines: [String] = []357}358