summaryrefslogtreecommitdiff
path: root/internal/tui/common/keys_test.go
blob: 2c486032e4fa8d4b4a0461a54b24efb69a1ca7e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package common

import "testing"

func TestDefaultKeyMapIncludesDirGroupBinding(t *testing.T) {
	keys := DefaultKeyMap()
	help := keys.DirGroup.Help()
	if help.Key != "d" || help.Desc != "dir group" {
		t.Fatalf("unexpected dir group binding help: key=%q desc=%q", help.Key, help.Desc)
	}

	probesHelp := keys.Probes.Help()
	if probesHelp.Key != "o" || probesHelp.Desc != "probes" {
		t.Fatalf("unexpected probes binding help: key=%q desc=%q", probesHelp.Key, probesHelp.Desc)
	}

	selectHelp := keys.SelectPID.Help()
	if selectHelp.Key != "p" || selectHelp.Desc != "select pid" {
		t.Fatalf("unexpected select pid binding help: key=%q desc=%q", selectHelp.Key, selectHelp.Desc)
	}

	selectTIDHelp := keys.SelectTID.Help()
	if selectTIDHelp.Key != "t" || selectTIDHelp.Desc != "select tid" {
		t.Fatalf("unexpected select tid binding help: key=%q desc=%q", selectTIDHelp.Key, selectTIDHelp.Desc)
	}

	flameHelp := keys.One.Help()
	if flameHelp.Key != "1" || flameHelp.Desc != "flame" {
		t.Fatalf("unexpected flame binding help: key=%q desc=%q", flameHelp.Key, flameHelp.Desc)
	}

	visualizeHelp := keys.Visualize.Help()
	if visualizeHelp.Key != "v" || visualizeHelp.Desc != "viz" {
		t.Fatalf("unexpected visualize binding help: key=%q desc=%q", visualizeHelp.Key, visualizeHelp.Desc)
	}

	metricHelp := keys.Metric.Help()
	if metricHelp.Key != "b" || metricHelp.Desc != "metric" {
		t.Fatalf("unexpected metric binding help: key=%q desc=%q", metricHelp.Key, metricHelp.Desc)
	}

	sortHelp := keys.Sort.Help()
	if sortHelp.Key != "s" || sortHelp.Desc != "sort table" {
		t.Fatalf("unexpected sort binding help: key=%q desc=%q", sortHelp.Key, sortHelp.Desc)
	}
	reverseSortHelp := keys.ReverseSort.Help()
	if reverseSortHelp.Key != "S" || reverseSortHelp.Desc != "reverse sort" {
		t.Fatalf("unexpected reverse sort binding help: key=%q desc=%q", reverseSortHelp.Key, reverseSortHelp.Desc)
	}

	undoHelp := keys.FilterUndo.Help()
	if undoHelp.Key != "F" || undoHelp.Desc != "undo filter" {
		t.Fatalf("unexpected filter undo binding help: key=%q desc=%q", undoHelp.Key, undoHelp.Desc)
	}
}

func TestDashboardFullHelpIncludesDirGroupBinding(t *testing.T) {
	keys := DefaultKeyMap()
	groups := keys.DashboardFullHelp()
	if len(groups) < 2 {
		t.Fatalf("expected at least 2 help groups")
	}

	found := false
	foundOne := false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "d" && help.Desc == "dir group" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected dir group binding in dashboard full help controls")
	}

	for _, binding := range groups[0] {
		help := binding.Help()
		if help.Key == "1" && help.Desc == "flame" {
			foundOne = true
			break
		}
	}
	if !foundOne {
		t.Fatalf("expected flame tab binding in dashboard full help tabs")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "o" && help.Desc == "probes" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected probes binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "p" && help.Desc == "select pid" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected select pid binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "t" && help.Desc == "select tid" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected select tid binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "v" && help.Desc == "viz" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected viz binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "b" && help.Desc == "metric" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected metric binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "s" && help.Desc == "sort table" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected sort binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "S" && help.Desc == "reverse sort" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected reverse sort binding in dashboard full help controls")
	}

	found = false
	for _, binding := range groups[1] {
		help := binding.Help()
		if help.Key == "F" && help.Desc == "undo filter" {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("expected undo filter binding in dashboard full help controls")
	}
}

func TestDashboardStatusHelpIncludesProbesBinding(t *testing.T) {
	keys := DefaultKeyMap()
	short := keys.DashboardStatusHelp()
	found := false
	foundSelectTID := false
	foundOne := false
	foundUndo := false
	foundSort := false
	foundReverseSort := false
	for _, binding := range short {
		help := binding.Help()
		if help.Key == "o" && help.Desc == "probes" {
			found = true
		}
		if help.Key == "t" && help.Desc == "select tid" {
			foundSelectTID = true
		}
		if help.Key == "1" && help.Desc == "flame" {
			foundOne = true
		}
		if help.Key == "F" && help.Desc == "undo filter" {
			foundUndo = true
		}
		if help.Key == "s" && help.Desc == "sort table" {
			foundSort = true
		}
		if help.Key == "S" && help.Desc == "reverse sort" {
			foundReverseSort = true
		}
	}
	if !found {
		t.Fatalf("expected probes binding in dashboard short help")
	}
	if !foundSelectTID {
		t.Fatalf("expected select tid binding in dashboard short help")
	}
	if !foundOne {
		t.Fatalf("expected flame tab binding in dashboard short help")
	}
	if !foundUndo {
		t.Fatalf("expected undo filter binding in dashboard short help")
	}
	if !foundSort {
		t.Fatalf("expected sort binding in dashboard short help")
	}
	if !foundReverseSort {
		t.Fatalf("expected reverse sort binding in dashboard short help")
	}
}