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! /// The scratch repo testRepoManagementFlows creates. A run that dies /// before deleting it leaves it behind, and then every later run /// fails at "create sheet did not dismiss" — the create is refused /// because the name is taken, which reads like a UI bug and is not. /// Removed before and after, so neither a crashed run nor this one /// can strand it. private static let scratchRepo = "cmc/ui-smoke" 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() // xcodebuild runs tests on simulator clones, so the base // device's appearance never applies; force it per run. switch ProcessInfo.processInfo.environment["GITBAY_UITEST_DARK"] { case "1": app.launchArguments.append("-gb-dark") case "0": app.launchArguments.append("-gb-light") default: break // follow the device, as a real launch does } app.launch() // A fresh device — a clone on another runtime, say — starts on // the token screen; the flows assume a signed-in app. signInIfNeeded() if name.contains("testRepoManagementFlows") { deleteScratchRepo() } if name.contains("testCreationAndEditingFlows") { ensureFixtureIssue() try requireFixtureBranch() } if name.contains("testBlameAndEditFlows") { try requireFixtureRepo() } } override func tearDownWithError() throws { if name.contains("testRepoManagementFlows") { deleteScratchRepo() } } /// `repo delete` over the JSON API — the app has no delete screen /// (deletion is SSH-only by design), so cleanup cannot go through /// the UI. A repo that is not there answers exit 3, which is the /// outcome we want anyway. private func deleteScratchRepo() { _ = runCommand(["repo", "delete", Self.scratchRepo, "--yes"]) // The rename round-trip's halfway name, in case a run died there. _ = runCommand(["repo", "delete", Self.scratchRepo + "-2", "--yes"]) } /// The issue the editing flow works on. It is a fixture, not a real /// issue: pinning the test to whatever issue happened to be open put /// it at the mercy of the project moving on, and it duly broke when /// that issue was closed (krz/gitbay-ios#8). static let fixtureIssueTitle = "ui-smoke fixture: do not close" /// Guarantee the fixture issue exists and is open. It is reused /// rather than recreated, so runs do not pile up closed issues. private func ensureFixtureIssue() { guard let data = readCommand( ["issue", "list", Self.fixtureRepo, "--state", "open"]), let envelope = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return } let issues = envelope["data"] as? [[String: Any]] ?? [] if issues.contains(where: { $0["title"] as? String == Self.fixtureIssueTitle }) { return } _ = runCommand( ["issue", "create", Self.fixtureRepo, "--title", Self.fixtureIssueTitle, "--file", "-"], stdin: "Created by the live smoke suite. It exercises the milestone " + "picker and the edit sheet, and is reused every run." ) } static let fixtureRepo = "krz/gitbay-ios" /// The MR flow needs a source branch carrying a commit main does not /// have. Nothing in the app or the API can create a branch — that is /// a push — so this only checks, and says so plainly rather than /// letting the test fail later at "created MR not in the list". private func requireFixtureBranch() throws { guard let data = readCommand(["repo", "refs", Self.fixtureRepo]), let envelope = try? JSONSerialization.jsonObject(with: data) as? [String: Any], let refs = envelope["data"] as? [String: Any], let branches = refs["branches"] as? [[String: Any]] else { return } // no token, or the instance is unreachable let names = branches.compactMap { $0["name"] as? String } try XCTSkipUnless(names.contains("ui-smoke"), """ krz/gitbay-ios has no ui-smoke branch. The MR flow opens a \ merge request from it; recreate it with a commit main does \ not have (see .gitbay/ui-smoke.md on that branch). """) } /// POST /api/v1/cmd. Writes the suite needs but the app cannot make. @discardableResult private func runCommand(_ argv: [String], stdin: String? = nil) -> Data? { var body: [String: Any] = ["argv": argv] if let stdin { body["stdin"] = stdin } return call(method: "POST", path: "/api/v1/cmd", body: body) } /// GET /api/v1/read, for the reads that decide what a test sets up. private func readCommand(_ argv: [String]) -> Data? { let query = argv .map { "argv=" + ($0.addingPercentEncoding( withAllowedCharacters: .alphanumerics) ?? $0) } .joined(separator: "&") return call(method: "GET", path: "/api/v1/read?" + query, body: nil) } private func call(method: String, path: String, body: [String: Any]?) -> Data? { guard let token = ProcessInfo.processInfo .environment["GITBAY_UITEST_TOKEN"], !token.isEmpty, let url = URL(string: "https://gitbay.org" + path) else { return nil } var request = URLRequest(url: url) request.httpMethod = method request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") if let body { request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.httpBody = try? JSONSerialization.data(withJSONObject: body) } var result: Data? let done = DispatchSemaphore(value: 0) URLSession.shared.dataTask(with: request) { data, _, _ in result = data done.signal() }.resume() _ = done.wait(timeout: .now() + 15) return result } /// 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") // --- the fixture issue: milestone picker assigns v1.0.0 --- app.staticTexts["Issues"].firstMatch.tap() let issueRow = app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'ui-smoke fixture'")).firstMatch XCTAssertTrue(issueRow.waitForExistence(timeout: 10), "fixture issue not in the list; setUp should have created it") 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") // --- the fixture issue: 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("ui-smoke fixture") == true, "edit sheet did not prefill") // Save the body as org, reopen, and the picker must start on Org: // the sheet has to read the stored format, not its own default. let format = app.segmentedControls.matching(identifier: "compose-format").firstMatch XCTAssertTrue(format.waitForExistence(timeout: 5), "format picker missing") XCTAssertTrue(format.buttons["Markdown"].isSelected, "fixture did not open on Markdown") format.buttons["Org"].tap() 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") app.descendants(matching: .any).matching(identifier: "issue-actions-menu") .firstMatch.tap() XCTAssertTrue(edit.waitForExistence(timeout: 5)) edit.tap() XCTAssertTrue(format.waitForExistence(timeout: 5), "edit sheet did not reopen") XCTAssertTrue(format.buttons["Org"].isSelected, "edit sheet did not open on the stored format") // Restore the fixture to markdown. format.buttons["Markdown"].tap() app.descendants(matching: .any).matching(identifier: "compose-submit") .firstMatch.tap() 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") focusAndType(source, "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 focusAndType(mrTitle, "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() // The gates are shown before any merge is tried. let gates = header("Gates") XCTAssertTrue(scrollTo(gates, swipes: 8), "gates section missing") // A fresh MR has one revision; the section lists it. let revisions = header("Revisions") XCTAssertTrue(scrollTo(revisions, swipes: 8), "revisions section missing") XCTAssertTrue(app.staticTexts["v1"].firstMatch.exists, "first revision not listed") 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) { selectTab("Repositories") // `.searchable` keeps the field tucked above the list until it is // scrolled into view. let search = app.searchFields.firstMatch if !search.waitForExistence(timeout: 5) { app.swipeDown() XCTAssertTrue(search.waitForExistence(timeout: 10), "search field never appeared") } focusAndType(search, 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), "repo screen did not open") } private func back() { app.navigationBars.buttons.firstMatch.tap() } /// Keys, PGP and email live behind the account menu, which is on the /// My Profile tab and nowhere else. func openAccountScreen(file: StaticString = #filePath, line: UInt = #line) { selectTab("My Profile") let menu = app.descendants(matching: .any) .matching(identifier: "account-menu").firstMatch XCTAssertTrue(menu.waitForExistence(timeout: 15), "account menu missing", file: file, line: line) menu.tap() let keys = app.buttons["Keys & Email"].firstMatch XCTAssertTrue(keys.waitForExistence(timeout: 5), "Keys & Email missing from the account menu", file: file, line: line) keys.tap() } /// The edit flow saves a change to a real file. Seeding a /// repository's first commit is a push, which no test can make, so /// this only checks — and says why, rather than failing later at /// "cmc/ui-smoke-edit not in the repo list". private func requireFixtureRepo() throws { guard let data = readCommand(["repo", "show", "cmc/ui-smoke-edit"]), let envelope = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return } // no token, or the instance is unreachable try XCTSkipUnless(envelope["data"] != nil, """ cmc/ui-smoke-edit is missing. The edit flow saves a change to \ notes.txt in it; recreate the repo with that file (see its \ README) and run again. """) } /// Scroll a list until an element is in the hierarchy. Offscreen /// rows do not exist to XCUITest, so waitForExistence alone fails on /// anything below the fold. @discardableResult /// A list section header. iOS 18 renders these uppercased and iOS 26 /// as written, so the match ignores case. func header(_ text: String) -> XCUIElement { app.staticTexts.matching(NSPredicate(format: "label ==[c] %@", text)).firstMatch } func scrollTo(_ element: XCUIElement, swipes: Int = 6) -> Bool { for _ in 0.. 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.) selectTab("Repositories") app.descendants(matching: .any).matching(identifier: "repo-create-button") .firstMatch.tap() let newRepo = app.buttons["New Repository"].firstMatch XCTAssertTrue(newRepo.waitForExistence(timeout: 5), "create menu did not open") newRepo.tap() let pathField = app.descendants(matching: .any) .matching(identifier: "repo-create-path").firstMatch XCTAssertTrue(pathField.waitForExistence(timeout: 5)) focusAndType(pathField, "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 createSearch = app.searchFields.firstMatch XCTAssertTrue(createSearch.waitForExistence(timeout: 10)) focusAndType(createSearch, "ui-smoke") XCTAssertTrue(app.staticTexts["cmc/ui-smoke"].firstMatch .waitForExistence(timeout: 15), "created repo not in the list") // --- access: grant a user on the scratch repo, then revoke --- app.staticTexts["cmc/ui-smoke"].firstMatch.tap() XCTAssertTrue(app.staticTexts["Files"].firstMatch.waitForExistence(timeout: 10)) app.staticTexts["Settings"].firstMatch.tap() let grantUser = app.descendants(matching: .any) .matching(identifier: "settings-grant-user").firstMatch XCTAssertTrue(scrollTo(grantUser, swipes: 8), "access section not reachable") focusAndType(grantUser, "apple-review") app.descendants(matching: .any).matching(identifier: "settings-grant-submit") .firstMatch.tap() let grantRow = app.staticTexts["apple-review"].firstMatch XCTAssertTrue(grantRow.waitForExistence(timeout: 15), "grant not listed") grantRow.swipeLeft() app.buttons["Revoke"].firstMatch.tap() let confirmGrantRevoke = app.buttons["Revoke"].firstMatch XCTAssertTrue(confirmGrantRevoke.waitForExistence(timeout: 5), "revoke confirmation missing") confirmGrantRevoke.tap() XCTAssertTrue(waitForDisappearance(grantRow, timeout: 15), "grant not revoked") // --- webhooks: add one, see it listed, remove it --- let webhooksLink = app.descendants(matching: .any) .matching(identifier: "settings-webhooks-link").firstMatch XCTAssertTrue(scrollTo(webhooksLink, swipes: 8), "webhooks link not reachable") webhooksLink.tap() let addHook = app.descendants(matching: .any) .matching(identifier: "webhook-add-button").firstMatch XCTAssertTrue(addHook.waitForExistence(timeout: 10), "webhooks did not load") addHook.tap() let hookURL = app.descendants(matching: .any) .matching(identifier: "webhook-url").firstMatch XCTAssertTrue(hookURL.waitForExistence(timeout: 5), "webhook sheet did not open") focusAndType(hookURL, "https://example.com/ui-smoke") app.descendants(matching: .any).matching(identifier: "webhook-submit") .firstMatch.tap() let hookRow = app.staticTexts["https://example.com/ui-smoke"].firstMatch XCTAssertTrue(hookRow.waitForExistence(timeout: 15), "webhook not listed") hookRow.swipeLeft() app.buttons["Remove"].firstMatch.tap() let confirmHookRemove = app.buttons["Remove"].firstMatch XCTAssertTrue(confirmHookRemove.waitForExistence(timeout: 5), "webhook remove confirmation missing") confirmHookRemove.tap() XCTAssertTrue(waitForDisappearance(hookRow, timeout: 15), "webhook not removed") back() // webhooks -> settings // --- rename the scratch repo there and back --- // Each rename pushes the renamed repository; the round-trip ends // on cmc/ui-smoke again, several screens deep. var firstRename = true let rename: (String, String) -> Void = { newName, expectedPath in if firstRename { firstRename = false // already on the settings screen } else { // Fresh repo screen: scroll to the top so no row hides // under the navigation bar, then reach Settings. self.app.swipeDown() let settingsLink = self.app.descendants(matching: .any).matching(identifier: "repo-settings-link").firstMatch XCTAssertTrue(self.scrollTo(settingsLink), "settings link not reachable") settingsLink.tap() } let renameButton = self.app.descendants(matching: .any) .matching(identifier: "settings-rename-button").firstMatch XCTAssertTrue(self.scrollTo(renameButton, swipes: 10), "rename button not reachable") renameButton.tap() let field = self.app.textFields["New name"].firstMatch XCTAssertTrue(field.waitForExistence(timeout: 5), "rename alert did not open") field.tap() // Prefilled with the current name; clear it before typing. field.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 12) + newName) self.app.buttons["Rename"].firstMatch.tap() // The settings screen offers the renamed repository at the // top; the list is scrolled to its end, so go back up first. let renamedLink = self.app.descendants(matching: .any) .matching(identifier: "settings-renamed-link").firstMatch sleep(2) for _ in 0..<6 where !renamedLink.exists { self.app.swipeDown() } XCTAssertTrue(renamedLink.waitForExistence(timeout: 10), "rename did not land") renamedLink.tap() XCTAssertTrue(self.app.staticTexts[expectedPath].firstMatch.waitForExistence(timeout: 15), "renamed repo did not open as \(expectedPath)") } rename("ui-smoke-2", "cmc/ui-smoke-2") rename("ui-smoke", "cmc/ui-smoke") // --- pin / unpin round-trip on krz/gitbay-ios --- // Start the list fresh; the rename left the stack several deep. app.terminate() app.launch() selectTab("Repositories") let search = app.searchFields.firstMatch XCTAssertTrue(search.waitForExistence(timeout: 10)) focusAndType(search, "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() // Bookmark it, find it in the bookmarks list, then unbookmark. // A run that died between the two leaves it bookmarked; undo // that first so the step starts from the same state every time. menu.tap() let leftover = app.buttons["Unbookmark"].firstMatch if leftover.waitForExistence(timeout: 3) { leftover.tap() XCTAssertTrue(waitForDisappearance(leftover, timeout: 10)) menu.tap() } let bookmark = app.buttons["Bookmark"].firstMatch XCTAssertTrue(bookmark.waitForExistence(timeout: 5), "Bookmark action missing") bookmark.tap() // An active search hides the list's toolbar, so start the list // fresh: relaunching lands on a list with the bookmarks button. app.terminate() app.launch() selectTab("Repositories") let bookmarksButton = app.descendants(matching: .any) .matching(identifier: "repo-bookmarks-button").firstMatch XCTAssertTrue(bookmarksButton.waitForExistence(timeout: 15), "bookmarks button missing") bookmarksButton.tap() let bookmarkedRow = app.staticTexts["krz/gitbay-ios"].firstMatch XCTAssertTrue(bookmarkedRow.waitForExistence(timeout: 15), "bookmarked repo not in the bookmarks list") // Open it from the bookmarks list and undo the bookmark there. bookmarkedRow.tap() XCTAssertTrue(menu.waitForExistence(timeout: 10)) menu.tap() let unbookmark = app.buttons["Unbookmark"].firstMatch XCTAssertTrue(unbookmark.waitForExistence(timeout: 10), "bookmark did not take") unbookmark.tap() // --- settings: topic and merge-rule round-trips --- // The links section can sit below the README fold, and the row's // label is not always exposed as a static text. let settingsLink = app.descendants(matching: .any) .matching(identifier: "repo-settings-link").firstMatch XCTAssertTrue(scrollTo(settingsLink), "settings link not reachable") settingsLink.tap() let addTopic = app.descendants(matching: .any) .matching(identifier: "settings-add-topic").firstMatch XCTAssertTrue(addTopic.waitForExistence(timeout: 10), "settings did not load") focusAndType(addTopic, "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 through the chip's own x button — by name, since // the repository carries other topics — and it asks first. app.descendants(matching: .any).matching(identifier: "settings-remove-topic-ios") .firstMatch.tap() let confirmRemove = app.buttons["Remove"].firstMatch XCTAssertTrue(confirmRemove.waitForExistence(timeout: 5), "topic remove confirmation missing") confirmRemove.tap() XCTAssertTrue(waitForDisappearance(chip, timeout: 10), "topic did not remove") // Merge-requests-only sits with the protected branches. let mergeOnly = app.switches["Merge requests only"].firstMatch XCTAssertTrue(scrollTo(mergeOnly), "merge-only toggle not reachable") let innerMergeOnly = mergeOnly.switches.firstMatch let flipMergeOnly: () -> Void = { if innerMergeOnly.exists && innerMergeOnly != mergeOnly { innerMergeOnly.tap() } else { mergeOnly.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap() } } flipMergeOnly() XCTAssertTrue(waitForValue(mergeOnly, "1", timeout: 10), "merge-only toggle did not persist on") flipMergeOnly() XCTAssertTrue(waitForValue(mergeOnly, "0", timeout: 10), "merge-only toggle did not persist off") // A tag glob is protected, listed, and unprotected. let tagGlob = app.descendants(matching: .any) .matching(identifier: "settings-protect-tag").firstMatch XCTAssertTrue(scrollTo(tagGlob), "protected tags section not reachable") focusAndType(tagGlob, "ui-smoke-*") app.descendants(matching: .any).matching(identifier: "settings-protect-tag-submit") .firstMatch.tap() let globRow = app.staticTexts["ui-smoke-*"].firstMatch XCTAssertTrue(globRow.waitForExistence(timeout: 10), "tag glob not listed") // By identifier: the protected branch above has an Unprotect too. app.descendants(matching: .any).matching(identifier: "settings-unprotect-tag-ui-smoke-*") .firstMatch.tap() XCTAssertTrue(waitForDisappearance(globRow, timeout: 10), "tag glob not unprotected") // Merge rules sit below the protected branches and tags. let resolved = app.switches["Require threads resolved"].firstMatch // The merge-requirements section sits below the fold, and a List // does not build rows it has not shown, so it must be scrolled // into existence before it can be queried. XCTAssertTrue(scrollTo(resolved), "merge requirements section not reachable") // 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") // The code-owner rule is one more toggle in the same section. let codeowners = app.switches["Require code owner review"].firstMatch XCTAssertTrue(scrollTo(codeowners), "code owner toggle not reachable") let innerCodeowners = codeowners.switches.firstMatch let flipCodeowners: () -> Void = { if innerCodeowners.exists && innerCodeowners != codeowners { innerCodeowners.tap() } else { codeowners.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap() } } flipCodeowners() XCTAssertTrue(waitForValue(codeowners, "1", timeout: 10), "code owner toggle did not persist on") flipCodeowners() XCTAssertTrue(waitForValue(codeowners, "0", timeout: 10), "code owner toggle did not persist off") back() // settings -> repo // The repo screen keeps the scroll that reached Settings, which // can leave Builds under the navigation bar. app.swipeDown() // --- nothing to trigger without a job file --- // This repo has no .gitbay/ci.yml, so `build jobs` returns none // and the control is gated rather than failing after a guess. app.staticTexts["Builds"].firstMatch.tap() let trigger = app.descendants(matching: .any) .matching(identifier: "build-trigger-button").firstMatch XCTAssertTrue(trigger.waitForExistence(timeout: 15), "trigger control missing") // Assert on behaviour, not on isEnabled: a disabled SwiftUI Menu // still reports itself enabled to XCUITest. trigger.tap() let anyJob = app.buttons.containing( NSPredicate(format: "label CONTAINS 'on push' OR label CONTAINS 'schedule '")) .firstMatch XCTAssertFalse(anyJob.waitForExistence(timeout: 3), "a repo with no job file offered a job to trigger") } 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 --- selectTab("Feed") 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 --- selectTab("Repositories") let search = app.searchFields.firstMatch XCTAssertTrue(search.waitForExistence(timeout: 10)) focusAndType(search, "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. It is // the last row of the links section, below the fold. let ownerLink = app.descendants(matching: .any)["krz"].firstMatch XCTAssertTrue(scrollTo(ownerLink), "owner link not reachable") ownerLink.tap() XCTAssertTrue(app.staticTexts["warez for the public"].firstMatch .waitForExistence(timeout: 15), "profile did not load") XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH[c] 'Repositories'")).firstMatch .waitForExistence(timeout: 10), "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)) focusAndType(grepField, "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() // Newest first, and the list has grown past the fold, so the // first row is whichever release is current. let row = app.cells.firstMatch XCTAssertTrue(row.waitForExistence(timeout: 15), "release list empty") row.tap() // Notes render and assets carry sizes. The assets sit under the // notes, which can run past the fold. XCTAssertTrue(app.descendants(matching: .any) .matching(identifier: "release-edit-button").firstMatch .waitForExistence(timeout: 15), "release did not open") XCTAssertTrue(scrollTo(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'SHA256SUMS'")).firstMatch, swipes: 10), "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") XCTAssertFalse((title.value as? String ?? "").isEmpty, "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)) focusAndType(tag, "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. openAccountScreen() // 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)) focusAndType(paste, "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() // Activity mail flips off and back on; the value comes back from // the server each time. let mail = app.switches["Activity by mail"].firstMatch XCTAssertTrue(scrollTo(mail), "mail toggle not reachable") let innerMail = mail.switches.firstMatch let flipMail: () -> Void = { if innerMail.exists && innerMail != mail { innerMail.tap() } else { mail.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap() } } let mailWasOn = (mail.value as? String) == "1" flipMail() XCTAssertTrue(waitForValue(mail, mailWasOn ? "0" : "1", timeout: 10), "mail toggle did not persist") flipMail() XCTAssertTrue(waitForValue(mail, mailWasOn ? "1" : "0", timeout: 10), "mail toggle did not restore") // The watch preference (v1.19.0) flips the same way. let watch = app.switches["Watch writable repositories"].firstMatch XCTAssertTrue(scrollTo(watch), "watch toggle not reachable") let innerWatch = watch.switches.firstMatch let flipWatch: () -> Void = { if innerWatch.exists && innerWatch != watch { innerWatch.tap() } else { watch.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap() } } let watchWasOn = (watch.value as? String) == "1" flipWatch() XCTAssertTrue(waitForValue(watch, watchWasOn ? "0" : "1", timeout: 10), "watch toggle did not persist") flipWatch() XCTAssertTrue(waitForValue(watch, watchWasOn ? "1" : "0", timeout: 10), "watch toggle did not restore") // A bogus verification code is refused, not swallowed. let code = app.descendants(matching: .any) .matching(identifier: "email-code").firstMatch // Email sits below the keys on a List, which does not build rows // it has not shown. XCTAssertTrue(scrollTo(code), "email section not reachable") // The addresses list above the fields, the primary one marked. XCTAssertTrue(app.staticTexts["primary"].firstMatch.exists, "primary address not marked") focusAndType(code, "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 { openAccountScreen() 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)) focusAndType(teamField, "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)) focusAndType(repoField, "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() // The confirmation dialog's destructive Revoke. let confirmRevoke = app.buttons["Revoke"].firstMatch XCTAssertTrue(confirmRevoke.waitForExistence(timeout: 5), "revoke confirmation missing") confirmRevoke.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") } } extension LiveSmokeUITests { /// The pre-merge screenshot checkpoint: walks the dense screens and /// attaches captures. Run per device/appearance; export the /// attachments from the xcresult. Signs in first when the device has /// no session and TEST_RUNNER_GITBAY_UITEST_TOKEN is provided. func testScreenshotCheckpoint() throws { signInIfNeeded() snap("dashboard") openRepo("krz/gitbay") snap("repo") app.staticTexts["Merge Requests"].firstMatch.tap() let all = app.segmentedControls.buttons["All"].firstMatch XCTAssertTrue(all.waitForExistence(timeout: 10), "state picker missing") all.tap() // A real MR row carries its !number; the picker row does not. let mrNumber = app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH '!'")).firstMatch XCTAssertTrue(mrNumber.waitForExistence(timeout: 15), "no MR rows after All") snap("mr-list") mrNumber.tap() // The detail opens at its header; the diff row sits below the // fold and a List does not build rows it has not shown. let diffRow = app.staticTexts["Diff"].firstMatch XCTAssertTrue(scrollTo(diffRow), "MR detail has no diff row") snap("mr-detail") diffRow.tap() XCTAssertTrue(app.cells.firstMatch.waitForExistence(timeout: 15)) snap("diff") } private func signInIfNeeded() { // Signed in already: the tab bar is up and there is no token field. if app.tabBars.firstMatch.waitForExistence(timeout: 10), !app.secureTextFields.firstMatch.exists { return } let tokenField = app.secureTextFields.firstMatch guard tokenField.waitForExistence(timeout: 5) else { return } guard let token = ProcessInfo.processInfo.environment["GITBAY_UITEST_TOKEN"] else { XCTFail("device is signed out and no GITBAY_UITEST_TOKEN was provided") return } focusAndType(tokenField, token + "\n") XCTAssertTrue(app.staticTexts["Dashboard"].firstMatch .waitForExistence(timeout: 20), "sign-in did not land") dismissSavePasswordPrompt() } /// iOS offers to save whatever went into a SecureField, and the sheet /// sits over the app until answered — over the dashboard, in one set /// of store screenshots. It belongs to springboard, not to the app. private func dismissSavePasswordPrompt() { let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let notNow = springboard.buttons["Not Now"].firstMatch if notNow.waitForExistence(timeout: 8) { notNow.tap() _ = waitForDisappearance(notNow, timeout: 10) return } let inApp = app.buttons["Not Now"].firstMatch if inApp.waitForExistence(timeout: 3) { inApp.tap() _ = waitForDisappearance(inApp, timeout: 10) return } // No prompt is fine: iOS only offers once per credential. } /// Capture a screen, but not while it is still loading. These go to /// the App Store, and a spinner shipped as a screenshot once already. private func snap(_ name: String, file: StaticString = #filePath, line: UInt = #line) { let spinner = app.activityIndicators.firstMatch if spinner.exists { XCTAssertTrue(waitForDisappearance(spinner, timeout: 30), "\(name) still loading after 30s", file: file, line: line) } // A list that has loaded has rows; an empty state has text. Either // way something must be on screen besides chrome. let content = app.cells.firstMatch _ = content.waitForExistence(timeout: 10) let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = name attachment.lifetime = .keepAlways add(attachment) } } extension LiveSmokeUITests { /// Blame and file editing — the two capabilities that were web-only /// until krz/gitbay#42 and #43 made them commands. Blame is read-only /// on a real repo; the edit writes to a scratch repo the runner /// creates and deletes over SSH. func testBlameAndEditFlows() throws { // --- blame on a real file --- openRepo("krz/gitbay") app.staticTexts["Files"].firstMatch.tap() let goMod = app.staticTexts["go.mod"].firstMatch XCTAssertTrue(goMod.waitForExistence(timeout: 15), "go.mod not in the tree") goMod.tap() XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "file-actions-menu") .firstMatch.waitForExistence(timeout: 15), "file screen did not open") app.descendants(matching: .any).matching(identifier: "file-actions-menu") .firstMatch.tap() app.buttons["Blame"].firstMatch.tap() // Attribution shows the commit subject beside the lines. XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'gitbay'")).firstMatch .waitForExistence(timeout: 20), "blame rendered no attribution") // --- edit on the scratch repo --- // Relaunch rather than reuse the list: `.searchable` keeps the // previous query, and clearing it from the harness is unreliable. app.terminate() app.launch() openRepo("cmc/ui-smoke-edit") app.staticTexts["Files"].firstMatch.tap() let notes = app.staticTexts["notes.txt"].firstMatch XCTAssertTrue(notes.waitForExistence(timeout: 15), "notes.txt not in the tree") notes.tap() let menu = app.descendants(matching: .any) .matching(identifier: "file-actions-menu").firstMatch XCTAssertTrue(menu.waitForExistence(timeout: 15)) menu.tap() let edit = app.buttons .containing(NSPredicate(format: "label BEGINSWITH 'Edit on'")).firstMatch XCTAssertTrue(edit.waitForExistence(timeout: 5), "edit action missing") edit.tap() let content = app.descendants(matching: .any) .matching(identifier: "file-edit-content").firstMatch XCTAssertTrue(content.waitForExistence(timeout: 10), "edit sheet did not open") focusAndType(content, " edited from the app") let message = app.descendants(matching: .any) .matching(identifier: "file-edit-message").firstMatch focusAndType(message, "edit from ios") app.descendants(matching: .any).matching(identifier: "file-edit-commit") .firstMatch.tap() XCTAssertTrue(waitForDisappearance(content, timeout: 20), "commit did not dismiss") // The reloaded file shows the committed text. XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'edited from the app'")).firstMatch .waitForExistence(timeout: 20), "edit not reflected after commit") } } extension LiveSmokeUITests { /// The navigation and profile changes: identity lives in one menu, /// the dashboard can create a repository, a profile is a real /// profile, and a log entry opens its commit. func testProfileAndNavigationFlows() throws { // --- the dashboard offers creation --- selectTab("Dashboard") let create = app.descendants(matching: .any) .matching(identifier: "dashboard-create-button").firstMatch XCTAssertTrue(create.waitForExistence(timeout: 15), "dashboard + missing") create.tap() let pathField = app.descendants(matching: .any) .matching(identifier: "repo-create-path").firstMatch XCTAssertTrue(pathField.waitForExistence(timeout: 10), "dashboard + did not open the create sheet") app.buttons["Cancel"].firstMatch.tap() // --- identity is its own tab; the account menu rides with it --- selectTab("My Profile") let menu = app.descendants(matching: .any) .matching(identifier: "account-menu").firstMatch XCTAssertTrue(menu.waitForExistence(timeout: 10), "account menu missing from My Profile") menu.tap() XCTAssertTrue(app.buttons["Keys & Email"].firstMatch.waitForExistence(timeout: 5), "keys not in the account menu") app.tap() // dismiss the menu; the profile is already on screen // --- a profile is a profile: description, links, orgs, graph, repos --- XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'Self-Hosting'")).firstMatch .waitForExistence(timeout: 20), "profile description missing") XCTAssertTrue(header("Organizations").exists, "org memberships missing") XCTAssertTrue(app.staticTexts["krz"].firstMatch.exists, "org row missing") // --- an org admin can edit the org's profile --- app.staticTexts["krz"].firstMatch.tap() XCTAssertTrue(app.descendants(matching: .any) .matching(identifier: "profile-edit-button").firstMatch .waitForExistence(timeout: 15), "org profile offers no edit to its admin") back() // The graph and the repositories sit below the orgs and links, // and a List does not build rows it has not shown. XCTAssertTrue(scrollTo(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'contributions in the last year'")).firstMatch), "activity graph missing") XCTAssertTrue(scrollTo(app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH[c] 'Repositories'")).firstMatch), "repositories missing") // --- a log entry opens its commit --- app.terminate() app.launch() openRepo("krz/gitbay") app.staticTexts["History"].firstMatch.tap() let firstCommit = app.cells.firstMatch XCTAssertTrue(firstCommit.waitForExistence(timeout: 20), "history is empty") firstCommit.tap() // The commit screen IS the patch: no navigating away to find it. // A hunk header (@@) only appears in a rendered diff, and sits // below the message and the file list. let hunk = app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH '@@'")).firstMatch _ = hunk.waitForExistence(timeout: 20) XCTAssertTrue(scrollTo(hunk, swipes: 10), "commit screen did not render the patch inline") } } extension LiveSmokeUITests { /// The three gaps that needed no server work: branches and tags, /// milestones, and an MR's milestone. Read-only except the MR /// milestone, which is set and cleared back. func testRefsAndMilestoneFlows() throws { openRepo("krz/gitbay") // --- branches and tags, and browsing at a ref --- app.staticTexts["Branches & Tags"].firstMatch.tap() let main = app.staticTexts["main"].firstMatch XCTAssertTrue(main.waitForExistence(timeout: 20), "refs did not load") XCTAssertTrue(app.staticTexts["default"].firstMatch.exists, "the default branch is not marked") XCTAssertTrue(header("Tags").exists, "tags section missing") main.tap() // Tapping a ref browses the repository there. XCTAssertTrue(app.cells.firstMatch.waitForExistence(timeout: 20), "browsing at a ref showed nothing") back() back() // --- milestones with progress --- app.staticTexts["Milestones"].firstMatch.tap() XCTAssertTrue(app.segmentedControls.firstMatch.waitForExistence(timeout: 15), "milestones did not load") app.segmentedControls.buttons["All"].firstMatch.tap() XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'closed'")).firstMatch .waitForExistence(timeout: 20), "milestone progress missing") back() // --- an MR's milestone reads back, and can be cleared --- app.staticTexts["Merge Requests"].firstMatch.tap() app.segmentedControls.buttons["All"].firstMatch.tap() let mrNumber = app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH '!'")).firstMatch XCTAssertTrue(mrNumber.waitForExistence(timeout: 20), "no MRs") mrNumber.tap() let milestone = app.descendants(matching: .any) .matching(identifier: "mr-milestone-menu").firstMatch // The nav bar is the "opened" signal; everything else on this // screen can be below the fold. XCTAssertTrue(app.navigationBars.element.waitForExistence(timeout: 20), "MR detail did not open") XCTAssertTrue(scrollTo(milestone, swipes: 8), "MR milestone row missing") milestone.tap() // The picker offers None plus the open milestones. XCTAssertTrue(app.buttons["None"].firstMatch.waitForExistence(timeout: 10), "milestone picker did not open") app.buttons["None"].firstMatch.tap() } } extension LiveSmokeUITests { /// Explore and history at a ref — the two capabilities krz/gitbay!101 /// made reachable. Read-only. func testExploreAndRefLogFlows() throws { // --- explore lists what the instance hosts --- selectTab("Explore") let firstRepo = app.cells.firstMatch XCTAssertTrue(firstRepo.waitForExistence(timeout: 20), "explore listed nothing") // Public repos this account does not own are reachable here. XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'audit-labs/'")).firstMatch .waitForExistence(timeout: 10), "explore is not the public listing") firstRepo.tap() XCTAssertTrue(app.staticTexts["Files"].firstMatch.waitForExistence(timeout: 20), "explore row did not open its repo") // --- history at a ref --- app.terminate() app.launch() openRepo("krz/gitbay") // Browse a ref, then ask for its history — the move the tree page // offers on the web. app.staticTexts["Branches & Tags"].firstMatch.tap() let main = app.staticTexts["main"].firstMatch XCTAssertTrue(main.waitForExistence(timeout: 20), "refs did not load") main.tap() let history = app.descendants(matching: .any) .matching(identifier: "tree-history-button").firstMatch XCTAssertTrue(history.waitForExistence(timeout: 20), "no History on the tree") history.tap() XCTAssertTrue(app.navigationBars .containing(NSPredicate(format: "identifier CONTAINS 'main'")).firstMatch .waitForExistence(timeout: 20), "ref history did not open") XCTAssertTrue(app.cells.firstMatch.waitForExistence(timeout: 20), "ref history rendered no commits") } } extension LiveSmokeUITests { /// The wiki — the last capability that was browser-only until /// krz/gitbay#48. Read-only; editing is a push, on every surface. func testWikiFlows() throws { openRepo("krz/gitbay") app.staticTexts["Wiki"].firstMatch.tap() // The landing page leads and is marked. let home = app.staticTexts["Home"].firstMatch XCTAssertTrue(home.waitForExistence(timeout: 20), "wiki pages did not load") XCTAssertTrue(app.staticTexts["home"].firstMatch.exists, "the landing page is not marked") // Parity.org is an org page, so this also proves the org renderer // runs on wiki content and not just READMEs. let parity = app.staticTexts["Parity"].firstMatch XCTAssertTrue(parity.exists, "Parity page missing from the listing") parity.tap() XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'surface'")).firstMatch .waitForExistence(timeout: 20), "wiki page rendered no prose") // Org headings render as headings, not as raw #+title:. XCTAssertFalse(app.staticTexts .containing(NSPredicate(format: "label CONTAINS '#+title'")).firstMatch.exists, "org markup leaked into the rendered page") } } extension LiveSmokeUITests { /// Builds on a repo that has a job file: the picker offers what the /// server names, and the detail screen says more than the log. func testBuildJobsAndDetail() throws { openRepo("krz/gitbay") app.staticTexts["Builds"].firstMatch.tap() // The picker lists jobs from `build jobs` — no name to type. let trigger = app.descendants(matching: .any) .matching(identifier: "build-trigger-button").firstMatch XCTAssertTrue(trigger.waitForExistence(timeout: 20), "trigger control missing") XCTAssertTrue(trigger.isEnabled, "trigger is disabled where a job file exists") trigger.tap() let job = app.buttons .containing(NSPredicate(format: "label CONTAINS 'build' AND label CONTAINS 'on push'")) .firstMatch XCTAssertTrue(job.waitForExistence(timeout: 10), "job menu did not list the job with why it runs") // Dismiss without queueing a real build. app.tap() // The detail screen carries status, ref and timing, not just log. let firstBuild = app.cells.firstMatch XCTAssertTrue(firstBuild.waitForExistence(timeout: 20), "no builds listed") firstBuild.tap() for label in ["success", "queued"] where app.staticTexts[label].firstMatch.exists { XCTAssertTrue(true) } XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label BEGINSWITH 'queued '")).firstMatch .waitForExistence(timeout: 20), "build detail shows no timing") } } extension LiveSmokeUITests { /// Store screenshots on iPad. It navigates by tab and through /// Explore rather than reusing the iPhone checkpoint: that one drives /// the repo list's `.searchable`, which iPadOS lays out differently, /// and chasing those differences is the iPad pass this release /// deferred. Tabs and a list row work on both. func testIPadScreenshotCheckpoint() throws { signInIfNeeded() snap("dashboard") selectTab("Explore") snap("explore") // First public repo in the list — no search field involved. let firstRepo = app.cells.firstMatch XCTAssertTrue(firstRepo.waitForExistence(timeout: 20), "explore listed nothing") firstRepo.tap() XCTAssertTrue(app.staticTexts["Files"].firstMatch.waitForExistence(timeout: 20), "repo screen did not open") snap("repo") selectTab("Feed") snap("feed") selectTab("My Profile") XCTAssertTrue(app.staticTexts .containing(NSPredicate(format: "label CONTAINS 'Self-Hosting'")).firstMatch .waitForExistence(timeout: 20), "profile did not load") snap("profile") } }