SPB Git

Repository Public

Next2UITests.swift 18.3 KB 333 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Drive pour iPhone et iPad9// File             : UITests/Next2UITests.swift10// Description      : Interface tests of the SP Drive 2.0 screens against the11//                    2.0 test backend: content search with highlighted12//                    passages, « ask this document » (the test bed's language13//                    model is a FAKE endpoint — no real model is exercised),14//                    versions compared, tags, collections, storage, activity,15//                    members and roles, « Partagés avec moi » for a viewer and16//                    for an uploader, the devices dashboard, the QR code of a17//                    link — and a 1.0 server, which must show none of the 2.018//                    controls.19// Module           : UITests20// Repository       : https://git.spboucher.ai/sp-drive-ios21// Created          : 2026-11-1922// Last Modified    : 2026-11-1923//24// =============================================================================25// AUTHOR & PROFESSIONAL AFFILIATION26// =============================================================================27//28// Author           : Simon-Pierre Boucher29// Position         : Professor of Finance30// Institution      : Université du Québec en Outaouais (UQO)31// Department       : Département des sciences administratives32// Organization     : SP Boucher33//34// Website          : https://spboucher.ai35// Git              : https://git.spboucher.ai36//37// =============================================================================38// OFFICIAL CONTACT DIRECTORY39// =============================================================================40//41// General          : info@spboucher.ai42// Professional     : contact@spboucher.ai43// Direct           : simon@spboucher.ai44// Research         : research@spboucher.ai45// Development      : dev@spboucher.ai46// Support          : support@spboucher.ai47// Security/Admin   : admin@spboucher.ai48// Notifications    : notifications@spboucher.ai49//50// Preferred Contact: support@spboucher.ai51//52// =============================================================================53// COPYRIGHT & INTELLECTUAL PROPERTY54// =============================================================================55//56// Copyright (c) 202657// Simon-Pierre Boucher58//59// All rights reserved where applicable.60//61// This file is governed by the applicable project license,62// copyright notices, institutional agreements and relevant law.63//64// Unless expressly authorized by the applicable license or65// rights holder, copying, redistribution, sublicensing,66// publication and commercial exploitation are not permitted.67//68// Existing third-party rights and notices remain unaffected.69//70// =============================================================================71// CONFIDENTIALITY & SECURITY72// =============================================================================73//74// Classification   : Public75// Distribution     : Public repository; use is governed by the project license76// Security Contact : admin@spboucher.ai77//78// Access to this source does not independently grant permission79// to redistribute or disclose confidential materials.80//81// Do not embed credentials, private keys, access tokens,82// certificates or confidential personal information.83//84// =============================================================================85// LICENSE & MAINTENANCE86// =============================================================================87//88// License          : None specified (no license file in this repository)89// Maintainer       : Simon-Pierre Boucher90// Technical Contact: dev@spboucher.ai91//92// =============================================================================93// END OF SP BOUCHER SOURCE HEADER94// =============================================================================9596import XCTest9798final class Next2UITests: DriveUITestCase {99    private var tokenC: String { ProcessInfo.processInfo.environment["SPDRIVE_TEST_TOKEN_C"] ?? "" }100    private var emailB: String { ProcessInfo.processInfo.environment["SPDRIVE_TEST_EMAIL_B"] ?? "" }101    private var emailC: String { ProcessInfo.processInfo.environment["SPDRIVE_TEST_EMAIL_C"] ?? "" }102    private func el(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }103    private func poll(_ timeout: TimeInterval = 30, _ what: String, _ condition: @escaping () -> Bool) {104        let deadline = Date().addingTimeInterval(timeout)105        while Date() < deadline { if condition() { return }; Thread.sleep(forTimeInterval: 0.5) }106        XCTFail("timed out: \(what)")107    }108    private func upload(_ name: String, _ text: String, folder: String, fileID: String? = nil, as bearer: String? = nil) throws -> String {109        let data = Data(text.utf8)110        var body: [String: Any] = ["folderId": folder, "name": name, "size": data.count]111        if let fileID { body["fileId"] = fileID; body["onConflict"] = "version" }112        let h = bearer.map { ["Authorization": "Bearer \($0)"] } ?? [:]113        let up = try XCTUnwrap(api("POST", "/api/v1/uploads", json: body, headers: h)["id"] as? String)114        try api("PATCH", "/api/v1/uploads/\(up)?offset=0", raw: data, headers: h)115        let file = try XCTUnwrap(api("POST", "/api/v1/uploads/\(up)/complete", headers: h)["file"] as? [String: Any])116        return try XCTUnwrap(file["id"] as? String)117    }118    private func closeSheet(_ app: XCUIApplication) { for label in ["Fermer", "OK"] where app.buttons[label].firstMatch.exists { app.buttons[label].firstMatch.tap(); return } }119120    func testSearchAskVersionsTagsCollectionsStorageActivity() throws {121        let meta = try api("GET", "/api/v1/meta")122        try XCTSkipUnless((meta["api"] as? Int) == 2, "needs the 2.0 backend")123        let word = "zygomatique\(UUID().uuidString.prefix(5).lowercased())"124        let folderName = "Deux \(UUID().uuidString.prefix(5))"125        let folderID = try seedFolder(folderName)126        let fileID = try upload("compte rendu.txt", "Réunion du lundi.\nBudget approuvé.\nFin.", folder: folderID)127        _ = try upload("compte rendu.txt", "Réunion du lundi.\nBudget approuvé, le mot rare est \(word).\nProchaine réunion mardi.\nFin.", folder: folderID, fileID: fileID)128        poll(60, "text indexed on the server") { ((try? self.apiSync("/api/v1/files/\(fileID)/text"))?["status"] as? String) == "ready" }129        try api("POST", "/api/v1/collections", json: ["name": "Textes \(word.suffix(5))", "color": "teal", "rule": ["match": "all", "conditions": [["field": "name", "op": "contains", "value": "compte rendu"]]]])130131        let app = launch(signedIn: true)132        XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))133134        // 1. search: a word that is only inside the document135        if isPad { app.buttons["Rechercher"].firstMatch.tap() } else { app.tabBars.buttons["Recherche"].tap() }136        let search = app.searchFields.firstMatch137        XCTAssertTrue(search.waitForExistence(timeout: 10))138        search.tap(); search.typeText(word)139        let hit = el(app, "hit.compte rendu.txt")140        XCTAssertTrue(hit.waitForExistence(timeout: 15), "found by its content")141        XCTAssertTrue(hit.label.contains(word), "the passage is shown: \(hit.label)")142        XCTAssertTrue(el(app, "search.scope").exists)143        shot("100-recherche-contenu")144        if isPad { app.buttons["Fermer"].firstMatch.tap() } else {145            search.typeText("\n") // the keyboard goes away and the tab bar comes back146            XCTAssertTrue(app.tabBars.buttons["Mon Drive"].waitForExistence(timeout: 8))147            app.tabBars.buttons["Mon Drive"].tap()148        }149        XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 10))150        item(app, folderName).tap()151        XCTAssertTrue(item(app, "compte rendu.txt").waitForExistence(timeout: 10))152153        // 2. ask this document — answered by the test bed's fake endpoint, which says so154        el(app, "more.compte rendu.txt").tap()155        XCTAssertTrue(el(app, "sheet.ask").waitForExistence(timeout: 5))156        shot("101-feuille-actions-2")157        el(app, "sheet.ask").tap()158        let field = el(app, "ask.field")159        XCTAssertTrue(field.waitForExistence(timeout: 15))160        XCTAssertTrue(el(app, "ask.route").exists, "the route (local or external) is stated")161        field.tap(); field.typeText("Quel est le mot rare \(word) ?")162        el(app, "ask.send").tap()163        XCTAssertTrue(el(app, "ask.source.1").waitForExistence(timeout: 30), "a numbered passage is cited")164        let answer = el(app, "ask.answer")165        XCTAssertTrue(answer.waitForExistence(timeout: 20))166        poll(20, "the streamed answer is complete") { answer.label.contains("[1]") }167        XCTAssertTrue(answer.label.contains("factice"), "no real model: \(answer.label)")168        shot("102-interroger-document")169        el(app, "ask.model").tap()170        XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Créé par Alibaba")).firstMatch.waitForExistence(timeout: 5), "the model's creator is named apart from the route")171        XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH[c] %@", "Servi par")).firstMatch.exists)172        shot("103-choix-modele")173        app.buttons["Fermer"].firstMatch.tap()174        Thread.sleep(forTimeInterval: 0.8)175        closeSheet(app)176177        // 3. versions: timeline, comparison of the two texts178        el(app, "more.compte rendu.txt").tap()179        el(app, "sheet.versions").tap()180        XCTAssertTrue(el(app, "version.2").waitForExistence(timeout: 15))181        shot("104-versions")182        app.buttons["version.compare.2"].firstMatch.tap()183        let summary = el(app, "diff.summary")184        XCTAssertTrue(summary.waitForExistence(timeout: 20))185        XCTAssertTrue(summary.label.contains("2") && summary.label.lowercased().contains("ajout"), summary.label)186        shot("105-comparaison-texte")187        app.buttons["Fermer"].firstMatch.tap()188        Thread.sleep(forTimeInterval: 0.8)189        closeSheet(app)190191        // 4. tags192        el(app, "more.compte rendu.txt").tap()193        el(app, "sheet.tags").tap()194        let tagName = el(app, "tag.newName")195        XCTAssertTrue(tagName.waitForExistence(timeout: 15))196        tagName.tap(); tagName.typeText("Urgent \(word.suffix(4))")197        el(app, "tag.create").tap()198        XCTAssertTrue(el(app, "tag.Urgent \(word.suffix(4))").waitForExistence(timeout: 15))199        shot("106-etiquettes")200        poll(15, "tag applied on the server") { (((try? self.apiSync("/api/v1/files/\(fileID)"))?["file"] as? [String: Any])?["tagIds"] as? [String])?.count == 1 }201        el(app, "tags.done").tap()202203        // 5. collections, storage, activity204        openSection(app, "collections")205        XCTAssertTrue(el(app, "collection.Textes \(word.suffix(5))").waitForExistence(timeout: 15))206        shot("107-collections")207        el(app, "collection.Textes \(word.suffix(5))").tap()208        XCTAssertTrue(item(app, "compte rendu.txt").waitForExistence(timeout: 15), "the rule gathers the file")209        shot("108-collection-resultats")210        openSection(app, "storage")211        XCTAssertTrue(el(app, "storage.used").waitForExistence(timeout: 15))212        XCTAssertTrue(el(app, "storage.kind.text").waitForExistence(timeout: 5))213        shot("109-stockage")214        openSection(app, "activity")215        XCTAssertTrue(el(app, "activity.file.version_added").waitForExistence(timeout: 15), "real audit events")216        shot("110-activite")217    }218219    func testMembersSharedWithMeDevicesAndQRCode() throws {220        let meta = try api("GET", "/api/v1/meta")221        try XCTSkipUnless((meta["api"] as? Int) == 2 && !tokenC.isEmpty, "needs the 2.0 backend and the third account")222        // someone else (account C) shares two folders with this account: one to read, one to drop into223        let c = ["Authorization": "Bearer \(tokenC)"]224        let suffix = UUID().uuidString.prefix(5)225        let readID = try XCTUnwrap(api("POST", "/api/v1/folders", json: ["parentId": "root", "name": "Lecture \(suffix)", "onConflict": "rename"], headers: c)["id"] as? String)226        let dropID = try XCTUnwrap(api("POST", "/api/v1/folders", json: ["parentId": "root", "name": "Dépôt \(suffix)", "onConflict": "rename"], headers: c)["id"] as? String)227        _ = try upload("à lire.txt", "pour le lecteur", folder: readID, as: tokenC)228        try api("POST", "/api/v1/folders/\(readID)/members", json: ["email": emailB, "role": "viewer", "workspaceName": "Équipe \(suffix)"], headers: c)229        try api("POST", "/api/v1/folders/\(dropID)/members", json: ["email": emailB, "role": "uploader"], headers: c)230        let mine = "À moi \(suffix)"231        let mineID = try seedFolder(mine)232        _ = try seedFile("partagé.txt", "contenu", in: mineID)233234        let app = launch(signedIn: true)235        XCTAssertTrue(item(app, mine).waitForExistence(timeout: 30))236237        // member side: a viewer reads…238        openSection(app, "sharedWithMe")239        let viewer = el(app, "grant.Équipe \(suffix)")240        XCTAssertTrue(viewer.waitForExistence(timeout: 15))241        shot("120-partages-avec-moi")242        viewer.tap()243        XCTAssertTrue(el(app, "shared.file.à lire.txt").waitForExistence(timeout: 15))244        XCTAssertFalse(el(app, "shared.add").exists, "a viewer has no way to add anything")245        shot("121-partage-lecture")246        app.navigationBars.buttons.firstMatch.tap()247        // … an uploader only sees a place to drop files248        let uploader = el(app, "grant.Dépôt \(suffix)")249        XCTAssertTrue(uploader.waitForExistence(timeout: 10))250        uploader.tap()251        XCTAssertTrue(el(app, "shared.drop").waitForExistence(timeout: 10))252        XCTAssertFalse(app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH %@", "shared.file.")).firstMatch.exists, "an uploader sees no listing")253        shot("122-partage-depot")254255        // owner side: members and roles of one of my folders256        if isPad { openSection(app, "drive") } else { app.tabBars.buttons["Mon Drive"].tap() }257        XCTAssertTrue(item(app, mine).waitForExistence(timeout: 10))258        el(app, "more.\(mine)").tap()259        XCTAssertTrue(el(app, "sheet.members").waitForExistence(timeout: 5))260        el(app, "sheet.members").tap()261        let email = el(app, "members.email")262        XCTAssertTrue(email.waitForExistence(timeout: 15))263        email.tap(); email.typeText(emailC)264        el(app, "members.add").tap()265        if !el(app, "member.Test C").waitForExistence(timeout: 15) { shot("123x-membre-absent") }266        XCTAssertTrue(el(app, "member.Test C").exists)267        // an unknown address is refused without revealing anything (the field was emptied by the successful addition)268        email.tap(); email.typeText("personne-\(suffix)@example.test")269        el(app, "members.add").tap()270        if !el(app, "members.notFound").waitForExistence(timeout: 8) { app.swipeUp() } // on iPad the line may sit under the keyboard, not yet rendered271        XCTAssertTrue(el(app, "members.notFound").waitForExistence(timeout: 8))272        shot("123-membres")273        poll(10, "grant on the server") { (((try? self.apiSync("/api/v1/folders/\(mineID)/members"))?["members"] as? [[String: Any]])?.count ?? 0) == 1 }274        closeSheet(app)275276        // a share link and its QR code, drawn on the device277        item(app, mine).tap()278        XCTAssertTrue(item(app, "partagé.txt").waitForExistence(timeout: 10))279        el(app, "more.partagé.txt").tap()280        el(app, "sheet.share").tap()281        let create = el(app, "share.create")282        if !create.waitForExistence(timeout: 8) { app.swipeUp() }283        XCTAssertTrue(create.waitForExistence(timeout: 10))284        if !create.isHittable { app.swipeUp() }285        create.tap()286        XCTAssertTrue(el(app, "share.url").waitForExistence(timeout: 15))287        let qr = el(app, "share.url.qrToggle")288        if !qr.isHittable { app.swipeUp() }289        qr.tap()290        if !el(app, "share.qr").waitForExistence(timeout: 5) { app.swipeUp() }291        XCTAssertTrue(el(app, "share.qr").waitForExistence(timeout: 5))292        shot("124-code-qr")293        app.terminate()294295        // devices dashboard296        let again = launch(signedIn: true, reset: false)297        XCTAssertTrue(item(again, mine).waitForExistence(timeout: 30))298        openSection(again, "settings")299        let devices = el(again, "settings.devices")300        for _ in 0..<4 where !devices.isHittable { again.swipeUp() }301        devices.tap()302        let current = el(again, "device.current")303        XCTAssertTrue(current.waitForExistence(timeout: 15))304        XCTAssertTrue(current.label.contains("SP Drive 2.0.0"), "platform and app version come from the client header: \(current.label)")305        shot("125-appareils")306    }307308    /// Against a server that announces nothing (1.0), no 2.0 control may be shown.309    func testA1ServerShowsNoNextControl() throws {310        let folderName = "Un \(UUID().uuidString.prefix(5))"311        let folderID = try seedFolder(folderName)312        _ = try seedFile("simple.txt", "texte", in: folderID)313        let app = launch(signedIn: true, environment: ["SPDRIVE_FORCE_V1": "1"])314        XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))315        if isPad {316            XCTAssertTrue(el(app, "sidebar.settings").waitForExistence(timeout: 5))317            for s in ["ask", "collections", "sharedWithMe", "activity", "storage"] { XCTAssertFalse(el(app, "sidebar.\(s)").exists, s) }318        } else {319            app.tabBars.buttons["Plus"].tap()320            XCTAssertTrue(el(app, "more.settings").waitForExistence(timeout: 5))321            for s in ["ask", "collections", "sharedWithMe", "activity", "storage"] { XCTAssertFalse(el(app, "more.\(s)").exists, s) }322            shot("130-serveur-1-0-plus")323            app.tabBars.buttons["Mon Drive"].tap()324        }325        item(app, folderName).tap()326        XCTAssertTrue(item(app, "simple.txt").waitForExistence(timeout: 10))327        el(app, "more.simple.txt").tap()328        XCTAssertTrue(el(app, "sheet.details").waitForExistence(timeout: 5))329        for row in ["ask", "versions", "tags", "activity", "members"] { XCTAssertFalse(el(app, "sheet.\(row)").exists, row) }330        shot("131-serveur-1-0-feuille")331    }332}333
Files main
Menu

Theme