adds nice git interface
This commit is contained in:
@@ -26,26 +26,26 @@ private struct MemorySession: SessionStoring {
|
||||
#expect(layout.widths.explorer == 520)
|
||||
}
|
||||
|
||||
@Test func sourceControlDragsStayInsideTheirRange() {
|
||||
@Test func explorerDragsStayInsideTheirRange() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
layout.dragSourceControl(by: -1000)
|
||||
#expect(layout.widths.sourceControl == 160)
|
||||
layout.dragSourceControl(by: 5000)
|
||||
#expect(layout.widths.sourceControl == 460)
|
||||
layout.dragExplorer(by: -1000)
|
||||
#expect(layout.widths.explorer == 160)
|
||||
layout.dragExplorer(by: 5000)
|
||||
#expect(layout.widths.explorer == 520)
|
||||
}
|
||||
|
||||
@Test func theAgentColumnNeverSqueezesTheEditorBelowItsMinimum() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
layout.windowResized(width: 1760)
|
||||
layout.dragAgent(by: -5000)
|
||||
let editor = 1760 - 3 - layout.widths.sourceControl - layout.widths.explorer - layout.widths.agent
|
||||
let editor = 1760 - 2 - layout.widths.explorer - layout.widths.agent
|
||||
#expect(editor >= ColumnLayout.minEditorWidth)
|
||||
}
|
||||
|
||||
@Test func roomyWindowsUseTheDesignProportions() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
layout.windowResized(width: 1760)
|
||||
#expect(layout.widths == ColumnWidths(sourceControl: 236, explorer: 289, agent: 480))
|
||||
#expect(layout.widths == ColumnWidths(explorer: 289, agent: 480))
|
||||
}
|
||||
|
||||
@Test func focusChangesTheFluidWidthsOnlyBelow1600() {
|
||||
@@ -75,19 +75,44 @@ private struct MemorySession: SessionStoring {
|
||||
layout.windowResized(width: 1760)
|
||||
layout.dragExplorer(by: 0)
|
||||
layout.windowResized(width: 1100)
|
||||
let total = layout.widths.sourceControl + layout.widths.explorer + layout.widths.agent
|
||||
#expect(total <= 1100 - 3 - ColumnLayout.minEditorWidth)
|
||||
layout.windowResized(width: 900)
|
||||
let total = layout.widths.explorer + layout.widths.agent
|
||||
#expect(total <= 900 - 2 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
|
||||
@Test func hidingGitDropsItsFocus() {
|
||||
@Test func hidingTheExplorerDropsItsFocus() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
layout.focus(.sourceControl)
|
||||
layout.togglePane(.sourceControl)
|
||||
layout.focus(.explorer)
|
||||
layout.togglePane(.explorer)
|
||||
#expect(layout.activePanel == nil)
|
||||
layout.focus(.sourceControl)
|
||||
layout.focus(.explorer)
|
||||
#expect(layout.activePanel == nil)
|
||||
}
|
||||
|
||||
@Test func theGitViewOpensClosesAndToggles() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
#expect(!layout.isGitViewOpen)
|
||||
layout.openGitView()
|
||||
#expect(layout.isGitViewOpen)
|
||||
layout.closeGitView()
|
||||
#expect(!layout.isGitViewOpen)
|
||||
layout.toggleGitView()
|
||||
#expect(layout.isGitViewOpen)
|
||||
layout.toggleGitView()
|
||||
#expect(!layout.isGitViewOpen)
|
||||
}
|
||||
|
||||
@Test func theGitViewIsNeitherSavedNorKeptAcrossAProjectSwitch() {
|
||||
let store = FakeLayouts()
|
||||
let layout = LayoutStore(session: MemorySession(), persistence: store)
|
||||
layout.restore(root: "/p")
|
||||
layout.openGitView()
|
||||
#expect(store.saved["/p"] == nil)
|
||||
layout.restore(root: "/q")
|
||||
#expect(!layout.isGitViewOpen)
|
||||
#expect(layout.visibility == .all)
|
||||
}
|
||||
|
||||
@Test func aProjectsColumnsSurviveARestart() {
|
||||
let store = FakeLayouts()
|
||||
let first = LayoutStore(session: MemorySession(), persistence: store)
|
||||
@@ -95,13 +120,13 @@ private struct MemorySession: SessionStoring {
|
||||
first.windowResized(width: 1760)
|
||||
first.dragExplorer(by: 40)
|
||||
first.endDrag()
|
||||
first.togglePane(.sourceControl)
|
||||
first.togglePane(.terminal)
|
||||
|
||||
let second = LayoutStore(session: MemorySession(), persistence: store)
|
||||
second.windowResized(width: 1760)
|
||||
second.restore(root: "/p")
|
||||
#expect(!second.fluid)
|
||||
#expect(!second.isVisible(.sourceControl))
|
||||
#expect(!second.isVisible(.terminal))
|
||||
#expect(second.widths.explorer == first.widths.explorer)
|
||||
#expect(second.widths.agent == first.widths.agent)
|
||||
}
|
||||
@@ -110,11 +135,11 @@ private struct MemorySession: SessionStoring {
|
||||
let store = FakeLayouts()
|
||||
let layout = LayoutStore(session: MemorySession(), persistence: store)
|
||||
layout.restore(root: "/a")
|
||||
layout.togglePane(.sourceControl)
|
||||
layout.togglePane(.explorer)
|
||||
layout.restore(root: "/b")
|
||||
#expect(layout.isVisible(.sourceControl))
|
||||
#expect(layout.isVisible(.explorer))
|
||||
layout.restore(root: "/a")
|
||||
#expect(!layout.isVisible(.sourceControl))
|
||||
#expect(!layout.isVisible(.explorer))
|
||||
}
|
||||
|
||||
@Test func dragsSaveOnlyWhenTheyEnd() {
|
||||
@@ -140,22 +165,22 @@ private struct MemorySession: SessionStoring {
|
||||
@Test func aWindowXMapsToTheColumnUnderIt() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
layout.windowResized(width: 1760)
|
||||
#expect(layout.panel(atX: 10) == .sourceControl)
|
||||
#expect(layout.panel(atX: 300) == .explorer)
|
||||
#expect(layout.panel(atX: 10) == .explorer)
|
||||
#expect(layout.panel(atX: 900) == .editor)
|
||||
#expect(layout.panel(atX: 1700) == .terminal)
|
||||
#expect(layout.panel(atX: 236, splitterMargin: 4) == nil)
|
||||
layout.togglePane(.sourceControl)
|
||||
#expect(layout.panel(atX: 10) == .explorer)
|
||||
#expect(layout.panel(atX: 289, splitterMargin: 4) == nil)
|
||||
layout.togglePane(.explorer)
|
||||
#expect(layout.panel(atX: 10) == .editor)
|
||||
}
|
||||
|
||||
@Test func neighbourColumnsClampAtTheEdgesAndSkipAHiddenGitColumn() {
|
||||
@Test func neighbourColumnsClampAtTheEdgesAndSkipAHiddenColumn() {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
#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.togglePane(.sourceControl)
|
||||
#expect(layout.neighbour(of: .explorer, step: -1) == .explorer)
|
||||
#expect(layout.neighbour(of: .editor, step: -1) == .explorer)
|
||||
layout.togglePane(.explorer)
|
||||
#expect(layout.neighbour(of: .editor, step: -1) == .editor)
|
||||
}
|
||||
|
||||
@Test func everyPaneStartsShownAndTogglesOnItsOwn() {
|
||||
@@ -163,8 +188,8 @@ private struct MemorySession: SessionStoring {
|
||||
#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])
|
||||
#expect(layout.visibility == ColumnVisibility(explorer: false, editor: true, agent: false))
|
||||
#expect(layout.columns == [.editor])
|
||||
layout.togglePane(.terminal)
|
||||
#expect(layout.isVisible(.terminal))
|
||||
}
|
||||
@@ -181,7 +206,7 @@ private struct MemorySession: SessionStoring {
|
||||
#expect(layout.activePanel == .editor)
|
||||
}
|
||||
|
||||
@Test func allFourPaneFlagsSurviveARestart() {
|
||||
@Test func allThreePaneFlagsSurviveARestart() {
|
||||
let store = FakeLayouts()
|
||||
let first = LayoutStore(session: MemorySession(), persistence: store)
|
||||
first.restore(root: "/p")
|
||||
@@ -191,20 +216,43 @@ private struct MemorySession: SessionStoring {
|
||||
|
||||
let second = LayoutStore(session: MemorySession(), persistence: store)
|
||||
second.restore(root: "/p")
|
||||
#expect(second.visibility == ColumnVisibility(sourceControl: true, explorer: false, editor: false, agent: false))
|
||||
#expect(second.visibility == ColumnVisibility(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.visibility == .all)
|
||||
#expect(snapshot.explorerWidth == 300)
|
||||
#expect(snapshot.agentWidth == 500)
|
||||
#expect(!snapshot.fluid)
|
||||
}
|
||||
|
||||
@Test func aSnapshotFromTheGitColumnDaysKeepsItsPaneFlags() throws {
|
||||
let json = #"{"sourceControlWidth":240,"explorerWidth":300,"agentWidth":500,"fluid":true,"gitVisible":true,"#
|
||||
+ #""explorerVisible":false,"fileVisible":true,"claudeVisible":false}"#
|
||||
let snapshot = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: Data(json.utf8))
|
||||
#expect(snapshot.visibility == ColumnVisibility(explorer: false, editor: true, agent: false))
|
||||
#expect(snapshot.fluid)
|
||||
}
|
||||
|
||||
@Test func aSnapshotWithoutTheGitKeysLoads() throws {
|
||||
let json = #"{"explorerWidth":300,"agentWidth":500,"fluid":false,"explorerVisible":true,"fileVisible":false,"claudeVisible":true}"#
|
||||
let snapshot = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: Data(json.utf8))
|
||||
#expect(snapshot.visibility == ColumnVisibility(explorer: true, editor: false, agent: true))
|
||||
#expect(snapshot.explorerWidth == 300)
|
||||
}
|
||||
|
||||
@Test func aSavedSnapshotNoLongerWritesTheGitKeys() throws {
|
||||
let data = try JSONEncoder().encode(ColumnLayoutSnapshot(explorerWidth: 288, agentWidth: 480, fluid: true))
|
||||
let keys = try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any]).keys
|
||||
#expect(!keys.contains("sourceControlWidth"))
|
||||
#expect(!keys.contains("gitVisible"))
|
||||
}
|
||||
|
||||
@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 visibility = ColumnVisibility(explorer: false, editor: true, agent: false)
|
||||
let snapshot = ColumnLayoutSnapshot(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)
|
||||
@@ -214,9 +262,9 @@ private struct MemorySession: SessionStoring {
|
||||
let layout = LayoutStore(session: MemorySession())
|
||||
layout.windowResized(width: 1760)
|
||||
layout.togglePane(.editor)
|
||||
#expect(layout.columns == [.sourceControl, .explorer, .terminal])
|
||||
#expect(layout.columns == [.explorer, .terminal])
|
||||
#expect(layout.span(of: .editor) == nil)
|
||||
let agentStart = layout.widths.sourceControl + 1 + layout.widths.explorer + 1
|
||||
let agentStart = layout.widths.explorer + 1
|
||||
#expect(layout.span(of: .terminal) == agentStart...1760)
|
||||
#expect(layout.panel(atX: 1000) == .terminal)
|
||||
}
|
||||
@@ -225,7 +273,6 @@ private struct MemorySession: SessionStoring {
|
||||
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)
|
||||
@@ -244,9 +291,8 @@ private struct MemorySession: SessionStoring {
|
||||
@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)
|
||||
#expect(layout.neighbour(of: .explorer, step: 1) == .terminal)
|
||||
#expect(layout.neighbour(of: .terminal, step: -1) == .explorer)
|
||||
}
|
||||
|
||||
@Test func theAgentMayGrowIntoTheRoomAHiddenExplorerLeaves() {
|
||||
@@ -254,6 +300,6 @@ private struct MemorySession: SessionStoring {
|
||||
layout.windowResized(width: 1760)
|
||||
layout.togglePane(.explorer)
|
||||
layout.dragAgent(by: -5000)
|
||||
#expect(layout.widths.agent == 1760 - 2 - layout.widths.sourceControl - ColumnLayout.minEditorWidth)
|
||||
#expect(layout.widths.agent == 1760 - 1 - ColumnLayout.minEditorWidth)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user