cmux/cmuxTests/WorkspacePullRequestSidebarTests.swift
Austin Wang 55cb5c6763
Fix sidebar workspace PR status display and false positives (#1636)
* test(sidebar): add failing PR checks regressions

* fix(sidebar): show workspace PR status

* refactor(sidebar): restore PR icon style

* refactor(sidebar): simplify PR check labels

* test(sidebar): cover focused workspace PR selection

* fix(sidebar): scope workspace PRs to current branch

* test(sidebar): cover stale PR after branch change

* fix(sidebar): clear stale PRs on branch changes

* test(sidebar): cover workspace PR false positives

* fix(sidebar): stop false-positive workspace PR badges

* test(cmuxTests): remove duplicate sidebar PR regressions
2026-03-17 22:57:12 -07:00

82 lines
2.9 KiB
Swift

import XCTest
#if canImport(cmux_DEV)
@testable import cmux_DEV
#elseif canImport(cmux)
@testable import cmux
#endif
@MainActor
final class WorkspacePullRequestSidebarTests: XCTestCase {
func testSidebarPullRequestsIgnoreStaleWorkspaceLevelCacheWithoutPanelState() throws {
let workspace = Workspace(title: "Test")
let panelId = UUID()
let staleURL = try XCTUnwrap(URL(string: "https://github.com/manaflow-ai/cmux/pull/1640"))
workspace.pullRequest = SidebarPullRequestState(
number: 1640,
label: "PR",
url: staleURL,
status: .open,
branch: "main"
)
workspace.gitBranch = SidebarGitBranchState(branch: "main", isDirty: false)
XCTAssertEqual(workspace.sidebarPullRequestsInDisplayOrder(orderedPanelIds: [panelId]), [])
}
func testSidebarPullRequestsFilterBranchMismatchPerPanel() throws {
let workspace = Workspace(title: "Test")
let panelId = UUID()
let staleURL = try XCTUnwrap(URL(string: "https://github.com/manaflow-ai/cmux/pull/1640"))
workspace.panelGitBranches[panelId] = SidebarGitBranchState(branch: "main", isDirty: false)
workspace.panelPullRequests[panelId] = SidebarPullRequestState(
number: 1640,
label: "PR",
url: staleURL,
status: .open,
branch: "feature/old"
)
XCTAssertEqual(workspace.sidebarPullRequestsInDisplayOrder(orderedPanelIds: [panelId]), [])
}
func testSidebarPullRequestsPreferBestStateAcrossPanels() throws {
let workspace = Workspace(title: "Test")
let firstPanelId = UUID()
let secondPanelId = UUID()
let url = try XCTUnwrap(URL(string: "https://github.com/manaflow-ai/cmux/pull/1640"))
workspace.panelGitBranches[firstPanelId] = SidebarGitBranchState(branch: "feature/work", isDirty: false)
workspace.panelGitBranches[secondPanelId] = SidebarGitBranchState(branch: "feature/work", isDirty: false)
workspace.panelPullRequests[firstPanelId] = SidebarPullRequestState(
number: 1640,
label: "PR",
url: url,
status: .open,
branch: "feature/work",
checks: .pass
)
workspace.panelPullRequests[secondPanelId] = SidebarPullRequestState(
number: 1640,
label: "PR",
url: url,
status: .merged,
branch: "feature/work"
)
XCTAssertEqual(
workspace.sidebarPullRequestsInDisplayOrder(orderedPanelIds: [firstPanelId, secondPanelId]),
[
SidebarPullRequestState(
number: 1640,
label: "PR",
url: url,
status: .merged,
branch: "feature/work"
)
]
)
}
}