SPB Git

Repository Public

MainFlowUITests.swift 9.1 KB 173 lines swift

1//2//  Fabri-Ka iOS v23//  File: FabriKaUITests/MainFlowUITests.swift4//  Description: parcours principaux contre l'API de préproduction — accueil, autocomplétion, recherche tolérante5//               aux fautes jusqu'à la fiche et son enseigne, favoris, boutique et suivi, carte, hors ligne,6//               inscription (validation locale seulement : aucune demande n'est envoyée). Captures jointes.7//8//  Author: Simon-Pierre Boucher9//  Contact: contact@spboucher.ai10//1112import XCTest1314@MainActor15final class MainFlowUITests: XCTestCase {16    private let product = "cafd5ce66af3bec2d78e"      // tuque en laine mérinos, 10 photos17    private let store = "tranchedebois.com"1819    private func launch(_ args: [String]) -> XCUIApplication {20        continueAfterFailure = false21        let app = XCUIApplication()22        app.launchArguments = ["-FBInMemory", "YES", "-FBSign", "courte"] + args23        app.launch()24        return app25    }2627    private func attach(_ app: XCUIApplication, _ name: String) {28        let a = XCTAttachment(screenshot: app.screenshot())29        a.name = name; a.lifetime = .keepAlways30        add(a)31    }3233    private func any(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }3435    private func tab(_ app: XCUIApplication, _ name: String) {36        let b = app.tabBars.buttons[name].firstMatch37        if b.waitForExistence(timeout: 5) { b.tap() } else { app.buttons[name].firstMatch.tap() }38    }3940    func testHomeShowsDiscoveriesCategoriesAndNoAccount() {41        let app = launch(["-FBTab", "home"])42        XCTAssertTrue(app.buttons["home-search"].waitForExistence(timeout: 15))43        XCTAssertTrue(app.staticTexts["Vus pour la première fois cette semaine"].waitForExistence(timeout: 20))44        XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'product-'")).firstMatch.waitForExistence(timeout: 20))45        for word in ["connexion", "compte Ka", "Groupe Ka", "certifié", "Acheter"] {46            XCTAssertFalse(app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] %@", word)).firstMatch.exists, "jamais « \(word) » à l'accueil")47        }48        attach(app, "accueil")49    }5051    func testSuggestionsOfferSearchStoresAndTerms() {52        let app = launch(["-FBTab", "search", "-FBQuery", "sav"])53        XCTAssertTrue(app.buttons["search-all"].waitForExistence(timeout: 20), "l'autocomplétion s'ouvre")54        XCTAssertTrue(app.buttons["savon"].waitForExistence(timeout: 20), "les mots du vocabulaire sont proposés")55        XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'suggest-store-'")).firstMatch.waitForExistence(timeout: 10))56        attach(app, "suggestions")57    }5859    func testTypoTolerantSearchOpensProductWithItsSign() {60        let app = launch(["-FBTab", "search", "-FBRoute", "search", "-FBSearch", "bracelt cuir"])61        let count = app.staticTexts["results-count"]62        XCTAssertTrue(count.waitForExistence(timeout: 20))63        XCTAssertTrue(count.label.contains("produits") && count.label.contains("boutiques"), count.label)64        let understood = app.staticTexts["results-understood"]65        XCTAssertTrue(understood.waitForExistence(timeout: 10), "le service dit ce qu'il a compris")66        XCTAssertTrue(understood.label.contains("bracelet"), understood.label)67        attach(app, "resultats")68        let first = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'product-'")).firstMatch69        XCTAssertTrue(first.waitForExistence(timeout: 10))70        first.tap()71        XCTAssertTrue(app.staticTexts["product-title"].waitForExistence(timeout: 20))72        let plaque = app.buttons["store-plaque"]73        XCTAssertTrue(plaque.waitForExistence(timeout: 10), "l'enseigne de la boutique est posée")74        XCTAssertTrue(plaque.label.contains("Boutique") || plaque.label.contains("Revendeur"), plaque.label)75        let visit = app.buttons["visit-store"]76        XCTAssertTrue(visit.waitForExistence(timeout: 10))77        XCTAssertTrue(visit.label.hasPrefix("Voir chez"), "le bouton dit où il mène : \(visit.label)")78        attach(app, "fiche")79    }8081    func testProductOrderThenFavoriteAppearsInSaved() {82        let app = launch(["-FBOpen", "produit/\(product)"])83        let title = app.staticTexts["product-title"]84        XCTAssertTrue(title.waitForExistence(timeout: 20))85        let price = app.staticTexts["product-price"], plaque = app.buttons["store-plaque"], visit = app.buttons["visit-store"]86        XCTAssertTrue(price.waitForExistence(timeout: 10) && plaque.waitForExistence(timeout: 10) && visit.waitForExistence(timeout: 10))87        // ordre standard : photos → prix, nom → boutique → action88        let gallery = any(app, "product-gallery")89        XCTAssertTrue(gallery.exists)90        XCTAssertLessThan(gallery.frame.minY, price.frame.minY)91        XCTAssertLessThan(price.frame.minY, title.frame.minY)92        XCTAssertLessThan(title.frame.maxY, plaque.frame.minY + 1)93        XCTAssertLessThan(plaque.frame.minY, visit.frame.minY)94        let fav = app.buttons["favorite-toggle"]95        XCTAssertTrue(fav.waitForExistence(timeout: 10))96        XCTAssertEqual(fav.label, "Garder dans les favoris")97        fav.tap()98        XCTAssertTrue(any(app, "toast").waitForExistence(timeout: 5))99        XCTAssertEqual(fav.label, "Retirer des favoris")100        attach(app, "fiche-gardee")101        app.navigationBars.buttons.element(boundBy: 0).tap()   // la fiche masque la barre d'onglets : retour d'abord102        tab(app, "Favoris")103        XCTAssertTrue(app.buttons["product-\(product)"].waitForExistence(timeout: 10), "le produit gardé est dans les favoris")104        attach(app, "favoris")105    }106107    func testStorePageShowsSignCatalogueAndFollow() {108        let app = launch(["-FBTab", "stores", "-FBOpen", "boutique/\(store)"])109        let sign = any(app, "store-sign")110        XCTAssertTrue(sign.waitForExistence(timeout: 20))111        XCTAssertTrue(sign.label.contains("Tranche de bois"), sign.label)112        XCTAssertTrue(app.buttons["visit-site"].waitForExistence(timeout: 10))113        let follow = app.buttons["follow-toggle"]114        XCTAssertTrue(follow.waitForExistence(timeout: 10))115        follow.tap()116        XCTAssertTrue(follow.label.hasPrefix("Ne plus suivre"), follow.label)117        attach(app, "boutique")118        app.swipeUp()119        XCTAssertTrue(app.staticTexts["Ses produits"].waitForExistence(timeout: 10))120        tab(app, "Favoris")121        app.segmentedControls.buttons.element(boundBy: 1).tap()122        XCTAssertTrue(app.buttons["store-\(store)"].waitForExistence(timeout: 10), "la boutique suivie est accrochée dans les favoris")123        attach(app, "boutiques-suivies")124    }125126    func testDirectoryListAndMap() {127        let app = launch(["-FBTab", "stores"])128        let count = app.staticTexts["stores-count"]129        XCTAssertTrue(count.waitForExistence(timeout: 20))130        XCTAssertTrue(count.label.contains("boutiques"), count.label)131        XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'store-'")).firstMatch.waitForExistence(timeout: 10))132        app.segmentedControls.buttons["Carte"].tap()133        let caption = app.staticTexts["map-caption"]134        XCTAssertTrue(caption.waitForExistence(timeout: 20))135        XCTAssertTrue(caption.label.contains("sans position connue"), "la carte dit ce qu'elle ne montre pas : \(caption.label)")136        attach(app, "carte")137    }138139    func testOfflineIsSaidAndSavedStaysUsable() {140        // une recherche jamais faite, service injoignable : la panne est dite, sans cache à servir141        let app = launch(["-FBTab", "search", "-FBRoute", "search", "-FBSearch", "hors ligne \(UUID().uuidString.prefix(8))",142                          "-FBBaseURL", "http://127.0.0.1:9"])143        XCTAssertTrue(any(app, "error-state").waitForExistence(timeout: 30))144        XCTAssertTrue(app.staticTexts["Pas de connexion"].exists)145        XCTAssertTrue(app.buttons["Réessayer"].exists)146        attach(app, "hors-ligne")147        app.navigationBars.buttons.element(boundBy: 0).tap()148        tab(app, "Favoris")149        XCTAssertTrue(any(app, "favorites-empty").waitForExistence(timeout: 10), "les favoris restent consultables sans réseau")150    }151152    func testRegisterFormValidatesLocallyWithoutSending() {153        let app = launch(["-FBTab", "home", "-FBRoute", "register"])154        let send = app.buttons["register-send"]155        XCTAssertTrue(app.textFields["register-name"].waitForExistence(timeout: 20))156        for _ in 0..<6 where !send.isHittable { app.swipeUp() }157        // formulaire vide : la demande ne part pas, le manque est dit158        send.tap()159        let problem = app.staticTexts["register-problem"]160        XCTAssertTrue(problem.waitForExistence(timeout: 5))161        XCTAssertTrue(problem.label.contains("nom de la boutique"), problem.label)162        XCTAssertFalse(any(app, "register-done").exists)163        attach(app, "inscription")164    }165166    func testSettingsAccessibilityAudit() throws {167        let app = launch(["-FBTab", "home", "-FBRoute", "settings"])168        XCTAssertTrue(app.buttons["erase-data"].waitForExistence(timeout: 15))169        try app.performAccessibilityAudit(for: [.sufficientElementDescription, .hitRegion])170        attach(app, "reglages")171    }172}173
Files main
Menu

Theme