SPB Git

Repository Public

MainFlowUITests.swift 7.5 KB 166 lines swift

1//2//  Auto-Ka iOS v23//  File: AutoKaUITests/MainFlowUITests.swift4//  Description: parcours principal — accueil, recherche, filtres, fiche, favori, geste d'ouverture, marché, outils,5//               audit d'accessibilité. L'app choisit seule son service (tunnel de développement, sinon préproduction).6//7//  Author: Simon-Pierre Boucher8//  Contact: contact@spboucher.ai9//1011import XCTest1213final class MainFlowUITests: XCTestCase {14    private var app: XCUIApplication!15    /// identifiant d'un vrai véhicule, choisi par Scripts/build.sh uitest16    private var uid: String? { ProcessInfo.processInfo.environment["AUTOKA_TEST_UID"] }1718    override func setUp() {19        continueAfterFailure = false20        app = XCUIApplication()21        app.launchArguments = ["-AKInMemory", "YES", "-AppleLanguages", "(fr-CA)"]22    }2324    private func snap(_ name: String) {25        let a = XCTAttachment(screenshot: XCUIScreen.main.screenshot())26        a.name = name27        a.lifetime = .keepAlways28        add(a)29    }3031    private func tab(_ name: String) -> XCUIElement {32        let bar = app.tabBars.buttons[name]33        return bar.exists ? bar : app.buttons[name].firstMatch34    }3536    private func any(_ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }3738    func testHomeThenSearch() {39        app.launch()40        XCTAssertTrue(app.staticTexts["Les véhicules d'occasion à vendre au Québec"].waitForExistence(timeout: 25), "le titre de l'accueil est affiché")41        let go = app.buttons["lancer-recherche"]42        XCTAssertTrue(go.waitForExistence(timeout: 20))43        snap("accueil")44        go.tap()45        XCTAssertTrue(any("total").waitForExistence(timeout: 25), "la recherche affiche un nombre de véhicules")46        XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'carte-'")).firstMatch.waitForExistence(timeout: 20), "au moins une carte de résultat")47        snap("recherche")48    }4950    func testFiltersNarrowTheSearch() {51        app.launchArguments += ["-AKSearch", "make:Toyota"]52        app.launch()53        let total = any("total")54        XCTAssertTrue(total.waitForExistence(timeout: 25))55        let before = total.label56        app.buttons["filtres"].tap()57        let chip = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Berline'")).firstMatch58        XCTAssertTrue(chip.waitForExistence(timeout: 15), "les carrosseries viennent des facettes")59        // la section Carrosserie est sous la ligne de flottaison de la feuille60        app.swipeUp()61        XCTAssertTrue(chip.isHittable)62        chip.tap()63        let apply = app.buttons["appliquer-filtres"]64        XCTAssertTrue(apply.waitForExistence(timeout: 5))65        snap("filtres")66        apply.tap()67        XCTAssertTrue(total.waitForExistence(timeout: 15))68        let changed = expectation(for: NSPredicate(format: "label != %@", before), evaluatedWith: total)69        wait(for: [changed], timeout: 20)70        snap("recherche-filtree")71    }7273    func testVehicleFavoriteRoundTrip() throws {74        let uid = try XCTUnwrap(uid, "AUTOKA_TEST_UID absent : lancer par Scripts/build.sh uitest")75        app.launchArguments += ["-AKOpen", "vehicule/\(uid)"]76        app.launch()77        XCTAssertTrue(any("prix").waitForExistence(timeout: 25), "le prix demandé est affiché")78        XCTAssertTrue(any("galerie").exists)79        snap("fiche")80        let fav = app.buttons["favori"]81        XCTAssertTrue(fav.waitForExistence(timeout: 5))82        fav.tap()83        app.swipeUp()84        app.swipeUp()85        snap("fiche-bas")86        tab("Favoris").tap()87        XCTAssertTrue(app.staticTexts["1 favori"].waitForExistence(timeout: 10), "le favori est gardé sur l'appareil")88        snap("favoris")89    }9091    /// Le geste « monter à bord » : toucher une carte de l'accueil joue l'animation, puis la fiche est là.92    func testBoardingOpensVehicleFromCard() {93        app.launch()94        let card = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'carte-'")).firstMatch95        XCTAssertTrue(card.waitForExistence(timeout: 25))96        card.tap()97        XCTAssertTrue(any("prix").waitForExistence(timeout: 12), "la fiche s'ouvre après le geste")98        snap("fiche-apres-geste")99        app.navigationBars.buttons.firstMatch.tap()100        XCTAssertTrue(app.buttons["lancer-recherche"].waitForExistence(timeout: 8), "le retour ramène à l'accueil")101    }102103    /// Un second toucher pendant l'animation l'interrompt : la fiche s'ouvre tout de suite.104    func testBoardingInterruptedByTap() {105        app.launchArguments += ["-AKBoardSlow", "4"]106        app.launch()107        let card = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'carte-'")).firstMatch108        XCTAssertTrue(card.waitForExistence(timeout: 25))109        card.tap()110        app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.7)).tap()111        XCTAssertTrue(any("prix").waitForExistence(timeout: 6), "l'interruption amène l'état final")112    }113114    func testMarketAndTools() {115        app.launchArguments += ["-AKTab", "market"]116        app.launch()117        XCTAssertTrue(app.staticTexts["prix demandé médian"].waitForExistence(timeout: 25), "les chiffres du marché sont chargés")118        snap("marche")119        tab("Plus").tap()120        XCTAssertTrue(app.staticTexts["Décodeur de NIV"].waitForExistence(timeout: 10))121        app.staticTexts["Concessionnaires"].firstMatch.tap()122        XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS 'commerces'")).firstMatch.waitForExistence(timeout: 25), "l'annuaire est chargé")123        snap("concessionnaires")124    }125126    /// Audit d'accessibilité d'Xcode. Les descriptions manquantes font échouer le test ; contraste et texte coupé127    /// sont consignés (AUTOKA_AUDIT_STRICT=1 les rend bloquants).128    func testAccessibilityAudit() throws {129        let strict = ProcessInfo.processInfo.environment["AUTOKA_AUDIT_STRICT"] == "1"130        let report = AuditReport()131        func audit(_ screen: String) throws {132            try app.performAccessibilityAudit(for: [.sufficientElementDescription, .hitRegion, .contrast, .textClipped, .trait]) { issue in133                let el = issue.element.map { "\($0.elementType.rawValue) « \($0.label) » \($0.identifier)" } ?? "?"134                report.lines.append("\(screen) | \(issue.auditType.rawValue) | \(issue.compactDescription) | \(el)")135                if strict { return false }136                return issue.auditType != .sufficientElementDescription137            }138        }139        defer {140            let a = XCTAttachment(string: report.lines.joined(separator: "\n")); a.name = "audit"; a.lifetime = .keepAlways; add(a)141        }142        app.launch()143        XCTAssertTrue(app.buttons["lancer-recherche"].waitForExistence(timeout: 25))144        try audit("accueil")145        tab("Favoris").tap()146        XCTAssertTrue(app.staticTexts["Aucun favori"].waitForExistence(timeout: 10))147        try audit("favoris vides")148        tab("Plus").tap()149        XCTAssertTrue(app.staticTexts["Décodeur de NIV"].waitForExistence(timeout: 10))150        try audit("plus")151        if let uid {152            app.terminate()153            app.launchArguments += ["-AKOpen", "vehicule/\(uid)"]154            app.launch()155            XCTAssertTrue(any("prix").waitForExistence(timeout: 25))156            sleep(3)157            try audit("fiche")158        }159    }160}161162/// Signalements de l'audit, consignés dans les pièces jointes du test.163private final class AuditReport: @unchecked Sendable {164    var lines: [String] = []165}166
Files main
Menu

Theme