Repository Public
1//2// Food-Ka iOS v23// File: FoodKaUITests/MainFlowUITests.swift4// Description: parcours principaux contre l'API de préproduction — accueil, recherche tolérante aux fautes, fiche5// et geste, liste d'épicerie et coût par enseigne, mode « à l'épicerie », produits suivis, hors ligne.6// Captures jointes au résultat.7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10//1112import XCTest1314@MainActor15final class MainFlowUITests: XCTestCase {16 private let product = "maxi:20894117004_EA" // nectar de mangue Del Monte, suivi dans 6 enseignes17 private let list = "provigo:20300006008_EA,provigo:20336722014_EA,metro:067311268376"1819 private func launch(_ args: [String]) -> XCUIApplication {20 continueAfterFailure = false21 let app = XCUIApplication()22 app.launchArguments = ["-FKInMemory", "YES", "-FKShelf", "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 tab(_ app: XCUIApplication, _ name: String) {34 let b = app.tabBars.buttons[name].firstMatch35 if b.waitForExistence(timeout: 5) { b.tap() } else { app.buttons[name].firstMatch.tap() }36 }3738 func testHomeShowsSearchDealsAndAisles() {39 let app = launch(["-FKTab", "home"])40 XCTAssertTrue(app.textFields["search-field"].waitForExistence(timeout: 15))41 XCTAssertTrue(app.staticTexts["Baisses vérifiées du moment"].waitForExistence(timeout: 20))42 XCTAssertTrue(app.buttons["index-line"].waitForExistence(timeout: 20), "l'indice du panier tient en une ligne")43 XCTAssertFalse(app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'aubaine'")).firstMatch.exists, "jamais le mot « aubaine »")44 attach(app, "accueil")45 }4647 func testSuggestionsThenTypoTolerantSearchOpensProduct() {48 let app = launch(["-FKTab", "home", "-FKQuery", "croustiles ketchup"])49 XCTAssertTrue(app.buttons["search-all"].waitForExistence(timeout: 20), "l'autocomplétion s'ouvre")50 attach(app, "suggestions")51 app.buttons["search-all"].tap()52 let count = app.staticTexts["results-count"]53 XCTAssertTrue(count.waitForExistence(timeout: 20))54 let found = NSPredicate(format: "label MATCHES %@", "[0-9].* produits?")55 expectation(for: found, evaluatedWith: count)56 waitForExpectations(timeout: 20)57 XCTAssertFalse(app.otherElements["results-empty"].exists, "« croustiles » trouve les croustilles")58 attach(app, "resultats")59 let first = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'product-'")).firstMatch60 XCTAssertTrue(first.waitForExistence(timeout: 10))61 first.tap()62 XCTAssertTrue(app.staticTexts["product-title"].waitForExistence(timeout: 20))63 XCTAssertTrue(app.otherElements["shelf-scene"].waitForExistence(timeout: 10), "la mise en tablette a lieu")64 attach(app, "fiche")65 }6667 func testProductShowsRailHistoryAndVerdict() {68 let app = launch(["-FKOpen", "produit/\(product)"])69 XCTAssertTrue(app.staticTexts["product-title"].waitForExistence(timeout: 20))70 let scene = app.otherElements["shelf-scene"]71 XCTAssertTrue(scene.waitForExistence(timeout: 10))72 XCTAssertTrue(scene.label.contains("$") && scene.label.contains("enseignes"), scene.label)73 app.swipeUp()74 XCTAssertTrue(app.staticTexts["Comparaison entre enseignes"].waitForExistence(timeout: 10))75 let best = app.descendants(matching: .any)["rail-row-0"]76 XCTAssertTrue(best.waitForExistence(timeout: 10))77 XCTAssertTrue(best.label.contains("le moins cher"), best.label)78 attach(app, "rail")79 app.swipeUp(); app.swipeUp()80 XCTAssertTrue(app.staticTexts["Historique du prix"].waitForExistence(timeout: 10))81 attach(app, "historique")82 }8384 func testAddToListThenCompareByStore() {85 let app = launch(["-FKOpen", "produit/\(product)"])86 let add = app.buttons["add-to-list"]87 XCTAssertTrue(add.waitForExistence(timeout: 20))88 add.tap()89 tab(app, "Liste")90 XCTAssertTrue(app.buttons["basket-line-0"].waitForExistence(timeout: 10), "le produit est dans la liste")91 app.buttons["qty-plus-0"].tap()92 XCTAssertEqual(app.staticTexts["qty-0"].label, "Quantité : 2")93 let field = app.textFields["basket-add-field"]94 field.tap()95 field.typeText("bananes\n")96 XCTAssertTrue(app.buttons["basket-line-1"].waitForExistence(timeout: 5), "une recherche libre devient une ligne")97 XCTAssertTrue(app.staticTexts["Coût par enseigne"].waitForExistence(timeout: 10))98 XCTAssertTrue(app.staticTexts["basket-statement"].waitForExistence(timeout: 30), "le coût par enseigne arrive")99 attach(app, "liste")100 }101102 func testSeededListStoreMode() {103 let app = launch(["-FKTab", "basket", "-FKSeed", list, "-FKSeedQ", "bananes"])104 XCTAssertTrue(app.buttons["basket-line-3"].waitForExistence(timeout: 30))105 app.buttons["store-mode-button"].tap()106 let remaining = app.staticTexts["store-mode-remaining"]107 XCTAssertTrue(remaining.waitForExistence(timeout: 10))108 XCTAssertEqual(remaining.label, "4 à trouver")109 app.buttons["check-bananes"].tap()110 XCTAssertEqual(remaining.label, "3 à trouver")111 XCTAssertEqual(app.buttons["check-bananes"].value as? String, "coché")112 attach(app, "a-l-epicerie")113 app.buttons["store-mode-close"].tap()114 XCTAssertTrue(app.staticTexts["basket-count"].waitForExistence(timeout: 5))115 XCTAssertTrue(app.staticTexts["basket-count"].label.contains("3 à trouver"))116 }117118 func testFollowedDropIsFlaggedAtLaunch() {119 // le premier produit suivi est semé avec un ancien prix plus élevé : sa baisse doit être signalée120 let app = launch(["-FKTab", "followed", "-FKFollow", product])121 XCTAssertTrue(app.staticTexts["En baisse depuis votre dernier passage"].waitForExistence(timeout: 30))122 attach(app, "suivis")123 app.buttons["acknowledge"].tap()124 XCTAssertTrue(app.staticTexts["Produits suivis"].waitForExistence(timeout: 5))125 }126127 func testDealsAndFlyerValidity() {128 let app = launch(["-FKTab", "deals"])129 XCTAssertTrue(app.staticTexts["Baisses vérifiées"].waitForExistence(timeout: 20))130 XCTAssertTrue(app.staticTexts["Circulaires en cours"].waitForExistence(timeout: 20))131 let flyer = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'flyer-'")).firstMatch132 XCTAssertTrue(flyer.waitForExistence(timeout: 10))133 flyer.tap()134 let validity = app.staticTexts["flyer-validity"]135 XCTAssertTrue(validity.waitForExistence(timeout: 20))136 XCTAssertTrue(validity.label.hasPrefix("Valide du "), validity.label)137 attach(app, "circulaire")138 }139140 func testMarketIndexAndStores() {141 let app = launch(["-FKTab", "market"])142 XCTAssertTrue(app.staticTexts["index-value"].waitForExistence(timeout: 20))143 attach(app, "marche")144 let app2 = launch(["-FKTab", "home", "-FKOpen", "enseigne/maxi"])145 XCTAssertTrue(app2.staticTexts["store-title"].waitForExistence(timeout: 20))146 XCTAssertEqual(app2.staticTexts["store-title"].label, "Maxi")147 attach(app2, "enseigne")148 }149150 func testOfflineKeepsTheListUsable() {151 // service injoignable : l'accueil le dit, la liste d'épicerie fonctionne152 let app = launch(["-FKTab", "basket", "-FKBaseURL", "http://127.0.0.1:9", "-FKSeedQ", "bananes,lait 2 L"])153 XCTAssertTrue(app.buttons["basket-line-1"].waitForExistence(timeout: 20), "la liste s'affiche sans réseau")154 app.buttons["qty-plus-0"].tap()155 XCTAssertEqual(app.staticTexts["qty-0"].label, "Quantité : 2")156 XCTAssertTrue(app.descendants(matching: .any)["compare-error"].firstMatch.waitForExistence(timeout: 30), "la panne de comparaison est dite")157 attach(app, "liste-hors-ligne")158 tab(app, "Accueil")159 // l'accueil dit la panne, ou sert la dernière version consultée en le disant160 let stale = app.descendants(matching: .any)["stale-banner"].firstMatch161 XCTAssertTrue(app.staticTexts["Pas de connexion"].waitForExistence(timeout: 15) || stale.waitForExistence(timeout: 15))162 attach(app, "accueil-hors-ligne")163 }164165 func testUnknownBarcodeLeadsToSearchByName() {166 let app = launch(["-FKTab", "home", "-FKSheet", "scan", "-FKCode", "0671234567890"])167 XCTAssertTrue(app.descendants(matching: .any)["barcode-unknown"].firstMatch.waitForExistence(timeout: 20), "un code inconnu est dit clairement")168 XCTAssertTrue(app.buttons["Chercher par nom"].exists)169 attach(app, "code-inconnu")170 let app2 = launch(["-FKTab", "home", "-FKSheet", "scan", "-FKCode", "067311268376"])171 XCTAssertTrue(app2.staticTexts["barcode-found"].waitForExistence(timeout: 20))172 attach(app2, "code-trouve")173 }174175 func testSettingsAccessibilityAudit() throws {176 let app = launch(["-FKTab", "home", "-FKRoute", "settings"])177 XCTAssertTrue(app.staticTexts["Thème"].waitForExistence(timeout: 15))178 try app.performAccessibilityAudit(for: [.sufficientElementDescription, .hitRegion]) { issue in179 // le système signale ses propres éléments de barre (bouton retour) : ignorés180 issue.element == nil || issue.element?.elementType == .navigationBar181 }182 attach(app, "reglages")183 }184}185