Skip to content

Commit 670ba6e

Browse files
committed
Add tests for window arrangement code
The output of the GetWindowDimensions function is hard to understand just by looking at it, so I've added a helper function in the tests to render the window layout as text, so that in order to create a new test you just come up with some args and paste the output as the expected output. This has the same downsides that any snapshot-based testing has: it's more brittle than targeted assertions. But it is much easier to make sense of these snapshots than it is to make sense of more fine-grained assertions, and I like the fact that these tests can serve as documentation.
1 parent b50ea9b commit 670ba6e

File tree

2 files changed

+364
-22
lines changed

2 files changed

+364
-22
lines changed

pkg/gui/controllers/helpers/window_arrangement_helper.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
125125
sidePanelsDirection = boxlayout.ROW
126126
}
127127

128-
mainPanelsDirection := boxlayout.ROW
129-
if splitMainPanelSideBySide(args) {
130-
mainPanelsDirection = boxlayout.COLUMN
131-
}
132-
133-
extrasWindowSize := getExtrasWindowSize(args)
134-
135128
showInfoSection := args.UserConfig.Gui.ShowBottomLine ||
136129
args.InSearchPrompt ||
137130
args.IsAnyModeActive ||
@@ -156,17 +149,7 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
156149
{
157150
Direction: boxlayout.ROW,
158151
Weight: mainSectionWeight,
159-
Children: []*boxlayout.Box{
160-
{
161-
Direction: mainPanelsDirection,
162-
Children: mainSectionChildren(args),
163-
Weight: 1,
164-
},
165-
{
166-
Window: "extras",
167-
Size: extrasWindowSize,
168-
},
169-
},
152+
Children: mainPanelChildren(args),
170153
},
171154
},
172155
},
@@ -184,6 +167,28 @@ func GetWindowDimensions(args WindowArrangementArgs) map[string]boxlayout.Dimens
184167
return MergeMaps(layerOneWindows, limitWindows)
185168
}
186169

170+
func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
171+
mainPanelsDirection := boxlayout.ROW
172+
if splitMainPanelSideBySide(args) {
173+
mainPanelsDirection = boxlayout.COLUMN
174+
}
175+
176+
result := []*boxlayout.Box{
177+
{
178+
Direction: mainPanelsDirection,
179+
Children: mainSectionChildren(args),
180+
Weight: 1,
181+
},
182+
}
183+
if args.ShowExtrasWindow {
184+
result = append(result, &boxlayout.Box{
185+
Window: "extras",
186+
Size: getExtrasWindowSize(args),
187+
})
188+
}
189+
return result
190+
}
191+
187192
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
188193
result := map[K]V{}
189194
for _, currMap := range maps {
@@ -368,10 +373,6 @@ func splitMainPanelSideBySide(args WindowArrangementArgs) bool {
368373
}
369374

370375
func getExtrasWindowSize(args WindowArrangementArgs) int {
371-
if !args.ShowExtrasWindow {
372-
return 0
373-
}
374-
375376
var baseSize int
376377
// The 'extras' window contains the command log context
377378
if args.CurrentStaticWindow == "extras" {

0 commit comments

Comments
 (0)