import XCTest /// Live smoke flows against gitbay.org, driven by accessibility — the /// coordinate-free verification the simulator's input pipeline cannot be /// trusted to do (krz/gitbay-ios#5). /// /// These WRITE to the live instance (an MR is opened and closed, a /// milestone assigned), so they only run when explicitly asked: /// /// TEST_RUNNER_GITBAY_UITEST_LIVE=1 xcodebuild test \ /// -only-testing:gitbayUITests ... /// /// They assume the simulator is already signed in as an account that can /// write to krz/gitbay-ios, and that branch `ui-smoke` exists. final class LiveSmokeUITests: XCTestCase { private var app: XCUIApplication! override func setUpWithError() throws { try XCTSkipUnless( ProcessInfo.processInfo.environment["GITBAY_UITEST_LIVE"] == "1", "live UI smoke is opt-in; set TEST_RUNNER_GITBAY_UITEST_LIVE=1" ) continueAfterFailure = false app = XCUIApplication() app.launch() } /// Everything in one ordered pass: milestone assign, edit-save, /// MR create, MR close. One test so the flows share navigation and /// the writes happen exactly once. func testCreationAndEditingFlows() throws { openRepo("krz/gitbay-ios") // --- Issue #4: milestone picker assigns v1.0.0 --- app.staticTexts["Issues"].firstMatch.tap() let issueRow = app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'README.org'")).firstMatch XCTAssertTrue(issueRow.waitForExistence(timeout: 10), "issue #4 not in the list") issueRow.tap() let milestoneMenu = app.descendants(matching: .any) .matching(identifier: "milestone-menu").firstMatch XCTAssertTrue(milestoneMenu.waitForExistence(timeout: 10)) milestoneMenu.tap() let milestoneChoice = app.buttons .containing(NSPredicate(format: "label BEGINSWITH 'v1.0.0'")).firstMatch XCTAssertTrue(milestoneChoice.waitForExistence(timeout: 5), "milestone menu did not open") milestoneChoice.tap() // The reload renders the assigned milestone in the header row. XCTAssertTrue(app.staticTexts["v1.0.0"].firstMatch .waitForExistence(timeout: 10), "milestone not shown after assign") // --- Issue #4: edit sheet saves (content unchanged) --- app.descendants(matching: .any).matching(identifier: "issue-actions-menu") .firstMatch.tap() let edit = app.buttons["Edit"].firstMatch XCTAssertTrue(edit.waitForExistence(timeout: 5)) edit.tap() let title = app.descendants(matching: .any) .matching(identifier: "compose-title").firstMatch XCTAssertTrue(title.waitForExistence(timeout: 5), "edit sheet did not open") XCTAssertTrue((title.value as? String)?.contains("README.org") == true, "edit sheet did not prefill") app.descendants(matching: .any).matching(identifier: "compose-submit") .firstMatch.tap() // Sheet dismissal proves the save round-tripped without error. XCTAssertTrue(waitForDisappearance(title, timeout: 15), "edit save did not dismiss") back() // to issues list back() // to repo screen // --- MR: create from ui-smoke, then close it --- app.staticTexts["Merge Requests"].firstMatch.tap() app.descendants(matching: .any).matching(identifier: "mr-create-button") .firstMatch.tap() let source = app.descendants(matching: .any) .matching(identifier: "mr-source").firstMatch XCTAssertTrue(source.waitForExistence(timeout: 5), "MR create sheet did not open") source.tap() source.typeText("ui-smoke") let target = app.descendants(matching: .any) .matching(identifier: "mr-target").firstMatch // The default branch prefilled while the sheet loaded. XCTAssertEqual(target.value as? String, "main", "target did not prefill") let mrTitle = app.descendants(matching: .any) .matching(identifier: "mr-title").firstMatch mrTitle.tap() mrTitle.typeText("UI smoke: mr create from the app") app.descendants(matching: .any).matching(identifier: "mr-submit") .firstMatch.tap() let createdRow = app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'UI smoke'")).firstMatch XCTAssertTrue(createdRow.waitForExistence(timeout: 15), "created MR not in the list") createdRow.tap() app.descendants(matching: .any).matching(identifier: "mr-actions-menu") .firstMatch.tap() let close = app.buttons["Close"].firstMatch XCTAssertTrue(close.waitForExistence(timeout: 5)) close.tap() // The confirmation dialog's destructive Close. let confirm = app.buttons["Close"].firstMatch XCTAssertTrue(confirm.waitForExistence(timeout: 5), "close confirmation missing") confirm.tap() XCTAssertTrue(app.staticTexts["closed"].firstMatch .waitForExistence(timeout: 15), "MR did not show closed after close") } // MARK: - Helpers private func openRepo(_ path: String) { let tab = app.buttons["Repositories"].firstMatch XCTAssertTrue(tab.waitForExistence(timeout: 10)) tab.tap() let search = app.searchFields.firstMatch XCTAssertTrue(search.waitForExistence(timeout: 10)) search.tap() search.typeText(path) let row = app.staticTexts[path].firstMatch XCTAssertTrue(row.waitForExistence(timeout: 15), "\(path) not in the repo list") row.tap() // Repo screen is loaded once its links render. XCTAssertTrue(app.staticTexts["Files"].firstMatch.waitForExistence(timeout: 10)) } private func back() { app.navigationBars.buttons.firstMatch.tap() } private func waitForDisappearance(_ element: XCUIElement, timeout: TimeInterval) -> Bool { let predicate = NSPredicate(format: "exists == false") let expectation = XCTNSPredicateExpectation(predicate: predicate, object: element) return XCTWaiter().wait(for: [expectation], timeout: timeout) == .completed } } extension LiveSmokeUITests { /// Repo management, kept reversible: create a scratch repo (deleted /// by the runner afterwards, deletion is CLI-only by design), pin and /// unpin, a topic round-trip, a merge-rule toggle round-trip, and the /// build-trigger error path on a repo with no job config. func testRepoManagementFlows() throws { // --- repo create first: it ends in the list's search state, // which the next step reuses. (Scratch repo; the runner deletes // it over SSH afterwards — deletion is CLI-only by design.) let tab = app.buttons["Repositories"].firstMatch XCTAssertTrue(tab.waitForExistence(timeout: 10)) tab.tap() app.descendants(matching: .any).matching(identifier: "repo-create-button") .firstMatch.tap() let pathField = app.descendants(matching: .any) .matching(identifier: "repo-create-path").firstMatch XCTAssertTrue(pathField.waitForExistence(timeout: 5)) pathField.tap() pathField.typeText("ui-smoke") app.switches.firstMatch.tap() // Private on app.descendants(matching: .any).matching(identifier: "repo-create-submit") .firstMatch.tap() // The sheet dismissing proves the create round-tripped; rows are // lazy, so find the new repo through the filter. XCTAssertTrue(waitForDisappearance(pathField, timeout: 15), "create sheet did not dismiss") let search = app.searchFields.firstMatch XCTAssertTrue(search.waitForExistence(timeout: 10)) search.tap() search.typeText("ui-smoke") XCTAssertTrue(app.staticTexts["cmc/ui-smoke"].firstMatch .waitForExistence(timeout: 15), "created repo not in the list") // --- pin / unpin round-trip on krz/gitbay-ios --- // Reuse the open search to get there. let clear = search.buttons.firstMatch if clear.exists { clear.tap() } else { search.tap() } search.typeText("krz/gitbay-ios") let repoRow = app.staticTexts["krz/gitbay-ios"].firstMatch XCTAssertTrue(repoRow.waitForExistence(timeout: 15)) repoRow.tap() XCTAssertTrue(app.staticTexts["Files"].firstMatch.waitForExistence(timeout: 10)) let menu = app.descendants(matching: .any) .matching(identifier: "repo-actions-menu").firstMatch XCTAssertTrue(menu.waitForExistence(timeout: 10)) menu.tap() let pin = app.buttons["Pin"].firstMatch XCTAssertTrue(pin.waitForExistence(timeout: 5), "Pin action missing") pin.tap() // State refreshed from the dashboard: the menu now offers Unpin. menu.tap() let unpin = app.buttons["Unpin"].firstMatch XCTAssertTrue(unpin.waitForExistence(timeout: 10), "pin did not take") unpin.tap() // --- settings: topic and merge-rule round-trips --- app.staticTexts["Settings"].firstMatch.tap() let addTopic = app.descendants(matching: .any) .matching(identifier: "settings-add-topic").firstMatch XCTAssertTrue(addTopic.waitForExistence(timeout: 10), "settings did not load") addTopic.tap() addTopic.typeText("ios") app.descendants(matching: .any).matching(identifier: "settings-add-topic-submit") .firstMatch.tap() let chip = app.staticTexts["ios"].firstMatch XCTAssertTrue(chip.waitForExistence(timeout: 10), "topic did not appear") // Remove it again: the chip's own x button is the next button. app.scrollViews.buttons.firstMatch.tap() XCTAssertTrue(waitForDisappearance(chip, timeout: 10), "topic did not remove") let resolved = app.switches["Require threads resolved"].firstMatch XCTAssertTrue(resolved.waitForExistence(timeout: 5)) // SwiftUI exposes the row as a switch that wraps the real // control; tap the innermost switch when there is one, else the // right edge of the row. let inner = resolved.switches.firstMatch let control: () -> Void = { if inner.exists && inner != resolved { inner.tap() } else { resolved.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap() } } control() XCTAssertTrue(waitForValue(resolved, "1", timeout: 10), "toggle did not persist on") control() XCTAssertTrue(waitForValue(resolved, "0", timeout: 10), "toggle did not persist off") back() // settings -> repo // --- build trigger error path (no .gitbay job config here) --- app.staticTexts["Builds"].firstMatch.tap() app.descendants(matching: .any).matching(identifier: "build-trigger-button") .firstMatch.tap() let jobField = app.textFields.firstMatch XCTAssertTrue(jobField.waitForExistence(timeout: 5), "trigger alert missing") jobField.tap() jobField.typeText("ci") app.buttons["Trigger"].firstMatch.tap() // "no job X" for an unknown job, "has no .gitbay/ci.yml" when the // repo has no CI config at all. let refusal = app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'no job' OR label CONTAINS 'no .gitbay'")).firstMatch XCTAssertTrue(refusal.waitForExistence(timeout: 15), "trigger refusal not surfaced") } private func waitForValue(_ element: XCUIElement, _ value: String, timeout: TimeInterval) -> Bool { let predicate = NSPredicate(format: "value == %@", value) let expectation = XCTNSPredicateExpectation(predicate: predicate, object: element) return XCTWaiter().wait(for: [expectation], timeout: timeout) == .completed } } extension LiveSmokeUITests { /// Discovery is read-only: feed, server-side repo search, grep, and /// profiles. No cleanup needed. func testDiscoveryFlows() throws { // --- feed renders events and navigates --- let feedTab = app.buttons["Feed"].firstMatch XCTAssertTrue(feedTab.waitForExistence(timeout: 10)) feedTab.tap() let firstEvent = app.cells.firstMatch XCTAssertTrue(firstEvent.waitForExistence(timeout: 15), "feed rendered no events") firstEvent.tap() // Wherever the event led, it left the feed root behind. XCTAssertTrue(app.navigationBars.buttons.firstMatch .waitForExistence(timeout: 10), "feed row did not navigate") back() // --- server-side search: "astronomy" is only a topic, invisible // to the client-side path/description filter --- let repoTab = app.buttons["Repositories"].firstMatch repoTab.tap() let search = app.searchFields.firstMatch XCTAssertTrue(search.waitForExistence(timeout: 10)) search.tap() search.typeText("astronomy") let hit = app.staticTexts["krz/space-wiki"].firstMatch XCTAssertTrue(hit.waitForExistence(timeout: 15), "server-side topic search found nothing") hit.tap() XCTAssertTrue(app.staticTexts["Files"].firstMatch.waitForExistence(timeout: 10)) // --- owner profile from the repo screen --- // The row's label merges; match it at any element type. app.descendants(matching: .any)["krz"].firstMatch.tap() XCTAssertTrue(app.staticTexts["warez for the public"].firstMatch .waitForExistence(timeout: 15), "profile did not load") XCTAssertTrue(app.staticTexts["Repositories"].firstMatch.exists, "profile repos missing") back() // --- grep inside the repo, last: its search UI owns the screen --- app.staticTexts["Search in Files"].firstMatch.tap() let grepField = app.searchFields.firstMatch XCTAssertTrue(grepField.waitForExistence(timeout: 10)) grepField.tap() grepField.typeText("space") app.keyboards.buttons["search"].firstMatch.tap() let match = app.cells.firstMatch XCTAssertTrue(match.waitForExistence(timeout: 15), "grep returned no matches") } } extension LiveSmokeUITests { /// Releases: list and detail on a real release, an edit round-trip /// that saves the prefilled content (a no-op write), and the /// missing-tag refusal on create. Nothing changes state. func testReleaseFlows() throws { openRepo("krz/gitbay") app.staticTexts["Releases"].firstMatch.tap() let row = app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'v1.0.0'")).firstMatch XCTAssertTrue(row.waitForExistence(timeout: 15), "release list empty") row.tap() // Notes render and assets carry sizes. XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'SHA256SUMS'")).firstMatch .waitForExistence(timeout: 15), "assets missing") // Edit sheet prefills; saving unchanged content round-trips. app.descendants(matching: .any).matching(identifier: "release-edit-button") .firstMatch.tap() let title = app.descendants(matching: .any) .matching(identifier: "compose-title").firstMatch XCTAssertTrue(title.waitForExistence(timeout: 5), "edit sheet did not open") XCTAssertTrue((title.value as? String)?.contains("v1.0.0") == true, "edit sheet did not prefill") app.descendants(matching: .any).matching(identifier: "compose-submit") .firstMatch.tap() XCTAssertTrue(waitForDisappearance(title, timeout: 15), "release edit did not dismiss") back() // Create with a tag that does not exist: the server's refusal is // the UI contract. app.descendants(matching: .any).matching(identifier: "release-create-button") .firstMatch.tap() let tag = app.descendants(matching: .any) .matching(identifier: "release-tag").firstMatch XCTAssertTrue(tag.waitForExistence(timeout: 5)) tag.tap() tag.typeText("v9.9.9") app.descendants(matching: .any).matching(identifier: "release-submit") .firstMatch.tap() XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'push the tag first'")).firstMatch .waitForExistence(timeout: 15), "missing-tag refusal not surfaced") app.buttons["Cancel"].firstMatch.tap() } } extension LiveSmokeUITests { /// Account keys and email. Read-only plus refusal paths — no key is /// added or removed, no mail is sent. func testAccountFlows() throws { // Dashboard toolbar -> account screen. let accountLink = app.descendants(matching: .any) .matching(identifier: "account-screen-link").firstMatch XCTAssertTrue(accountLink.waitForExistence(timeout: 10)) accountLink.tap() // Real keys render: SSH fingerprints and the PGP key's UID email. XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH 'SHA256:'")).firstMatch .waitForExistence(timeout: 15), "SSH keys missing") XCTAssertTrue(app.staticTexts["hello@cleberg.net"].firstMatch .waitForExistence(timeout: 10), "PGP key UID missing") // Pasting garbage as an SSH key surfaces the server's validation. app.descendants(matching: .any).matching(identifier: "add-ssh-key") .firstMatch.tap() let paste = app.descendants(matching: .any) .matching(identifier: "key-paste-text").firstMatch XCTAssertTrue(paste.waitForExistence(timeout: 5)) paste.tap() paste.typeText("not a key") app.descendants(matching: .any).matching(identifier: "key-paste-submit") .firstMatch.tap() XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'not a valid public key'")).firstMatch .waitForExistence(timeout: 15), "invalid-key refusal not surfaced") app.buttons["Cancel"].firstMatch.tap() // A bogus verification code is refused, not swallowed. let code = app.descendants(matching: .any) .matching(identifier: "email-code").firstMatch XCTAssertTrue(code.waitForExistence(timeout: 5)) code.tap() XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5)) code.typeText("000000") if (code.value as? String)?.contains("000000") != true { // The first keystrokes can race focus; type once more. code.typeText("000000") } let verify = app.descendants(matching: .any) .matching(identifier: "email-verify").firstMatch XCTAssertTrue(verify.waitForExistence(timeout: 5)) XCTAssertTrue(verify.isEnabled, "verify stayed disabled — code text never landed") verify.tap() XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'invalid, expired'")).firstMatch .waitForExistence(timeout: 15), "bad-code refusal not surfaced") } } extension LiveSmokeUITests { /// Orgs: members render, and a team lives a full life — created, /// granted a repo, the grant revoked, the team deleted. Everything /// this test makes, it removes. func testOrgFlows() throws { let accountLink = app.descendants(matching: .any) .matching(identifier: "account-screen-link").firstMatch XCTAssertTrue(accountLink.waitForExistence(timeout: 10)) accountLink.tap() let orgRow = app.staticTexts["krz"].firstMatch XCTAssertTrue(orgRow.waitForExistence(timeout: 15), "org list missing") orgRow.tap() // Members render with roles. XCTAssertTrue(app.staticTexts["cmc"].firstMatch .waitForExistence(timeout: 15), "org members missing") // Create a team. let teamField = app.descendants(matching: .any) .matching(identifier: "org-new-team").firstMatch XCTAssertTrue(teamField.waitForExistence(timeout: 5)) teamField.tap() teamField.typeText("ui-smoke") app.descendants(matching: .any).matching(identifier: "org-new-team-submit") .firstMatch.tap() let teamRow = app.staticTexts["ui-smoke"].firstMatch XCTAssertTrue(teamRow.waitForExistence(timeout: 15), "created team not listed") // Grant it a repo, then revoke. teamRow.tap() let repoField = app.textFields["org/repo"].firstMatch XCTAssertTrue(repoField.waitForExistence(timeout: 10)) repoField.tap() repoField.typeText("krz/gitbay-ios") app.buttons["Grant"].firstMatch.tap() let grantRow = app.staticTexts["krz/gitbay-ios"].firstMatch XCTAssertTrue(grantRow.waitForExistence(timeout: 15), "grant not listed") grantRow.swipeLeft() app.buttons["Revoke"].firstMatch.tap() XCTAssertTrue(waitForDisappearance(grantRow, timeout: 15), "grant not revoked") back() // Delete the team, through its confirmation. let row = app.staticTexts["ui-smoke"].firstMatch XCTAssertTrue(row.waitForExistence(timeout: 10)) row.swipeLeft() app.buttons["Delete"].firstMatch.tap() // The confirmation dialog's destructive Delete. let confirm = app.buttons["Delete"].firstMatch XCTAssertTrue(confirm.waitForExistence(timeout: 5)) confirm.tap() XCTAssertTrue(waitForDisappearance(row, timeout: 15), "team not deleted") } }