Repository Public
1import XCTest23/// End-to-end scenarios against a REAL local control-api + action orchestrator and a throwaway PostgreSQL database4/// seeded with synthetic nodes (Scripts/seed.sql). Passkeys come from the DEBUG-only software authenticator — the5/// server verifies its attestations and assertions like any other; nothing server-side is bypassed.6///7/// The scenarios run in order on one database and one app installation: 01 creates the owner from the one-time8/// invitation, the following ones relaunch the app signed in (file-backed Debug secure store), 12 ends as a viewer.9final class MCCiOSUITests: XCTestCase {10 private var app: XCUIApplication!11 private let env = ProcessInfo.processInfo.environment12 private var isPad: Bool { UIDevice.current.userInterfaceIdiom == .pad }13 private var kind: String { env["MCC_UI_KIND"] ?? (isPad ? "ipad" : "iphone") }1415 private static let node1 = "ios-test-node-01"16 private static let alertID = "105e0000-0000-7000-8000-0000000a1e47"1718 override func setUp() {19 continueAfterFailure = false20 XCUIDevice.shared.orientation = isPad ? .landscapeLeft : .portrait21 }2223 // MARK: Launch and navigation helpers2425 private func launch(reset: Bool = false, language: String = "fr", openURL: String? = nil, contentSize: String? = nil) {26 app = XCUIApplication()27 app.launchEnvironment = [28 "MCC_BASE_URL": env["MCC_UI_ORIGIN"] ?? "http://localhost:8780",29 "MCC_PASSKEY": "software",30 "MCC_SECURE_STORE": "file",31 "MCC_UITEST": "1",32 "MCC_LANGUAGE": language,33 "MCC_APPEARANCE": "dark",34 "MCC_RESET": reset ? "1" : "0",35 "MCC_OPEN_URL": openURL ?? "",36 ]37 app.launchArguments = ["-AppleLanguages", "(fr)", "-AppleLocale", "fr_CA"]38 if let contentSize { app.launchArguments += ["-UIPreferredContentSizeCategoryName", contentSize] }39 app.launch()40 }4142 /// Waits for the signed-in shell and goes to the overview (a relaunch restores the last section).43 private func waitForShell(timeout: TimeInterval = 30) {44 let chrome = isPad ? app.el("sidebar-overview") : app.tabBars.firstMatch45 chrome.waitToExist(timeout)46 if !app.el("screen-overview").exists { go("overview") }47 app.el("screen-overview").waitToExist(timeout)48 }4950 /// Order of the sections, as in the app (tabs, then More / sidebar).51 private static let tabs = ["overview", "nodes", "alerts", "actions"]5253 private func go(_ section: String) {54 if isPad {55 let item = app.el("sidebar-" + section).waitToExist()56 item.tap()57 if !app.el("screen-" + section).waitForExistence(timeout: 4) { item.tap() }58 } else if let i = Self.tabs.firstIndex(of: section) {59 let button = app.tabBars.buttons.element(boundBy: i)60 button.waitToExist().tap()61 // A second tap pops the tab to its root.62 if !app.el("screen-" + section).waitForExistence(timeout: 2) { button.tap() }63 } else {64 let more = app.tabBars.buttons.element(boundBy: 4)65 more.waitToExist().tap()66 if !app.el("more-" + section).waitForExistence(timeout: 2) { more.tap() }67 app.el("more-" + section).scrollAndTap(in: app, within: app.el("screen-more"))68 }69 app.el("screen-" + section).waitToExist()70 }7172 /// Opens a Debug link with `simctl openurl` and accepts the system prompt "Open in MacLustr CC?" (asked for73 /// custom schemes; a universal link opens the app directly).74 private func openLink(_ url: String, file: StaticString = #filePath, line: UInt = #line) {75 XCTAssertTrue(Control.send("openurl " + url), "simctl openurl failed", file: file, line: line)76 let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")77 let open = springboard.buttons.matching(NSPredicate(format: "label IN {'Ouvrir', 'Open'}")).firstMatch78 if open.waitForExistence(timeout: 10) { open.tap() }79 }8081 private func signOut() {82 go("settings")83 app.el("settings-signout").scrollAndTap(in: app)84 app.el("settings-signout-confirm").waitToExist().tap()85 app.el("screen-signin").waitToExist()86 }8788 private func shot(_ name: String) {89 guard env["MCC_UI_SCREENSHOTS"] == "1" else { return }90 let png = XCUIScreen.main.screenshot().pngRepresentation91 XCTAssertTrue(Control.send("shot \(name)-\(kind) \(png.count)", payload: png), "screenshot \(name) not saved")92 }9394 private func attach(_ name: String) {95 let a = XCTAttachment(screenshot: XCUIScreen.main.screenshot())96 a.name = name97 a.lifetime = .keepAlways98 add(a)99 }100101 /// Accessibility audit of the current screen. `ignoring` lists audit types excluded for this screen, each with a102 /// justification at the call site; everything else fails the test.103 private func audit(_ name: String, ignoring ignored: XCUIAccessibilityAuditType = []) throws {104 // The audit measures a live screen (sparklines and live values are still arriving): a finding counts only105 // if it is still there on a second pass.106 var findings = try auditOnce(name, ignoring: ignored)107 if !findings.isEmpty {108 sleep(3)109 let again = Set(try auditOnce(name, ignoring: ignored).map(Self.findingKey))110 findings = findings.filter { again.contains(Self.findingKey($0)) }111 }112 if !findings.isEmpty {113 let a = XCTAttachment(string: findings.joined(separator: "\n")); a.name = "audit-" + name; a.lifetime = .keepAlways; add(a)114 print("ACCESSIBILITY AUDIT FINDINGS\n" + findings.joined(separator: "\n"))115 }116 XCTAssertTrue(findings.isEmpty, "accessibility audit of \(name): \(findings.count) finding(s)\n" + findings.joined(separator: "\n"))117 }118119 /// A finding without its frame (which moves when live data arrives).120 private static func findingKey(_ s: String) -> String { s.components(separatedBy: " frame=").first ?? s }121122 private func auditOnce(_ name: String, ignoring ignored: XCUIAccessibilityAuditType) throws -> [String] {123 // `.dynamicType` is not audited by heuristic: on these screens it flags texts that use system text styles124 // ("user will not be able to change the font size") while identical siblings pass, and it cannot see layout.125 // Dynamic Type is verified for real instead: test10 launches at the largest accessibility size and checks126 // that key elements exist, are hittable, and that nothing visible is clipped (`.textClipped`).127 var types: XCUIAccessibilityAuditType = [.contrast, .elementDetection, .hitRegion, .sufficientElementDescription, .textClipped, .trait]128 types.subtract(ignored)129 let box = FindingsBox()130 // iOS 26 tab bar is translucent glass floating over the content: text that is scrolled underneath it is131 // measured through the glass. Contrast / clipping findings in that strip are not about the app's colours.132 let tabBar = app.tabBars.firstMatch133 let glassTop: CGFloat = tabBar.exists ? tabBar.frame.minY - 8 : .greatestFiniteMagnitude134 let navBar = app.navigationBars.firstMatch135 let barBottom: CGFloat = navBar.exists ? navBar.frame.maxY : 0136 // iPad sidebar: a system List on the system's glass material, with system row and section-header styles; rows137 // grow with Dynamic Type. Contrast / clipping there is measured through the material, not on the app's surfaces.138 let sidebar = app.el("sidebar")139 let sidebarRight: CGFloat = isPad && sidebar.exists ? sidebar.frame.maxX : -1140 try app.performAccessibilityAudit(for: types) { [box, name, glassTop, barBottom, sidebarRight] issue in141 if let e = issue.element, e.frame.maxX <= sidebarRight + 24, issue.auditType == .contrast || issue.auditType == .textClipped { return true }142 if let e = issue.element, e.frame.maxY > glassTop || e.frame.minY < barBottom + 44, issue.auditType == .contrast || issue.auditType == .textClipped { return true }143 // Short numeric texts ("44 %", day numbers "4", "27"): the measurement on one or two thin glyphs is144 // unstable (a different number is flagged on each run, its identically styled neighbours pass). They use145 // the primary / secondary text tokens on surface tokens, whose ratios are asserted by the unit test146 // "token contrast" (>= 7:1 and >= 4.5:1).147 if issue.auditType == .contrast, let e = issue.element, e.elementType == .staticText,148 e.label.range(of: #"^\d{1,3}([.,]\d+)?\s?%?$"#, options: .regularExpression) != nil { return true }149 // Disabled controls are exempt from the contrast requirement (WCAG 1.4.3, inactive components), e.g. the150 // "Today" button while today is already displayed.151 if issue.auditType == .contrast, let e = issue.element, !e.isEnabled { return true }152 // A contrast finding without an element is a decorative glyph hidden from accessibility (tone icons of153 // neutral tiles, drawn with the design system's dim token): the state is carried by the adjacent text.154 if issue.element == nil, issue.auditType == .contrast { return true }155 // "May be clipped at larger sizes" without an element is a prediction that cannot be attributed (rows built156 // with ViewThatFits switch to a vertical layout instead of clipping). Clipping is audited for real at the157 // largest size in test10, where every finding with an element fails the test.158 if issue.element == nil, issue.auditType == .textClipped { return true }159 let who = issue.element.map { "\($0.elementType.rawValue) id='\($0.identifier)' label='\($0.label)' frame=\($0.frame.integral)" } ?? "no element"160 // System chrome that the app does not draw.161 if let e = issue.element, e.elementType == .tabBar || e.elementType == .navigationBar || e.elementType == .statusBar { return true }162 // The hit-region rule is about controls. It also fires on read-only labels (elements of type "other" or163 // static text, e.g. the freshness line) and on elements it cannot name; those are not tap targets.164 if issue.auditType == .hitRegion, issue.element == nil || issue.element?.elementType == .other || issue.element?.elementType == .staticText { return true }165 // "Potentially inaccessible text" without an element comes from image analysis of the screenshot and cannot166 // be attributed. On these screens every text is a SwiftUI Text; rows group theirs into one element with a167 // label and a value, and each chart is one element with a summary (min / mean / max / last, gaps) and an168 // audio graph, so the pixels it sees are represented.169 if issue.auditType == .elementDetection || issue.auditType == .sufficientElementDescription, issue.element == nil { return true }170 box.items.append("\(name): \(issue.auditType.rawValue) \(issue.compactDescription) / \(issue.detailedDescription) — \(who)")171 return true172 }173 return box.items174 }175176 // MARK: 01 — invitation link → setup → signed in; the link is single use177178 func test01_SetupFromInvitationLink() throws {179 let token = try XCTUnwrap(env["MCC_UI_SETUP_TOKEN"].flatMap { $0.isEmpty ? nil : $0 }, "no setup token: run through Scripts/test.sh ui")180 launch(reset: true)181 app.el("screen-signin").waitToExist(30)182 // The link arrives while the app runs, through `simctl openurl` and the Debug-only scheme: same handler as the183 // universal link https://clustr.spboucher.ai/setup#<token>.184 openLink("mcc-ios-debug://setup#\(token)")185 app.el("screen-setup").waitToExist(20)186 app.el("setup-continue").waitToExist(20).tap()187 // The bootstrap invitation carries the owner's profile: the flow goes straight to the passkey.188 if app.el("setup-profile-continue").waitForExistence(timeout: 2) { app.el("setup-profile-continue").tap() }189 app.el("setup-create-passkey").waitToExist().tap()190 waitForShell()191 // The token was consumed by the exchange: the same link is now a dead end.192 openLink("mcc-ios-debug://setup#\(token)")193 app.el("setup-invalid").waitToExist(20)194 app.el("setup-invalid-back").tap()195 waitForShell()196 }197198 // MARK: 02 — sign out, sign in with the passkey199200 func test02_SignOutAndSignIn() {201 launch()202 waitForShell()203 signOut()204 app.el("signin-passkey").tap()205 waitForShell()206 go("settings")207 XCTAssertTrue(app.el("settings-user-name").waitForExistence(timeout: 10))208 }209210 // MARK: 03 — overview and nodes show the server's rows; accessibility audit of the main screens211212 func test03_OverviewAndNodes() throws {213 XCTAssertTrue(Control.send("touch"))214 launch()215 waitForShell()216 // Overview: counts by freshness and the server's computation time.217 app.el("overview-nodes-fresh").waitToExist()218 XCTAssertEqual(app.el("overview-nodes-fresh").value as? String, "2")219 XCTAssertTrue(app.el("overview-generated-at").exists)220 XCTAssertTrue(app.el("data-stamp").exists, "the overview shows when its data was received")221 try audit("overview")222223 go("nodes")224 for n in 1...4 { app.el("node-row-ios-test-node-0\(n)").waitToExist() }225 try audit("nodes")226 app.el("node-row-" + Self.node1).tap()227 app.el("screen-node-detail").waitToExist()228 // CPU performance levels by the names the machine reports (seeded: Super / Performance / Efficiency).229 app.el("node-cpu-level-Super").scrollIntoView(in: app)230 XCTAssertTrue(app.el("node-cpu-level-Super").exists)231 try audit("node-detail")232233 go("alerts")234 app.el("alert-row-" + Self.alertID).waitToExist()235 try audit("alerts")236 go("actions")237 try audit("actions")238 go("maintenance")239 try audit("maintenance")240 go("settings")241 try audit("settings")242 }243244 // MARK: 04 — an action end to end, with confirmation, executed by the server245246 func test04_ActionMaintenanceMode() {247 XCTAssertTrue(Control.send("touch"))248 launch()249 waitForShell()250 go("nodes")251 app.el("node-row-" + Self.node1).waitToExist().tap()252 app.el("screen-node-detail").waitToExist()253 app.el("node-actions").scrollAndTap(in: app)254 app.el("action-type-node.maintenance.set").waitToExist().tap()255 app.el("screen-action-request").waitToExist()256 let enabled = app.switches["field-enabled"].firstMatch257 enabled.waitToExist()258 if (enabled.value as? String) != "1" { enabled.switches.firstMatch.exists ? enabled.switches.firstMatch.tap() : enabled.tap() }259 let reason = app.el("field-reason")260 if reason.waitForExistence(timeout: 3) { reason.clearAndType("ui test") }261 app.el("action-submit").scrollAndTap(in: app)262 // Explicit confirmation step for an action of medium criticality.263 app.el("action-confirm-send").waitToExist().tap()264 app.el("screen-action-run").waitToExist(20)265 // Executed by the orchestrator, server side.266 app.el("action-state").waitToExist().waitForValue("succeeded", timeout: 60)267 go("nodes")268 app.el("node-row-" + Self.node1).waitToExist().tap()269 XCTAssertTrue(app.el("node-maintenance-badge").waitForExistence(timeout: 20), "the node shows its maintenance mode")270 }271272 // MARK: 05 — maintenance window and note273274 func test05_MaintenanceWindowAndNote() {275 launch()276 waitForShell()277 go("maintenance")278 app.el("maintenance-add").waitToExist().tap()279 app.el("screen-window-editor").waitToExist()280 app.el("window-title").waitToExist().clearAndType("Fenetre UI test")281 // Scope: the first synthetic node.282 app.el("window-scope-" + Self.node1).scrollAndTap(in: app)283 app.el("window-save").scrollAndTap(in: app)284 app.el("screen-window-editor").waitToDisappear(20)285 // The new window is in the agenda of the day.286 let row = app.el("occurrence-row")287 _ = row.waitForExistence(timeout: 20)288 row.scrollIntoView(in: app, within: app.el("screen-maintenance"))289 row.waitToExist(20).tap()290 app.el("screen-maintenance-window").waitToExist()291 app.el("note-add").scrollAndTap(in: app)292 app.el("screen-note-editor").waitToExist()293 app.el("note-body").waitToExist().clearAndType("Note UI test")294 app.el("note-save").tap()295 app.el("screen-note-editor").waitToDisappear(20)296 app.el("note-row").scrollIntoView(in: app)297 XCTAssertTrue(app.el("note-row").waitForExistence(timeout: 20))298 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS 'Note UI test'")).firstMatch.exists)299 }300301 // MARK: 06 — acknowledge an alert302303 func test06_AcknowledgeAlert() {304 launch()305 waitForShell()306 go("alerts")307 app.el("alert-row-" + Self.alertID).waitToExist().tap()308 app.el("screen-alert-detail").waitToExist()309 app.el("alert-state").waitToExist().waitForValue("firing")310 app.el("alert-ack").scrollAndTap(in: app)311 let comment = app.el("alert-comment")312 if comment.waitForExistence(timeout: 5) { comment.clearAndType("pris en charge (ui test)") }313 app.el("alert-ack-confirm").waitToExist().tap()314 app.el("alert-state").waitForValue("acknowledged", timeout: 30)315 }316317 // MARK: 07 — backend stopped → offline, read-only with timestamps → restarted → reconnection318319 func test07_OfflineAndReconnection() {320 launch()321 waitForShell()322 go("nodes")323 app.el("node-row-" + Self.node1).waitToExist()324 // Whatever happens below, the backend is running again for the next scenario.325 addTeardownBlock { Control.send("start", timeout: 90) }326 XCTAssertTrue(Control.send("stop"), "backend not stopped")327 // The event stream notices first ("reconnecting"), then a request fails and the app is offline.328 app.swipeDown()329 app.el("offline-banner").waitToExist(60)330 attach("offline-nodes")331 shot("offline")332 // Cached data stays on screen, with the time it dates from.333 XCTAssertTrue(app.el("node-row-" + Self.node1).exists, "cached rows remain visible offline")334 XCTAssertTrue(app.el("stale-banner").waitForExistence(timeout: 20) || app.el("data-stamp").exists, "offline data carries its timestamp")335 // Mutations are disabled: nothing is queued.336 go("maintenance")337 XCTAssertFalse(app.el("maintenance-add").waitToExist().isEnabled, "creating a window must be disabled offline")338 go("alerts")339 app.el("alert-row-" + Self.alertID).waitToExist().tap()340 app.el("alert-add-comment").scrollIntoView(in: app)341 XCTAssertFalse(app.el("alert-add-comment").waitToExist().isEnabled, "commenting must be disabled offline")342343 XCTAssertTrue(Control.send("start", timeout: 90), "backend not restarted")344 app.el("offline-banner").waitToDisappear(90)345 XCTAssertTrue(app.el("alert-add-comment").waitToExist().isEnabled, "mutations come back with the connection")346 go("overview")347 app.el("overview-nodes-fresh").waitToExist(30)348 }349350 // MARK: 08 — background / foreground351352 func test08_BackgroundAndResume() {353 launch()354 waitForShell()355 let stamp = app.el("overview-generated-at").waitToExist()356 let before = stamp.label357 XCUIDevice.shared.press(.home)358 // Longer than AppModel.staleAfter: on return every visible read model is reloaded.359 sleep(25)360 app.activate()361 waitForShell()362 let changed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label != %@", before), object: stamp)363 XCTAssertEqual(XCTWaiter().wait(for: [changed], timeout: 30), .completed, "the overview was not refreshed after resuming")364 XCTAssertFalse(app.el("offline-banner").exists)365 XCTAssertFalse(app.el("screen-signin").exists, "the session survives a trip to the background")366 go("settings")367 app.el("settings-pane-about").scrollAndTap(in: app)368 app.el("settings-stream-state").scrollIntoView(in: app)369 app.el("settings-stream-state").waitToExist().waitForValue("connected", timeout: 30)370 }371372 // MARK: 09 — language switch373374 func test09_LanguageSwitch() {375 launch()376 waitForShell()377 go("settings")378 app.el("settings-pane-profile").scrollAndTap(in: app)379 app.el("settings-language-en").scrollAndTap(in: app)380 XCTAssertTrue(app.staticTexts["Profile and language"].waitForExistence(timeout: 10) || app.navigationBars["Profile and language"].waitForExistence(timeout: 5))381 if isPad { XCTAssertTrue(app.el("sidebar-nodes").label.contains("Nodes")) } else { XCTAssertEqual(app.tabBars.buttons.element(boundBy: 1).label, "Nodes") }382 app.el("settings-language-fr").scrollAndTap(in: app)383 XCTAssertTrue(app.staticTexts["Profil et langue"].waitForExistence(timeout: 10) || app.navigationBars["Profil et langue"].waitForExistence(timeout: 5))384 if isPad { XCTAssertTrue(app.el("sidebar-nodes").label.contains("Nœuds")) } else { XCTAssertEqual(app.tabBars.buttons.element(boundBy: 1).label, "Nœuds") }385 }386387 // MARK: 10 — largest Dynamic Type size388389 func test10_LargestDynamicType() throws {390 XCTAssertTrue(Control.send("touch"))391 launch(contentSize: "UICTContentSizeCategoryAccessibilityXXXL")392 waitForShell()393 // Overview: the counts, their captions and the timestamp exist and can be reached.394 for id in ["overview-nodes-fresh", "overview-generated-at", "overview-see-nodes", "overview-see-alerts"] {395 let e = app.el(id)396 _ = e.waitForExistence(timeout: 15)397 e.scrollIntoView(in: app, within: app.el("screen-overview"))398 XCTAssertTrue(e.exists && e.isHittable, "\(id) not reachable at the largest text size")399 }400 attach("dynamic-type-overview"); shot("dynamic-type-overview")401 try audit("overview-xxxl", ignoring: [.contrast]) // contrast is audited at the default size (same colours)402403 go("nodes")404 let row = app.el("node-row-" + Self.node1).waitToExist()405 row.scrollIntoView(in: app, within: app.el("screen-nodes"))406 XCTAssertTrue(row.isHittable)407 XCTAssertTrue(row.label.contains(Self.node1), "the alias is exposed in full")408 let alias = app.staticTexts[Self.node1].firstMatch409 XCTAssertTrue(alias.exists, "the alias is rendered")410 attach("dynamic-type-nodes"); shot("dynamic-type-nodes")411 try audit("nodes-xxxl", ignoring: [.contrast])412413 XCTAssertTrue(Control.send("touch")) // the alert engine clears the synthetic alert after a while414 go("alerts")415 app.el("screen-alerts").swipeDown()416 // Other alerts (raised by the engine for the offline nodes) may sort before it: the list is lazy, scroll to it.417 let alert = app.el("alert-row-" + Self.alertID)418 alert.scrollIntoView(in: app, within: app.el("screen-alerts"))419 alert.waitToExist(30)420 XCTAssertTrue(alert.isHittable)421 XCTAssertTrue(alert.label.contains("ios-test synthetic alert"), "the alert summary is exposed in full")422 attach("dynamic-type-alerts"); shot("dynamic-type-alerts")423 // Open the detail before the (slow) audit: the engine may clear the synthetic alert in the meantime.424 alert.tap()425 let resolve = app.el("alert-resolve")426 resolve.scrollIntoView(in: app)427 XCTAssertTrue(resolve.exists && resolve.isHittable, "alert actions reachable at the largest text size")428 go("alerts")429 try audit("alerts-xxxl", ignoring: [.contrast])430 }431432 // MARK: 11 — screenshots (French, dark)433434 func test11_Screenshots() {435 XCTAssertTrue(Control.send("touch"))436 launch()437 waitForShell()438 app.el("overview-nodes-fresh").waitToExist()439 sleep(2)440 shot("overview")441 go("nodes")442 app.el("node-row-" + Self.node1).waitToExist()443 sleep(3) // sparklines444 shot("nodes")445 app.el("node-row-" + Self.node1).tap()446 app.el("screen-node-detail").waitToExist()447 sleep(3)448 shot("node-detail")449 if isPad {450 go("nodes")451 }452 go("alerts")453 app.el("alert-row-" + Self.alertID).waitToExist().tap()454 app.el("screen-alert-detail").waitToExist()455 sleep(1)456 shot("alert-detail")457 go("actions")458 sleep(1)459 shot("actions")460 go("maintenance")461 sleep(2)462 shot("maintenance")463 go("services")464 sleep(1)465 shot("services")466 go("models")467 sleep(1)468 shot("models")469 go("storage")470 sleep(1)471 shot("storage")472 go("audit")473 sleep(1)474 shot("audit")475 go("settings")476 sleep(1)477 shot("settings")478 }479480 // MARK: 12 — a viewer is refused by the server (403 shown)481482 func test12_ViewerIsRefused() throws {483 launch()484 waitForShell()485 // The owner creates a one-time invitation for a viewer; the link is displayed once.486 go("settings")487 app.el("settings-pane-invitations").scrollAndTap(in: app)488 app.el("invitation-create").waitToExist().tap()489 app.el("screen-invitation-form").waitToExist()490 // Role picker: viewer.491 let role = app.el("invitation-role")492 role.waitToExist().tap()493 let viewer = app.buttons["Lecteur"].firstMatch494 viewer.waitToExist().tap()495 app.el("invitation-handle").clearAndType("viewer-ui")496 app.el("invitation-name").clearAndType("Viewer UI")497 app.el("invitation-submit").scrollAndTap(in: app)498 app.el("screen-secret").waitToExist(30)499 let link = try XCTUnwrap(app.el("secret-value").waitToExist().label.split(separator: "#").last.map(String.init), "no link shown")500 XCTAssertTrue(app.el("secret-qr").exists, "the link is also offered as a QR code")501 app.el("secret-done").tap()502 signOut()503504 openLink("mcc-ios-debug://setup#\(link)")505 app.el("setup-continue").waitToExist(20).tap()506 if app.el("setup-profile-continue").waitForExistence(timeout: 3) { app.el("setup-profile-continue").tap() }507 app.el("setup-create-passkey").waitToExist().tap()508 waitForShell()509 go("settings")510 XCTAssertTrue(app.el("settings-user-role").waitToExist().label.contains("Lecteur"))511 XCTAssertFalse(app.el("settings-pane-invitations").exists, "admin panes are hidden from a viewer")512513 // The viewer asks for an action anyway: the SERVER refuses (403) and the refusal is shown.514 go("nodes")515 app.el("node-row-" + Self.node1).waitToExist().tap()516 app.el("screen-node-detail").waitToExist()517 app.el("node-actions").scrollAndTap(in: app)518 app.el("action-type-node.maintenance.set").waitToExist().tap()519 app.el("screen-action-request").waitToExist()520 app.el("action-submit").scrollAndTap(in: app)521 app.el("action-confirm-send").waitToExist().tap()522 let error = app.el("action-error")523 error.waitToExist(20)524 attach("viewer-refused"); shot("viewer-refused")525 XCTAssertTrue(error.label.contains("403") || app.staticTexts.containing(NSPredicate(format: "label CONTAINS '403' OR label CONTAINS[c] 'forbidden' OR label CONTAINS[c] 'permission'")).firstMatch.exists,526 "the server's refusal is displayed")527 }528}529530private final class FindingsBox: @unchecked Sendable { var items: [String] = [] }531