SPB Git

Repository Public

StudioUITests.swift 6.3 KB 117 lines swift

1//2//  SP Chat iOS3//  File: SPChat-iOS/UITests/StudioUITests.swift4//  Description: UI tests of Cost Intelligence (Réglages → Dépenses), the project editor, deep research and the image5//               studio against the development backend. Nothing here starts a billed generation.6//7//  Author: Simon-Pierre Boucher8//  Contact: contact@spboucher.ai9//1011import XCTest1213final class StudioUITests: XCTestCase {14    private var baseURL: String? { ProcessInfo.processInfo.environment["SPCHAT_BASE_URL"] }15    private var token: String? { ProcessInfo.processInfo.environment["SPCHAT_DEBUG_SESSION"] }1617    override func setUp() { continueAfterFailure = false }1819    private func launch(link: String, theme: String) throws -> XCUIApplication {20        guard let baseURL, let token else { throw XCTSkip("serveur de développement non fourni (Scripts/test-live.sh uitest)") }21        let app = XCUIApplication()22        app.launchEnvironment["SPCHAT_UI_TESTS"] = "1"23        app.launchEnvironment["SPCHAT_UI_MODEL"] = "claude-haiku-5-5"24        app.launchEnvironment["SPCHAT_UI_THEME"] = theme25        app.launchEnvironment["SPCHAT_BASE_URL"] = baseURL26        app.launchEnvironment["SPCHAT_DEBUG_SESSION"] = token27        app.launchEnvironment["SPCHAT_UI_LINK"] = link28        app.launchArguments += ["-AppleLanguages", "(fr)", "-AppleLocale", "fr_CA"]29        app.launch()30        return app31    }3233    private func attach(_ app: XCUIApplication, _ name: String) {34        let a = XCTAttachment(screenshot: app.screenshot()); a.name = name; a.lifetime = .keepAlways; add(a)35    }3637    private func any(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: id).firstMatch }3839    func testCostIntelligenceShowsBudgetBasisRoutesAndConversations() throws {40        for theme in ["dark", "light"] {41            let app = try launch(link: "spchat://settings", theme: theme)42            let entry = app.staticTexts["Dépenses et utilisation"]43            XCTAssertTrue(entry.waitForExistence(timeout: 15))44            entry.tap()45            XCTAssertTrue(app.staticTexts["Budget"].waitForExistence(timeout: 15), "les limites du serveur sont affichées")46            XCTAssertTrue(app.staticTexts["Facturé ou estimé"].waitForExistence(timeout: 5), "part facturée / estimée (costBasis)")47            XCTAssertTrue(app.staticTexts["Facturé"].exists && app.staticTexts["Estimé"].exists)48            attach(app, "depenses-haut-\(theme)")49            app.swipeUp()50            attach(app, "depenses-milieu-\(theme)")51            var scrolls = 052            while !app.staticTexts["Par conversation"].exists && scrolls < 6 { app.swipeUp(); scrolls += 1 }53            XCTAssertTrue(app.staticTexts["Par route"].exists || app.staticTexts["Par conversation"].exists)54            XCTAssertTrue(app.staticTexts["Par conversation"].exists, "coût par conversation")55            attach(app, "depenses-bas-\(theme)")56            if theme == "dark" {57                // the budget editor loads the server's limits and cannot save nonsense58                var ups = 059                while !any(app, "usage.editBudget").isHittable && ups < 8 { app.swipeDown(); ups += 1 }60                any(app, "usage.editBudget").tap()61                let daily = app.textFields["budget.daily"]62                XCTAssertTrue(daily.waitForExistence(timeout: 5))63                XCTAssertFalse((daily.value as? String ?? "").isEmpty)64                XCTAssertTrue(app.buttons["budget.save"].isEnabled)65                daily.tap(); daily.typeText("x")66                XCTAssertFalse(app.buttons["budget.save"].isEnabled, "un montant invalide ne s'enregistre pas")67                attach(app, "budget-\(theme)")68                app.navigationBars["Budget"].buttons["Annuler"].tap()69                // opening a conversation from the list leaves the settings70                var downs = 071                while !app.buttons["usage.conversation"].firstMatch.isHittable && downs < 8 { app.swipeUp(); downs += 1 }72                app.buttons["usage.conversation"].firstMatch.tap()73                XCTAssertTrue(app.textFields["composer.field"].waitForExistence(timeout: 10), "la conversation s'ouvre et les réglages se ferment")74                XCTAssertFalse(app.navigationBars["Dépenses"].exists)75            }76            app.terminate()77        }78    }7980    func testProjectEditorResearchFormAndImageStudioOpen() throws {81        var app = try launch(link: "spchat://projects", theme: "dark")82        XCTAssertTrue(app.navigationBars["Projets"].waitForExistence(timeout: 15))83        attach(app, "projets")84        let row = app.descendants(matching: .any).matching(identifier: "projects.row").firstMatch85        if row.waitForExistence(timeout: 8) {86            row.tap()87            XCTAssertTrue(app.textFields["project.name"].waitForExistence(timeout: 10))88            XCTAssertFalse(app.buttons["project.save"].isEnabled, "rien à enregistrer tant que rien n'a changé")89            attach(app, "projet-editeur")90            let name = app.textFields["project.name"]91            name.tap(); name.typeText(" x")92            XCTAssertTrue(app.buttons["project.save"].isEnabled)93            app.swipeUp()94            attach(app, "projet-editeur-bas")95        }96        app.terminate()9798        app = try launch(link: "spchat://research", theme: "light")99        XCTAssertTrue(app.navigationBars["Recherche approfondie"].waitForExistence(timeout: 15))100        XCTAssertFalse(app.buttons["research.start"].isEnabled, "pas de recherche sans question")101        let q = any(app, "research.question")102        q.tap(); q.typeText("Quelle est la dernière version stable de SQLite ?")103        XCTAssertTrue(app.buttons["research.start"].isEnabled)104        any(app, "research.depth.deep").tap()105        XCTAssertTrue(app.staticTexts["≈ 8 requêtes · 12 pages · 5 à 10 min"].waitForExistence(timeout: 3))106        attach(app, "recherche")107        app.terminate()108109        app = try launch(link: "spchat://images", theme: "dark")110        XCTAssertTrue(app.navigationBars["Studio d’images"].waitForExistence(timeout: 15))111        XCTAssertFalse(app.buttons["images.generate"].isEnabled, "pas de génération sans description")112        XCTAssertTrue(any(app, "images.model").exists && any(app, "images.size").exists && any(app, "images.quality").exists)113        attach(app, "images")114        XCTAssertEqual(app.webViews.count, 0)115    }116}117
Files main
Menu

Theme