Improves helder
This commit is contained in:
@@ -13,7 +13,52 @@ import Testing
|
||||
}
|
||||
|
||||
@Test func fittingKeepsTheEditorMinimum() {
|
||||
let fitted = ColumnLayout.fitted(ColumnWidths(sourceControl: 400, explorer: 400, agent: 400), windowWidth: 1000, sourceControlVisible: true)
|
||||
let fitted = ColumnLayout.fitted(ColumnWidths(sourceControl: 400, explorer: 400, agent: 400), windowWidth: 1000, visible: .all)
|
||||
#expect(fitted.sourceControl + fitted.explorer + fitted.agent <= 1000 - 3 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
|
||||
@Test func aHiddenColumnIsNeitherCountedNorScaled() {
|
||||
let widths = ColumnWidths(sourceControl: 400, explorer: 400, agent: 400)
|
||||
let visible = ColumnVisibility(sourceControl: false)
|
||||
let fitted = ColumnLayout.fitted(widths, windowWidth: 1000, visible: visible)
|
||||
#expect(fitted.sourceControl == 400)
|
||||
#expect(fitted.explorer + fitted.agent <= 1000 - 2 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
|
||||
@Test func withTheEditorHiddenTheAgentIsTheFlexColumn() {
|
||||
let widths = ColumnWidths(sourceControl: 400, explorer: 400, agent: 900)
|
||||
let fitted = ColumnLayout.fitted(widths, windowWidth: 1000, visible: ColumnVisibility(editor: false))
|
||||
#expect(fitted.agent == 900)
|
||||
#expect(fitted.sourceControl + fitted.explorer <= 1000 - 2 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
|
||||
@Test func withoutAFlexColumnTheFixedOnesOnlyHaveToFitTheWindow() {
|
||||
let widths = ColumnWidths(sourceControl: 300, explorer: 300, agent: 480)
|
||||
let visible = ColumnVisibility(editor: false, agent: false)
|
||||
#expect(ColumnLayout.fitted(widths, windowWidth: 1000, visible: visible) == widths)
|
||||
let narrow = ColumnLayout.fitted(widths, windowWidth: 501, visible: visible)
|
||||
#expect(narrow.sourceControl + narrow.explorer <= 500)
|
||||
#expect(narrow.agent == 480)
|
||||
}
|
||||
|
||||
@Test func fittingWithOnlyTheAgentBesideTheEditor() {
|
||||
let widths = ColumnWidths(sourceControl: 300, explorer: 300, agent: 900)
|
||||
let fitted = ColumnLayout.fitted(widths, windowWidth: 1000, visible: ColumnVisibility(sourceControl: false, explorer: false))
|
||||
#expect(fitted.sourceControl == 300)
|
||||
#expect(fitted.agent <= 1000 - 1 - ColumnLayout.minEditorWidth)
|
||||
#expect(fitted.agent >= 1000 - 2 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
|
||||
@Test func splittersSitOnlyBetweenVisibleColumns() {
|
||||
#expect(ColumnVisibility.all.splitterCount == 3)
|
||||
#expect(ColumnVisibility(sourceControl: false, editor: false).splitterCount == 1)
|
||||
#expect(ColumnVisibility(sourceControl: false, explorer: false, editor: false, agent: false).splitterCount == 0)
|
||||
}
|
||||
|
||||
@Test func theAgentLimitCountsOnlyVisibleColumns() {
|
||||
let widths = ColumnWidths(sourceControl: 300, explorer: 300, agent: 480)
|
||||
#expect(ColumnLayout.maxAgentWidth(windowWidth: 1600, widths: widths, visible: .all) == 1600 - 3 - 600 - ColumnLayout.minEditorWidth)
|
||||
#expect(ColumnLayout.maxAgentWidth(windowWidth: 1600, widths: widths, visible: ColumnVisibility(explorer: false))
|
||||
== 1600 - 2 - 300 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,11 +476,27 @@ import Testing
|
||||
let harness = WorkspaceHarness()
|
||||
await harness.start()
|
||||
harness.model.perform(.toggleGit)
|
||||
#expect(!harness.model.layout.isVisible(.sourceControl))
|
||||
harness.model.perform(.focusCommitMessage)
|
||||
#expect(harness.model.layout.gitVisible)
|
||||
#expect(harness.model.layout.isVisible(.sourceControl))
|
||||
#expect(harness.model.focusRequest?.target == .commitMessage)
|
||||
}
|
||||
|
||||
@Test func aPaneToggleHidesItsColumnAndAHiddenColumnTakesNoFocus() async {
|
||||
let harness = WorkspaceHarness()
|
||||
await harness.start()
|
||||
harness.model.perform(.focus(.terminal))
|
||||
harness.model.perform(.togglePane(.terminal))
|
||||
#expect(!harness.model.layout.isVisible(.terminal))
|
||||
#expect(harness.model.layout.activePanel == nil)
|
||||
harness.model.perform(.focus(.editor))
|
||||
harness.model.perform(.focus(.terminal))
|
||||
#expect(harness.model.layout.activePanel == .editor)
|
||||
#expect(harness.model.focusRequest?.target == .panel(.editor))
|
||||
harness.model.perform(.togglePane(.terminal))
|
||||
#expect(harness.model.layout.isVisible(.terminal))
|
||||
}
|
||||
|
||||
@Test func rowCursorKeysDriveTheFocusedList() async {
|
||||
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false), ("b.php", .added, true)]),
|
||||
contents: ["a.php": "", "b.php": ""])
|
||||
|
||||
Reference in New Issue
Block a user