SPB Git

Repository Public

KAMapsUITests.swift 11.6 KB 265 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : KA Maps Engine9// File             : sdk/ios/Example/UITests/KAMapsUITests.swift10// Module           : sdk11// Repository       : https://git.spboucher.ai/ka-maps-engine12// Created          : 2026-12-0113// Last Modified    : 2026-12-0114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : None specified (no license file in this repository)80// Maintainer       : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import XCTest8889/// Essais d'interface sur le simulateur, sans fenêtre (`xcodebuild test`).90/// Les vrais gestes sont synthétisés par XCUITest ; les scénarios scriptés tournent dans l'application91/// (voir `Scenarios.swift`) et publient leur état dans l'élément « status ».92@MainActor93final class KAMapsUITests: XCTestCase {94    override func setUp() {95        continueAfterFailure = false96        XCUIDevice.shared.orientation = .portrait97    }9899    private func attach(_ name: String) {100        let shot = XCUIScreen.main.screenshot()101        let a = XCTAttachment(screenshot: shot)102        a.name = name103        a.lifetime = .keepAlways104        add(a)105        // Copie hors du lot .xcresult si un dossier est donné (TEST_RUNNER_KAMAPS_SHOTS=/chemin).106        if let dir = ProcessInfo.processInfo.environment["KAMAPS_SHOTS"] {107            try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)108            try? shot.pngRepresentation.write(to: URL(fileURLWithPath: dir).appendingPathComponent("\(name).png"))109        }110    }111112    /// Lit « z 13.5  0°  cap 0° » dans le bandeau de l'application.113    private func hud(_ app: XCUIApplication) -> (zoom: Double, pitch: Double, bearing: Double) {114        let label = app.descendants(matching: .any)["hud"].label115        let nums = label.replacingOccurrences(of: ",", with: ".").components(separatedBy: CharacterSet(charactersIn: "0123456789.-").inverted).compactMap(Double.init)116        return (nums.count > 0 ? nums[0] : -1, nums.count > 1 ? nums[1] : -1, nums.count > 2 ? nums[2] : -1)117    }118119    private func waitFor(_ what: String, timeout: TimeInterval = 15, _ cond: () -> Bool) {120        let end = Date().addingTimeInterval(timeout)121        while Date() < end {122            if cond() { return }123            usleep(150_000)124        }125        XCTFail("délai dépassé : \(what)")126    }127128    private func launchPlain() -> XCUIApplication {129        let app = XCUIApplication()130        app.launch()131        XCTAssertTrue(app.descendants(matching: .any)["KAMapSummary"].waitForExistence(timeout: 30), "la carte n'expose pas son élément d'accessibilité")132        waitFor("premier chargement") { self.hud(app).zoom > 0 }133        sleep(3)134        return app135    }136137    /// Scénarios scriptés (vraies tuiles de Montréal, Québec, campagne ; 2D↔3D ; grappes ; thèmes ;138    /// couches ; caméra ; outils ; reveal ; rendu à la demande ; mémoire ; géo ; accessibilité ; hors ligne).139    func testScenarioSuite() {140        let app = XCUIApplication()141        let list = ProcessInfo.processInfo.environment["KAMAPS_SCENARIOS"] ?? "montreal,quebec,rural,mode3d,markers,themes,layers,camera,tools,reveal,idle,memwarn,geo,a11y,offline"142        app.launchArguments = ["-scenario", list]143        app.launch()144        let status = app.descendants(matching: .any)["status"]145        XCTAssertTrue(status.waitForExistence(timeout: 30))146        var last = ""147        let end = Date().addingTimeInterval(600)148        while Date() < end {149            let s = status.label150            if s != last {151                last = s152                if s.hasPrefix("SHOT ") { attach(String(s.dropFirst(5))) }153                if s.hasPrefix("DONE") { break }154            }155            usleep(100_000)156        }157        XCTAssertEqual(last, "DONE ok", "scénarios en échec : \(last)")158    }159160    /// Double toucher, toucher à deux doigts, pincement, rotation, glissement, inclinaison : de vrais161    /// événements tactiles traversent les reconnaisseurs de gestes du SDK.162    func testRealGestures() {163        let app = launchPlain()164        let map = app.descendants(matching: .any)["KAMapSummary"]165        let center = map.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45))166167        let z0 = hud(app).zoom168        center.doubleTap()169        waitFor("zoom avant par double toucher") { self.hud(app).zoom > z0 + 0.9 }170        let z1 = hud(app).zoom171        XCTAssertEqual(z1, z0 + 1, accuracy: 0.11)172173        map.twoFingerTap()174        waitFor("zoom arrière par toucher à deux doigts") { self.hud(app).zoom < z1 - 0.9 }175176        let z2 = hud(app).zoom177        map.pinch(withScale: 2.2, velocity: 1.5)178        waitFor("zoom par pincement") { self.hud(app).zoom > z2 + 0.5 }179        attach("gesture-pinch")180181        let b0 = hud(app).bearing182        map.rotate(0.9, withVelocity: 1.2)183        waitFor("rotation à deux doigts") { abs(self.hud(app).bearing - b0) > 10 }184        attach("gesture-rotate")185186        // Glisser : la carte suit le doigt (le zoom ne change pas, la vue reste vivante).187        let z3 = hud(app).zoom188        center.press(forDuration: 0.05, thenDragTo: map.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0.7)))189        sleep(2)190        XCTAssertEqual(hud(app).zoom, z3, accuracy: 0.05)191192        // Bascule 3D par le bouton, puis retour.193        app.buttons["toggle.mode"].tap()194        waitFor("inclinaison 3D") { self.hud(app).pitch > 40 }195        attach("gesture-3d")196        app.buttons["toggle.mode"].tap()197        waitFor("retour à plat") { self.hud(app).pitch < 1 }198    }199200    /// Toucher une pastille par son élément d'accessibilité : la fiche de sélection apparaît ; toucher201    /// l'attribution : le détail des sources s'ouvre.202    func testMarkerTapAndAttribution() {203        let app = launchPlain()204        let map = app.descendants(matching: .any)["KAMapSummary"]205        // Zoomer jusqu'à voir des pastilles individuelles.206        var marker = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'KAMapMarker-'")).firstMatch207        var tries = 0208        while !marker.exists, tries < 5 {209            map.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45)).doubleTap()210            sleep(2)211            marker = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'KAMapMarker-'")).firstMatch212            tries += 1213        }214        XCTAssertTrue(marker.exists, "aucune pastille exposée à l'accessibilité")215        XCTAssertTrue(marker.label.hasPrefix("Fictif"), "libellé inattendu : \(marker.label)")216        marker.tap()217        XCTAssertTrue(app.descendants(matching: .any)["selectionCard"].waitForExistence(timeout: 5), "la fiche de sélection n'apparaît pas après le toucher d'une pastille")218        attach("tap-marker")219220        let attribution = app.descendants(matching: .any)["KAMapAttribution"]221        XCTAssertTrue(attribution.exists, "attribution absente")222        XCTAssertTrue((attribution.value as? String ?? "").contains("OpenStreetMap"))223        attribution.tap()224        XCTAssertTrue(app.alerts.firstMatch.waitForExistence(timeout: 5), "le détail de l'attribution ne s'ouvre pas")225        attach("attribution")226        app.alerts.firstMatch.buttons.element(boundBy: 1).tap()227    }228229    /// Changement de thème et de marque par l'interface, rotation de l'écran.230    func testThemeSwitchAndRotation() {231        let app = launchPlain()232        app.buttons["menu.theme"].tap()233        app.buttons["midnight"].tap()234        sleep(2)235        attach("ui-theme-midnight")236        app.buttons["menu.brand"].tap()237        app.buttons["valoplex"].tap()238        sleep(2)239        attach("ui-brand-valoplex")240        XCUIDevice.shared.orientation = .landscapeLeft241        sleep(3)242        attach("ui-landscape")243        let att = app.descendants(matching: .any)["KAMapAttribution"]244        XCTAssertTrue(att.exists && att.frame.width > 40 && app.windows.firstMatch.frame.contains(att.frame), "l'attribution doit rester visible en paysage : \(att.frame)")245        XCUIDevice.shared.orientation = .portrait246        sleep(2)247        XCTAssertTrue(hud(app).zoom > 0)248    }249250    /// Arrière-plan puis retour : la carte reprend, les gestes répondent toujours.251    func testBackgroundAndForeground() {252        let app = launchPlain()253        let map = app.descendants(matching: .any)["KAMapSummary"]254        XCUIDevice.shared.press(.home)255        sleep(3)256        app.activate()257        XCTAssertTrue(map.waitForExistence(timeout: 15))258        sleep(2)259        attach("lifecycle-foreground")260        let z0 = hud(app).zoom261        map.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45)).doubleTap()262        waitFor("zoom après retour au premier plan") { self.hud(app).zoom > z0 + 0.9 }263    }264}265
Files main
Menu

Theme