import XCTest final class WorkspaceUITests: XCTestCase { @MainActor private func reveal(_ element: XCUIElement, in scrollView: XCUIElement) { for _ in 0..<8 { if scrollView.frame.contains(CGPoint(x: element.frame.midX, y: element.frame.midY)), element.isHittable { return } let start = scrollView.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) let direction: CGFloat = element.frame.midY > scrollView.frame.midY ? 0.2 : 0.8 let end = scrollView.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: direction)) start.press(forDuration: 0.05, thenDragTo: end) } XCTAssertTrue(element.isHittable) } @MainActor func testSavedWorkspaceColdStartNeverShowsSelectionBeforeRecovery() { continueAfterFailure = false XCUIDevice.shared.orientation = .portrait defer { XCUIDevice.shared.orientation = .portrait } let app = XCUIApplication() app.launchEnvironment["OS_ACTIVITY_DT_MODE"] = "NO" app.launchEnvironment["OS_ACTIVITY_MODE"] = "disable" app.launch() let settings = app.buttons["showServerSettings"] if settings.waitForExistence(timeout: 3) { settings.tap() } let address = app.textFields["serverAddress"] XCTAssertTrue(address.waitForExistence(timeout: 20)) address.tap() if address.buttons.firstMatch.exists { address.buttons.firstMatch.tap() } address.typeText("https://127.0.0.1:9/") app.buttons["openWorkspace"].tap() let confirmation = app.alerts.buttons["Switch server"] if confirmation.waitForExistence(timeout: 1) { confirmation.tap() } XCTAssertTrue(app.staticTexts["connectionStatus"].waitForExistence(timeout: 20)) app.terminate() app.launch() // An unreachable saved server may fail immediately; only recovery may reveal setup. for _ in 0..<30 { if address.exists { XCTAssertTrue(app.staticTexts["connectionStatus"].label.contains("server did not finish loading")) break } XCTAssertFalse(app.staticTexts["Choose your workspace."].exists) Thread.sleep(forTimeInterval: 0.1) } XCTAssertTrue(address.waitForExistence(timeout: 20)) XCTAssertEqual(address.value as? String, "https://127.0.0.1:9/") XCTAssertTrue(app.buttons["openWorkspace"].label.contains("Try again")) } @MainActor func testLauncherKeyboardValidationRotationAndAppearance() { continueAfterFailure = false XCUIDevice.shared.orientation = .portrait defer { XCUIDevice.shared.orientation = .portrait } let app = XCUIApplication() app.launchEnvironment["OS_ACTIVITY_DT_MODE"] = "NO" app.launchEnvironment["OS_ACTIVITY_MODE"] = "disable" app.launch() let settings = app.buttons["showServerSettings"] if settings.waitForExistence(timeout: 3) { settings.tap() } let address = app.textFields["serverAddress"] XCTAssertTrue(address.waitForExistence(timeout: 15)) address.tap() let clear = address.buttons.firstMatch if clear.exists { clear.tap() } address.typeText("http://invalid.example") app.buttons["openWorkspace"].tap() XCTAssertTrue(app.staticTexts["connectionStatus"].label.contains("valid HTTPS")) XCUIDevice.shared.orientation = .landscapeLeft let launcher = app.scrollViews["serverSettings"] reveal(address, in: launcher) let open = app.buttons["openWorkspace"] reveal(open, in: launcher) let dark = app.segmentedControls["appearance"].buttons["Dark"] reveal(dark, in: launcher) dark.tap() XCTAssertTrue(dark.isSelected) app.segmentedControls["appearance"].buttons["System"].tap() XCUIDevice.shared.orientation = .portrait } }