v0.26.1 75cd777

transform_legacy_test.go RawHistoryFolder

1package config
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7	"github.com/stretchr/testify/require"
8)
9
10func TestTransformLegacyActions_SliceFormat(t *testing.T) {
11	transformer := NewLegacyConfigTransformer()
12
13	rawConfig := map[string]any{
14		"workspace": map[string]any{
15			"pane_mode": map[string]any{
16				"actions": map[string]any{
17					"focus-left": []any{"h", "arrowleft"},
18				},
19			},
20		},
21	}
22
23	transformer.TransformLegacyActions(rawConfig)
24
25	actions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
26	binding, ok := actions["focus-left"].(map[string]any)
27	require.True(t, ok, "should be converted to map")
28
29	keys, ok := binding["keys"].([]string)
30	require.True(t, ok, "keys should be []string")
31	assert.Equal(t, []string{"h", "arrowleft"}, keys)
32	assert.NotEmpty(t, binding["desc"], "should have description from defaults")
33}
34
35func TestTransformLegacyActions_AllModes(t *testing.T) {
36	transformer := NewLegacyConfigTransformer()
37
38	rawConfig := map[string]any{
39		"workspace": map[string]any{
40			"pane_mode": map[string]any{
41				"actions": map[string]any{
42					"focus-left": []any{"h"},
43				},
44			},
45			"tab_mode": map[string]any{
46				"actions": map[string]any{
47					"next-tab": []any{"l"},
48				},
49			},
50			"resize_mode": map[string]any{
51				"actions": map[string]any{
52					"resize-increase": []any{"+"},
53				},
54			},
55			"shortcuts": map[string]any{
56				"actions": map[string]any{
57					"close_pane": []any{"ctrl+w"},
58				},
59			},
60		},
61		"session": map[string]any{
62			"session_mode": map[string]any{
63				"actions": map[string]any{
64					"session-manager": []any{"m"},
65				},
66			},
67		},
68	}
69
70	transformer.TransformLegacyActions(rawConfig)
71
72	// Check pane mode
73	paneActions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
74	paneFocus, ok := paneActions["focus-left"].(map[string]any)
75	require.True(t, ok)
76	assert.Equal(t, []string{"h"}, paneFocus["keys"])
77
78	// Check tab mode
79	tabActions := rawConfig["workspace"].(map[string]any)["tab_mode"].(map[string]any)["actions"].(map[string]any)
80	tabNext, ok := tabActions["next-tab"].(map[string]any)
81	require.True(t, ok)
82	assert.Equal(t, []string{"l"}, tabNext["keys"])
83
84	// Check resize mode
85	resizeActions := rawConfig["workspace"].(map[string]any)["resize_mode"].(map[string]any)["actions"].(map[string]any)
86	resizeInc, ok := resizeActions["resize-increase"].(map[string]any)
87	require.True(t, ok)
88	assert.Equal(t, []string{"+"}, resizeInc["keys"])
89
90	// Check shortcuts
91	shortcutActions := rawConfig["workspace"].(map[string]any)["shortcuts"].(map[string]any)["actions"].(map[string]any)
92	closePane, ok := shortcutActions["close_pane"].(map[string]any)
93	require.True(t, ok)
94	assert.Equal(t, []string{"ctrl+w"}, closePane["keys"])
95
96	// Check session mode
97	sessionActions := rawConfig["session"].(map[string]any)["session_mode"].(map[string]any)["actions"].(map[string]any)
98	sessionMgr, ok := sessionActions["session-manager"].(map[string]any)
99	require.True(t, ok)
100	assert.Equal(t, []string{"m"}, sessionMgr["keys"])
101}
102
103func TestTransformLegacyActions_AlreadyNewFormat(t *testing.T) {
104	transformer := NewLegacyConfigTransformer()
105
106	rawConfig := map[string]any{
107		"workspace": map[string]any{
108			"pane_mode": map[string]any{
109				"actions": map[string]any{
110					"focus-left": map[string]any{
111						"keys": []string{"h"},
112						"desc": "Custom description",
113					},
114				},
115			},
116		},
117	}
118
119	transformer.TransformLegacyActions(rawConfig)
120
121	actions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
122	binding := actions["focus-left"].(map[string]any)
123
124	// Should remain unchanged
125	assert.Equal(t, "Custom description", binding["desc"])
126}
127
128func TestTransformLegacyActions_MissingSection(t *testing.T) {
129	transformer := NewLegacyConfigTransformer()
130
131	rawConfig := map[string]any{
132		"appearance": map[string]any{
133			"theme": "dark",
134		},
135	}
136
137	// Should not panic
138	transformer.TransformLegacyActions(rawConfig)
139
140	// Config should be unchanged
141	assert.Equal(t, "dark", rawConfig["appearance"].(map[string]any)["theme"])
142}
143
144func TestTransformLegacyActions_EmptyConfig(t *testing.T) {
145	transformer := NewLegacyConfigTransformer()
146
147	rawConfig := map[string]any{}
148
149	// Should not panic
150	transformer.TransformLegacyActions(rawConfig)
151
152	assert.Empty(t, rawConfig)
153}
154
155func TestTransformLegacyActions_PartialPath(t *testing.T) {
156	transformer := NewLegacyConfigTransformer()
157
158	rawConfig := map[string]any{
159		"workspace": map[string]any{
160			"pane_mode": map[string]any{
161				// actions section missing
162			},
163		},
164	}
165
166	// Should not panic
167	transformer.TransformLegacyActions(rawConfig)
168
169	// Verify config is unchanged
170	require.NotNil(t, rawConfig["workspace"])
171}
172
173func TestTransformLegacyActions_UnknownAction(t *testing.T) {
174	transformer := NewLegacyConfigTransformer()
175
176	rawConfig := map[string]any{
177		"workspace": map[string]any{
178			"pane_mode": map[string]any{
179				"actions": map[string]any{
180					"unknown-action": []any{"x"},
181				},
182			},
183		},
184	}
185
186	transformer.TransformLegacyActions(rawConfig)
187
188	actions := rawConfig["workspace"].(map[string]any)["pane_mode"].(map[string]any)["actions"].(map[string]any)
189	binding, ok := actions["unknown-action"].(map[string]any)
190	require.True(t, ok)
191	assert.Equal(t, []string{"x"}, binding["keys"])
192	assert.Empty(t, binding["desc"], "unknown action should have empty description")
193}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close