Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Drive pour iPhone et iPad9// File : UITests/NextUITests.swift10// Description : Interface tests of SP Drive 2.0 on the simulator, against11// the disposable backend: the contextual bottom sheet, the12// scanner review (fed with generated pages: the simulator13// has no camera), the transfer pill and « Wi-Fi only », the14// conflict sheet on a real conflict, PDF annotation saved as15// a new version, and the appearance matrix (dark mode, large16// text, English).17// Module : UITests18// Repository : https://git.spboucher.ai/sp-drive-ios19// Created : 2026-11-1920// Last Modified : 2026-11-1921//22// =============================================================================23// AUTHOR & PROFESSIONAL AFFILIATION24// =============================================================================25//26// Author : Simon-Pierre Boucher27// Position : Professor of Finance28// Institution : Université du Québec en Outaouais (UQO)29// Department : Département des sciences administratives30// Organization : SP Boucher31//32// Website : https://spboucher.ai33// Git : https://git.spboucher.ai34//35// =============================================================================36// OFFICIAL CONTACT DIRECTORY37// =============================================================================38//39// General : info@spboucher.ai40// Professional : contact@spboucher.ai41// Direct : simon@spboucher.ai42// Research : research@spboucher.ai43// Development : dev@spboucher.ai44// Support : support@spboucher.ai45// Security/Admin : admin@spboucher.ai46// Notifications : notifications@spboucher.ai47//48// Preferred Contact: support@spboucher.ai49//50// =============================================================================51// COPYRIGHT & INTELLECTUAL PROPERTY52// =============================================================================53//54// Copyright (c) 202655// Simon-Pierre Boucher56//57// All rights reserved where applicable.58//59// This file is governed by the applicable project license,60// copyright notices, institutional agreements and relevant law.61//62// Unless expressly authorized by the applicable license or63// rights holder, copying, redistribution, sublicensing,64// publication and commercial exploitation are not permitted.65//66// Existing third-party rights and notices remain unaffected.67//68// =============================================================================69// CONFIDENTIALITY & SECURITY70// =============================================================================71//72// Classification : Public73// Distribution : Public repository; use is governed by the project license74// Security Contact : admin@spboucher.ai75//76// Access to this source does not independently grant permission77// to redistribute or disclose confidential materials.78//79// Do not embed credentials, private keys, access tokens,80// certificates or confidential personal information.81//82// =============================================================================83// LICENSE & MAINTENANCE84// =============================================================================85//86// License : None specified (no license file in this repository)87// Maintainer : Simon-Pierre Boucher88// Technical Contact: dev@spboucher.ai89//90// =============================================================================91// END OF SP BOUCHER SOURCE HEADER92// =============================================================================9394import XCTest9596final class NextUITests: DriveUITestCase {97 private func el(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }9899 private func poll(_ timeout: TimeInterval = 30, _ what: String, _ condition: @escaping () -> Bool) {100 let deadline = Date().addingTimeInterval(timeout)101 while Date() < deadline { if condition() { return }; Thread.sleep(forTimeInterval: 0.5) }102 XCTFail("timed out: \(what)")103 }104105 private func children(_ folderID: String) -> (files: [[String: Any]], folders: [[String: Any]]) {106 let r = (try? apiSync("/api/v1/folders/\(folderID)")) ?? [:]107 return (r["files"] as? [[String: Any]] ?? [], r["folders"] as? [[String: Any]] ?? [])108 }109110 /// Bottom sheet, scanner review, transfer pill, « Wi-Fi only » and its one-time exemption — on a (simulated) cellular path.111 func testSheetScanPillAndWiFiOnly() throws {112 let folderName = "Next \(UUID().uuidString.prefix(6))"113 let folderID = try seedFolder(folderName)114 let fileID = try seedFile("notes.txt", "Bonjour.", in: folderID)115 let app = launch(signedIn: true, environment: ["SPDRIVE_FAKE_CONDITIONS": "cellular"], arguments: ["-transfers.cellular", "NO"])116 XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))117 shot("50-mon-drive-v2")118 item(app, folderName).tap()119 XCTAssertTrue(item(app, "notes.txt").waitForExistence(timeout: 10))120121 // the contextual bottom sheet: state, quick actions122 el(app, "more.notes.txt").tap()123 XCTAssertTrue(el(app, "sheet.star").waitForExistence(timeout: 5))124 XCTAssertTrue(el(app, "sheet.state").exists)125 shot("51-feuille-actions")126 el(app, "sheet.star").tap()127 // metadata is light: it travels even with « Wi-Fi only » on a cellular path128 poll(20, "favourite on the server") { ((try? self.apiSync("/api/v1/files/\(fileID)"))?["file"] as? [String: Any])?["starred"] as? Bool == true }129 app.swipeDown(velocity: .fast)130 if el(app, "sheet.star").exists { el(app, "sheet.star").coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: -3)).tap() }131132 // the scanner: pages → review → searchable PDF queued for upload133 app.buttons["add"].tap()134 app.buttons["Numériser un document"].tap()135 XCTAssertTrue(el(app, "scan.save").waitForExistence(timeout: 10))136 XCTAssertTrue(el(app, "scan.ocr").exists)137 shot("52-numerisation")138 el(app, "scan.save").tap()139 let scanned = app.descendants(matching: .any).matching(NSPredicate(format: "identifier CONTAINS %@", "risation 20")).firstMatch140 XCTAssertTrue(scanned.waitForExistence(timeout: 60), "the scan is in the folder at once, before it is sent")141142 // « Wi-Fi only » on cellular: the upload waits, and the pill says why143 let pill = el(app, "transferPill")144 if !pill.waitForExistence(timeout: 15) { shot("53x-pastille-absente") }145 XCTAssertTrue(pill.exists)146 XCTAssertTrue((pill.value as? String ?? pill.label).contains("Wi-Fi"), "pill: \(pill.value ?? "") / \(pill.label)")147 shot("53-pastille-wifi")148 Thread.sleep(forTimeInterval: 2)149 XCTAssertTrue(children(folderID).files.allSatisfy { ($0["name"] as? String)?.contains("risation 20") != true }, "nothing was sent on cellular")150151 // the pill expands into the transfer centre; « use cellular data this once » lets the file through152 pill.tap()153 XCTAssertTrue(el(app, "transfers.holdBanner").waitForExistence(timeout: 8))154 shot("54-centre-transferts")155 el(app, "transfers.allowCellular").tap()156 poll(40, "scan uploaded after the exemption") { self.children(folderID).files.contains { ($0["name"] as? String)?.contains("risation 20") == true && ($0["size"] as? Int ?? 0) > 1000 } }157 shot("55-transfert-termine")158 }159160 /// A real conflict, staged with the API, then resolved in the side-by-side sheet (« keep both »).161 func testConflictSheetOnARealConflict() throws {162 let folderName = "Conflit \(UUID().uuidString.prefix(6))"163 let folderID = try seedFolder(folderName)164 let fileID = try seedFile("contrat.txt", "version de départ", in: folderID)165 // the app does not look at the change feed by itself during this test: the other « device » is the test runner166 let app = launch(signedIn: true, environment: ["SPDRIVE_POLL_SECONDS": "900", "SPDRIVE_NO_EVENTS": "1"])167 XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))168 item(app, folderName).tap()169 XCTAssertTrue(item(app, "contrat.txt").waitForExistence(timeout: 10))170 el(app, "more.contrat.txt").tap()171 XCTAssertTrue(el(app, "sheet.editText").waitForExistence(timeout: 5))172 el(app, "sheet.editText").tap()173 let editor = el(app, "textEditor")174 XCTAssertTrue(editor.waitForExistence(timeout: 20))175176 // meanwhile, elsewhere: a new version of the same file177 let other = Data("version du serveur, écrite ailleurs".utf8)178 let up = try XCTUnwrap(api("POST", "/api/v1/uploads", json: ["folderId": folderID, "name": "contrat.txt", "size": other.count, "fileId": fileID, "onConflict": "version"])["id"] as? String)179 try api("PATCH", "/api/v1/uploads/\(up)?offset=0", raw: other)180 try api("POST", "/api/v1/uploads/\(up)/complete")181182 Thread.sleep(forTimeInterval: 1.5) // the sheet finishes arriving183 editor.typeText("ma modification ")184 app.buttons["Enregistrer"].tap()185 // the upload names the version it started from: the server refuses, nothing is overwritten186 let file = item(app, "contrat.txt")187 XCTAssertTrue(file.waitForExistence(timeout: 10))188 poll(30, "the item shows its conflict") { (file.value as? String)?.contains("Conflit") == true }189 shot("60-element-en-conflit")190 XCTAssertEqual(((try apiSync("/api/v1/files/\(fileID)"))["file"] as? [String: Any])?["size"] as? Int, other.count, "the Drive still holds the other version")191192 // opening a file in conflict shows the choice193 file.tap()194 XCTAssertTrue(el(app, "conflict.keepBoth").waitForExistence(timeout: 15))195 XCTAssertTrue(el(app, "conflict.local").exists && el(app, "conflict.server").exists)196 let facts = el(app, "conflict.server.facts")197 XCTAssertTrue(facts.label.contains("Version 2"), facts.label)198 shot("61-feuille-conflit")199 el(app, "conflict.keepBoth").tap()200 poll(40, "both versions on the Drive") {201 let files = self.children(folderID).files.compactMap { $0["name"] as? String }202 return files.count == 2 && files.contains("contrat.txt") && files.contains { $0.contains("(conflit") }203 }204 XCTAssertTrue(app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH %@", "item.contrat (conflit")).firstMatch.waitForExistence(timeout: 20))205 shot("62-conflit-resolu")206 }207208 /// PDF annotation: draw on the page, save, and the Drive holds a second version.209 func testPDFAnnotationSavesANewVersion() throws {210 let folderName = "Annot \(UUID().uuidString.prefix(6))"211 let folderID = try seedFolder(folderName)212 let app = launch(signedIn: true)213 XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))214 item(app, folderName).tap()215 // a PDF made by the app's own scanner pipeline (generated pages), sent for real first216 app.buttons["add"].firstMatch.waitForExistence(timeout: 5) ? app.buttons["add"].firstMatch.tap() : el(app, "empty.scan").tap()217 if app.buttons["Numériser un document"].waitForExistence(timeout: 3) { app.buttons["Numériser un document"].tap() }218 XCTAssertTrue(el(app, "scan.save").waitForExistence(timeout: 10))219 el(app, "scan.save").tap()220 var pdfID = ""221 poll(60, "scan uploaded") {222 guard let f = self.children(folderID).files.first(where: { ($0["name"] as? String)?.hasSuffix(".pdf") == true }) else { return false }223 pdfID = f["id"] as? String ?? ""224 return !pdfID.isEmpty225 }226 let name = try XCTUnwrap(children(folderID).files.first?["name"] as? String)227 Thread.sleep(forTimeInterval: 2) // the provisional item takes its definitive identifier228 el(app, "more.\(name)").tap()229 XCTAssertTrue(el(app, "sheet.annotate").waitForExistence(timeout: 8))230 el(app, "sheet.annotate").tap()231 let save = app.buttons["annotate.save"].firstMatch232 XCTAssertTrue(save.waitForExistence(timeout: 20))233 XCTAssertFalse(save.isEnabled, "nothing drawn yet: nothing to save")234 Thread.sleep(forTimeInterval: 1.5)235 // no Pencil in the simulator: the finger draws (the default on iPhone; switched on here on iPad)236 if isPad, (el(app, "annotate.finger").value as? String) != "1" { el(app, "annotate.finger").tap() }237 // the PencilKit canvases are not exposed to the accessibility tree: the stroke is drawn by screen position, over the page238 let window = app.windows.firstMatch239 window.coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.42)).press(forDuration: 0.15, thenDragTo: window.coordinate(withNormalizedOffset: CGVector(dx: 0.75, dy: 0.5)))240 poll(10, "strokes on the page enable saving") { save.isEnabled }241 shot("70-annotation-pdf")242 save.tap()243 poll(60, "second version on the Drive") { ((try? self.apiSync("/api/v1/files/\(pdfID)"))?["versions"] as? [[String: Any]])?.count == 2 }244 shot("71-annotation-envoyee")245 }246247 /// Dark mode, the largest standard text size (XXXL), an accessibility size, and English: the same screens, captured.248 func testAppearanceMatrix() throws {249 let folderName = "Documents de travail"250 let folderID = try seedFolder(folderName)251 _ = try seedFolder("Photos de chantier 2026")252 _ = try seedFile("Rapport annuel d’activité — version finale relue.txt", "Texte du rapport.", in: folderID)253 _ = try seedFile("Budget prévisionnel.csv", "a,b\n1,2\n", in: folderID)254 _ = try seedFile("Notes de réunion.md", "# Notes\n", in: folderID)255256 func capture(_ tag: String, dark: Bool, size: String?, language: String = "fr") {257 let args = size.map { ["-UIPreferredContentSizeCategoryName", $0] } ?? []258 let app = launch(signedIn: true, environment: ["SPDRIVE_FORCE_SCHEME": dark ? "dark" : "light"], arguments: args, language: language)259 XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))260 shot("80-\(tag)-racine")261 item(app, folderName).tap()262 let long = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH %@", "item.Rapport annuel")).firstMatch263 XCTAssertTrue(long.waitForExistence(timeout: 10))264 shot("81-\(tag)-liste")265 let options = app.buttons["options"].firstMatch266 XCTAssertTrue(options.waitForExistence(timeout: 5))267 options.tap()268 let gridButton = app.buttons[language == "fr" ? "Grille" : "Grid"].firstMatch269 XCTAssertTrue(gridButton.waitForExistence(timeout: 5))270 gridButton.tap()271 XCTAssertTrue(long.waitForExistence(timeout: 5))272 shot("82-\(tag)-grille")273 // back to the list: the layout is a persistent preference and the other tests expect rows274 options.tap()275 let listButton = app.buttons[language == "fr" ? "Liste" : "List"].firstMatch276 XCTAssertTrue(listButton.waitForExistence(timeout: 5))277 listButton.tap()278 let budget = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH %@", "item.Budget")).firstMatch279 XCTAssertTrue(budget.waitForExistence(timeout: 5))280 budget.press(forDuration: 1.0)281 shot("83-\(tag)-menu")282 app.terminate()283 }284 capture("clair", dark: false, size: nil)285 capture("sombre", dark: true, size: nil)286 capture("xxxl", dark: false, size: "UICTContentSizeCategoryXXXL")287 capture("ax3-sombre", dark: true, size: "UICTContentSizeCategoryAccessibilityXL")288 capture("anglais", dark: false, size: nil, language: "en")289 }290291 /// iPad: the inspector column next to the browser, the keyboard-shortcut sheet, and the transfer section in the sidebar.292 func testPadInspectorAndShortcuts() throws {293 try XCTSkipUnless(isPad, "iPad layout")294 XCUIDevice.shared.orientation = .landscapeLeft // wide enough for the three columns side by side295 defer { XCUIDevice.shared.orientation = .portrait }296 let folderName = "Tablette \(UUID().uuidString.prefix(6))"297 let folderID = try seedFolder(folderName)298 _ = try seedFile("plan.txt", "Plan de travail.", in: folderID)299 let app = launch(signedIn: true)300 XCTAssertTrue(item(app, folderName).waitForExistence(timeout: 30))301 shot("90-ipad-colonnes")302 item(app, folderName).tap()303 XCTAssertTrue(item(app, "plan.txt").waitForExistence(timeout: 10))304 el(app, "more.plan.txt").tap()305 XCTAssertTrue(el(app, "sheet.details").waitForExistence(timeout: 5))306 shot("91-ipad-feuille-actions")307 el(app, "sheet.details").tap()308 XCTAssertTrue(el(app, "inspector.details").waitForExistence(timeout: 8), "the inspector column opens instead of a sheet")309 XCTAssertTrue(item(app, "plan.txt").exists, "the browser stays in view next to the inspector")310 shot("92-ipad-inspecteur")311 // keyboard: ⌘2 switches to the grid, ⌘1 back to the list, ⌘/ lists the shortcuts312 app.typeKey("2", modifierFlags: .command)313 Thread.sleep(forTimeInterval: 1)314 XCTAssertFalse(el(app, "more.plan.txt").exists, "⌘2: grid layout (cards have no « more » button)")315 shot("94-ipad-grille")316 app.typeKey("1", modifierFlags: .command)317 XCTAssertTrue(el(app, "more.plan.txt").waitForExistence(timeout: 5), "⌘1: back to the list")318 app.typeKey("/", modifierFlags: .command)319 XCTAssertTrue(app.navigationBars["Raccourcis clavier"].waitForExistence(timeout: 5), "⌘/: the list of shortcuts")320 shot("93-ipad-raccourcis")321 }322}323