Improves helder

This commit is contained in:
2026-10-05 09:24:25 +02:00
parent 8fafea4fc3
commit 336987d821
44 changed files with 3454 additions and 542 deletions
@@ -1,6 +1,7 @@
import HelderCore
import HelderServices
@testable import HelderUI
import Foundation
import Testing
private struct MemorySession: SessionStoring {
@@ -81,7 +82,7 @@ private struct MemorySession: SessionStoring {
@Test func hidingGitDropsItsFocus() {
let layout = LayoutStore(session: MemorySession())
layout.focus(.sourceControl)
layout.toggleGit()
layout.togglePane(.sourceControl)
#expect(layout.activePanel == nil)
layout.focus(.sourceControl)
#expect(layout.activePanel == nil)
@@ -94,13 +95,13 @@ private struct MemorySession: SessionStoring {
first.windowResized(width: 1760)
first.dragExplorer(by: 40)
first.endDrag()
first.toggleGit()
first.togglePane(.sourceControl)
let second = LayoutStore(session: MemorySession(), persistence: store)
second.windowResized(width: 1760)
second.restore(root: "/p")
#expect(!second.fluid)
#expect(!second.gitVisible)
#expect(!second.isVisible(.sourceControl))
#expect(second.widths.explorer == first.widths.explorer)
#expect(second.widths.agent == first.widths.agent)
}
@@ -109,11 +110,11 @@ private struct MemorySession: SessionStoring {
let store = FakeLayouts()
let layout = LayoutStore(session: MemorySession(), persistence: store)
layout.restore(root: "/a")
layout.toggleGit()
layout.togglePane(.sourceControl)
layout.restore(root: "/b")
#expect(layout.gitVisible)
#expect(layout.isVisible(.sourceControl))
layout.restore(root: "/a")
#expect(!layout.gitVisible)
#expect(!layout.isVisible(.sourceControl))
}
@Test func dragsSaveOnlyWhenTheyEnd() {
@@ -144,7 +145,7 @@ private struct MemorySession: SessionStoring {
#expect(layout.panel(atX: 900) == .editor)
#expect(layout.panel(atX: 1700) == .terminal)
#expect(layout.panel(atX: 236, splitterMargin: 4) == nil)
layout.toggleGit()
layout.togglePane(.sourceControl)
#expect(layout.panel(atX: 10) == .explorer)
}
@@ -153,7 +154,106 @@ private struct MemorySession: SessionStoring {
#expect(layout.neighbour(of: nil, step: 1) == .terminal)
#expect(layout.neighbour(of: .terminal, step: 1) == .terminal)
#expect(layout.neighbour(of: .explorer, step: -1) == .sourceControl)
layout.toggleGit()
layout.togglePane(.sourceControl)
#expect(layout.neighbour(of: .explorer, step: -1) == .explorer)
}
@Test func everyPaneStartsShownAndTogglesOnItsOwn() {
let layout = LayoutStore(session: MemorySession())
#expect(layout.visibility == .all)
layout.togglePane(.explorer)
layout.togglePane(.terminal)
#expect(layout.visibility == ColumnVisibility(sourceControl: true, explorer: false, editor: true, agent: false))
#expect(layout.columns == [.sourceControl, .editor])
layout.togglePane(.terminal)
#expect(layout.isVisible(.terminal))
}
@Test func hidingAFocusedPaneDropsItsFocusAndAHiddenPaneTakesNone() {
let layout = LayoutStore(session: MemorySession())
layout.focus(.terminal)
layout.togglePane(.terminal)
#expect(layout.activePanel == nil)
layout.focus(.terminal)
#expect(layout.activePanel == nil)
layout.focus(.editor)
layout.togglePane(.explorer)
#expect(layout.activePanel == .editor)
}
@Test func allFourPaneFlagsSurviveARestart() {
let store = FakeLayouts()
let first = LayoutStore(session: MemorySession(), persistence: store)
first.restore(root: "/p")
first.togglePane(.explorer)
first.togglePane(.editor)
first.togglePane(.terminal)
let second = LayoutStore(session: MemorySession(), persistence: store)
second.restore(root: "/p")
#expect(second.visibility == ColumnVisibility(sourceControl: true, explorer: false, editor: false, agent: false))
}
@Test func anOlderSnapshotWithOnlyTheGitFlagStillLoads() throws {
let json = #"{"sourceControlWidth":240,"explorerWidth":300,"agentWidth":500,"fluid":false,"gitVisible":false}"#
let snapshot = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: Data(json.utf8))
#expect(snapshot.visibility == ColumnVisibility(sourceControl: false, explorer: true, editor: true, agent: true))
#expect(snapshot.explorerWidth == 300)
#expect(!snapshot.fluid)
}
@Test func aSnapshotRoundTripsItsPaneFlags() throws {
let visibility = ColumnVisibility(sourceControl: true, explorer: false, editor: true, agent: false)
let snapshot = ColumnLayoutSnapshot(sourceControlWidth: 236, explorerWidth: 288, agentWidth: 480, fluid: true, visibility: visibility)
let decoded = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: JSONEncoder().encode(snapshot))
#expect(decoded == snapshot)
#expect(decoded.visibility == visibility)
}
@Test func withTheEditorHiddenTheAgentColumnFillsTheRest() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
layout.togglePane(.editor)
#expect(layout.columns == [.sourceControl, .explorer, .terminal])
#expect(layout.span(of: .editor) == nil)
let agentStart = layout.widths.sourceControl + 1 + layout.widths.explorer + 1
#expect(layout.span(of: .terminal) == agentStart...1760)
#expect(layout.panel(atX: 1000) == .terminal)
}
@Test func withTheAgentHiddenTheEditorReachesTheWindowEdge() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
layout.togglePane(.terminal)
layout.togglePane(.sourceControl)
#expect(layout.span(of: .explorer) == 0...layout.widths.explorer)
#expect(layout.span(of: .editor) == (layout.widths.explorer + 1)...1760)
#expect(layout.span(of: .terminal) == nil)
#expect(layout.panel(atX: 1700) == .editor)
}
@Test func withEveryPaneHiddenNothingIsUnderThePointer() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
for panel in Panel.allCases { layout.togglePane(panel) }
#expect(layout.columns.isEmpty)
#expect(layout.panel(atX: 500) == nil)
#expect(layout.neighbour(of: .editor, step: 1) == .editor)
}
@Test func neighboursSkipEveryHiddenPane() {
let layout = LayoutStore(session: MemorySession())
layout.togglePane(.editor)
layout.togglePane(.explorer)
#expect(layout.neighbour(of: .sourceControl, step: 1) == .terminal)
#expect(layout.neighbour(of: .terminal, step: -1) == .sourceControl)
}
@Test func theAgentMayGrowIntoTheRoomAHiddenExplorerLeaves() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
layout.togglePane(.explorer)
layout.dragAgent(by: -5000)
#expect(layout.widths.agent == 1760 - 2 - layout.widths.sourceControl - ColumnLayout.minEditorWidth)
}
}