MCPcopy Create free account
hub / github.com/cli/cli / TestHuhPrompterMultiSelect

Function TestHuhPrompterMultiSelect

internal/prompter/huh_prompter_test.go:258–314  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

256}
257
258func TestHuhPrompterMultiSelect(t *testing.T) {
259 tests := []struct {
260 name string
261 options []string
262 defaults []string
263 ix interaction
264 wantResult []int
265 }{
266 {
267 name: "no defaults and no toggles returns empty",
268 options: []string{"a", "b", "c"},
269 ix: newInteraction(enter()),
270 wantResult: []int{},
271 },
272 {
273 name: "defaults are pre-selected",
274 options: []string{"a", "b", "c"},
275 defaults: []string{"a", "c"},
276 ix: newInteraction(enter()),
277 wantResult: []int{0, 2},
278 },
279 {
280 name: "toggle first option",
281 options: []string{"a", "b", "c"},
282 ix: newInteraction(toggle(), enter()),
283 wantResult: []int{0},
284 },
285 {
286 name: "toggle multiple options",
287 options: []string{"a", "b", "c"},
288 ix: newInteraction(
289 toggle(), // toggle a
290 down(), // move to b
291 down(), // move to c
292 toggle(), // toggle c
293 enter(),
294 ),
295 wantResult: []int{0, 2},
296 },
297 {
298 name: "invalid defaults are excluded",
299 options: []string{"a", "b"},
300 defaults: []string{"z"},
301 ix: newInteraction(enter()),
302 wantResult: []int{},
303 },
304 }
305
306 for _, tt := range tests {
307 t.Run(tt.name, func(t *testing.T) {
308 p := newTestHuhPrompter()
309 f, result := p.buildMultiSelectForm("Pick:", tt.defaults, tt.options)
310 runForm(t, f, tt.ix)
311 require.Equal(t, tt.wantResult, *result)
312 })
313 }
314}
315

Callers

nothing calls this directly

Calls 9

newInteractionFunction · 0.85
enterFunction · 0.85
toggleFunction · 0.85
downFunction · 0.85
newTestHuhPrompterFunction · 0.85
runFormFunction · 0.85
buildMultiSelectFormMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…