Merge pull request #2405 from manaflow-ai/issue-2388-sidebar-layout-regression
Fix duplicate sidebar git metadata publishes
This commit is contained in:
commit
6e6a2c95b5
3 changed files with 206 additions and 17 deletions
|
|
@ -6,6 +6,7 @@ import WebKit
|
|||
import ObjectiveC.runtime
|
||||
import Bonsplit
|
||||
import UserNotifications
|
||||
import Combine
|
||||
|
||||
#if canImport(cmux_DEV)
|
||||
@testable import cmux_DEV
|
||||
|
|
@ -2111,6 +2112,133 @@ final class WorkspacePanelGitBranchTests: XCTestCase {
|
|||
XCTAssertEqual(ordered.map(\.isDirty), [false, true])
|
||||
}
|
||||
|
||||
func testUpdatingFocusedPanelGitBranchWithSameStateDoesNotRepublishWorkspace() {
|
||||
let workspace = Workspace()
|
||||
guard let panelId = workspace.focusedPanelId else {
|
||||
XCTFail("Expected initial focused panel")
|
||||
return
|
||||
}
|
||||
|
||||
var publishCount = 0
|
||||
let cancellable = workspace.objectWillChange.sink { _ in
|
||||
publishCount += 1
|
||||
}
|
||||
defer { cancellable.cancel() }
|
||||
|
||||
workspace.updatePanelGitBranch(panelId: panelId, branch: "main", isDirty: false)
|
||||
let baselinePublishCount = publishCount
|
||||
|
||||
XCTAssertGreaterThan(
|
||||
baselinePublishCount,
|
||||
0,
|
||||
"Expected the first focused branch update to publish workspace changes"
|
||||
)
|
||||
|
||||
workspace.updatePanelGitBranch(panelId: panelId, branch: "main", isDirty: false)
|
||||
|
||||
XCTAssertEqual(
|
||||
publishCount,
|
||||
baselinePublishCount,
|
||||
"Expected identical focused branch refreshes to avoid extra workspace publishes"
|
||||
)
|
||||
}
|
||||
|
||||
func testUpdatingFocusedPanelPullRequestWithSameStateDoesNotRepublishWorkspace() {
|
||||
let workspace = Workspace()
|
||||
guard let panelId = workspace.focusedPanelId else {
|
||||
XCTFail("Expected initial focused panel")
|
||||
return
|
||||
}
|
||||
|
||||
workspace.updatePanelGitBranch(panelId: panelId, branch: "feature/sidebar-pr", isDirty: false)
|
||||
|
||||
var publishCount = 0
|
||||
let cancellable = workspace.objectWillChange.sink { _ in
|
||||
publishCount += 1
|
||||
}
|
||||
defer { cancellable.cancel() }
|
||||
|
||||
let pullRequestURL = URL(string: "https://github.com/manaflow-ai/cmux/pull/2388")!
|
||||
workspace.updatePanelPullRequest(
|
||||
panelId: panelId,
|
||||
number: 2388,
|
||||
label: "PR",
|
||||
url: pullRequestURL,
|
||||
status: .open,
|
||||
branch: "feature/sidebar-pr"
|
||||
)
|
||||
let baselinePublishCount = publishCount
|
||||
|
||||
XCTAssertGreaterThan(
|
||||
baselinePublishCount,
|
||||
0,
|
||||
"Expected the first focused pull request update to publish workspace changes"
|
||||
)
|
||||
|
||||
workspace.updatePanelPullRequest(
|
||||
panelId: panelId,
|
||||
number: 2388,
|
||||
label: "PR",
|
||||
url: pullRequestURL,
|
||||
status: .open,
|
||||
branch: "feature/sidebar-pr"
|
||||
)
|
||||
|
||||
XCTAssertEqual(
|
||||
publishCount,
|
||||
baselinePublishCount,
|
||||
"Expected identical focused pull request refreshes to avoid extra workspace publishes"
|
||||
)
|
||||
}
|
||||
|
||||
func testSidebarObservationPublisherEmitsForFocusedGitBranchChangesOnlyOncePerState() {
|
||||
let workspace = Workspace()
|
||||
guard let panelId = workspace.focusedPanelId else {
|
||||
XCTFail("Expected initial focused panel")
|
||||
return
|
||||
}
|
||||
|
||||
var publishCount = 0
|
||||
let cancellable = workspace.sidebarObservationPublisher.sink {
|
||||
publishCount += 1
|
||||
}
|
||||
defer { cancellable.cancel() }
|
||||
|
||||
workspace.updatePanelGitBranch(panelId: panelId, branch: "main", isDirty: false)
|
||||
let baselinePublishCount = publishCount
|
||||
XCTAssertGreaterThan(
|
||||
baselinePublishCount,
|
||||
0,
|
||||
"Expected focused git branch updates to invalidate sidebar rows"
|
||||
)
|
||||
|
||||
workspace.updatePanelGitBranch(panelId: panelId, branch: "main", isDirty: false)
|
||||
XCTAssertEqual(
|
||||
publishCount,
|
||||
baselinePublishCount,
|
||||
"Expected identical git metadata refreshes to be ignored by sidebar rows"
|
||||
)
|
||||
}
|
||||
|
||||
func testSidebarObservationPublisherIgnoresRemoteHeartbeatOnlyChanges() {
|
||||
let workspace = Workspace()
|
||||
|
||||
var publishCount = 0
|
||||
let cancellable = workspace.sidebarObservationPublisher.sink {
|
||||
publishCount += 1
|
||||
}
|
||||
defer { cancellable.cancel() }
|
||||
|
||||
workspace.remoteHeartbeatCount = 1
|
||||
workspace.remoteLastHeartbeatAt = Date()
|
||||
|
||||
XCTAssertEqual(
|
||||
publishCount,
|
||||
0,
|
||||
"Expected non-visible remote heartbeat updates to avoid invalidating sidebar rows"
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testSidebarPullRequestsTrackFocusedPanelOnly() {
|
||||
let workspace = Workspace()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue