SPB Git

Repository Public

VQuantUITests.swift 4.7 KB 66 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Tests/UITests/VQuantUITests.swift3// Description: UI tests of the signed-out application (no session, no network dependency): the sign-in screen and its setup-link validation.4import XCTest56final class VQuantUITests: XCTestCase {7    func testSignInScreenAndSetupLinkValidation() throws {8        let app = XCUIApplication()9        app.launchArguments = ["-VQUITest", "-VQInMemory", "-VQServer", "http://127.0.0.1:9", "-ApplePersistenceIgnoreState", "YES"]10        app.launch()11        let button = app.buttons["signin.passkey"]12        XCTAssertTrue(button.waitForExistence(timeout: 15), "the sign-in screen is shown when no session exists")13        app.descendants(matching: .any)["signin.setup"].firstMatch.click()14        let field = app.textFields["signin.link"]15        XCTAssertTrue(field.waitForExistence(timeout: 5))16        field.click(); field.typeText("not a link")17        app.buttons["Enrol"].click()18        let message = app.staticTexts["signin.message"]19        XCTAssertTrue(message.waitForExistence(timeout: 5))20        XCTAssertEqual((message.value as? String).flatMap { $0.isEmpty ? nil : $0 } ?? message.label, "This is not a VQuant setup link.")21        // nothing behind the gate is reachable while signed out22        XCTAssertFalse(app.outlines.buttons["sidebar.research"].exists)23    }2425    /// Signed in on the backend TEST copy (Scripts/ui-test.sh passes a development session): every sidebar entry (14 in 2.0) is26    /// clickable and shows its section; the dataset list and a detached chart respond too.27    func testSidebarNavigationAndSections() throws {28        let env = ProcessInfo.processInfo.environment29        guard let token = env["VQ_DEV_TOKEN"], let server = env["VQ_SERVER"] else { throw XCTSkip("needs a development session (Scripts/ui-test.sh)") }30        let app = XCUIApplication()31        app.launchArguments = ["-VQUITest", "-VQInMemory", "-ApplePersistenceIgnoreState", "YES"]32        app.launchEnvironment = ["VQ_DEV_TOKEN": token, "VQ_SERVER": server]33        app.launch()34        let window = app.windows.firstMatch35        XCTAssertTrue(window.waitForExistence(timeout: 20))36        let sections = ["research": "Research", "studio": "Research Studio", "overview": "Overview", "markets": "Markets", "watchlists": "Watchlists", "charting": "Charting",37                        "statements": "Statements", "quant": "Quant Lab", "portfolio": "Portfolios", "data": "Data Explorer", "risk": "Risk Analytics", "jobs": "Jobs",38                        "agent": "Agent", "documents": "Documents"]39        for key in ["studio", "overview", "markets", "watchlists", "charting", "statements", "quant", "portfolio", "data", "risk", "jobs", "agent", "documents", "research"] {40            let row = app.descendants(matching: .any)["sidebar.\(key)"].firstMatch41            XCTAssertTrue(row.waitForExistence(timeout: 10), "sidebar entry \(key) exists")42            row.click()43            // the window title is the section title44            let deadline = Date().addingTimeInterval(3)45            // the title is the section name, followed by a subtitle in some sections ("Charting – AAPL")46            // exact title or "Title – subtitle": "Research" must not be satisfied by "Research Studio"47            func shown() -> Bool { let t = window.title; let want = sections[key]!; return t == want || t.hasPrefix(want + " –") || t.hasPrefix(want + " —") || t.hasPrefix(want + " -") }48            while !shown(), Date() < deadline { usleep(150_000) }49            XCTAssertTrue(shown(), "clicking \(key) shows its section (title: \(window.title))")50        }51        // lists inside sections select too: a computation in the Quant Engine, a conversation in Research52        app.descendants(matching: .any)["sidebar.quant"].firstMatch.click()53        let job = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'quantjob.'")).firstMatch54        if job.waitForExistence(timeout: 10) {55            job.click()56            XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "value BEGINSWITH 'Job ' OR label BEGINSWITH 'Job '")).firstMatch.waitForExistence(timeout: 10), "selecting a computation shows its provenance line")57        }58        // inside a section: the dataset list changes the dataset59        app.descendants(matching: .any)["sidebar.data"].firstMatch.click()60        let balance = app.descendants(matching: .any)["dataset.balance-sheet"].firstMatch61        XCTAssertTrue(balance.waitForExistence(timeout: 10))62        balance.click()63        XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "value CONTAINS 'Balance sheet' OR label CONTAINS 'Balance sheet'")).firstMatch.waitForExistence(timeout: 10))64    }65}66
Files main
Menu

Theme