MCPcopy Index your code
hub / github.com/cli/cli / TestHuhPrompterMultiSelectWithSearch

Function TestHuhPrompterMultiSelectWithSearch

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

Source from the content-addressed store, hash-verified

425}
426
427func TestHuhPrompterMultiSelectWithSearch(t *testing.T) {
428 staticSearchFunc := func(query string) MultiSelectSearchResult {
429 if query == "" {
430 return MultiSelectSearchResult{
431 Keys: []string{"result-a", "result-b"},
432 Labels: []string{"Result A", "Result B"},
433 }
434 }
435 return MultiSelectSearchResult{
436 Keys: []string{"search-1", "search-2"},
437 Labels: []string{"Search 1", "Search 2"},
438 }
439 }
440
441 tests := []struct {
442 name string
443 defaults []string
444 persistent []string
445 ix interaction
446 wantResult []string
447 }{
448 {
449 name: "defaults are pre-selected and returned on immediate submit",
450 defaults: []string{"result-a"},
451 ix: newInteraction(tab(), enter()),
452 wantResult: []string{"result-a"},
453 },
454 {
455 name: "toggle an option from search results",
456 ix: newInteraction(tab(), waitForOptions(), toggle(), enter()),
457 wantResult: []string{"result-a"},
458 },
459 {
460 name: "toggle multiple options",
461 ix: newInteraction(
462 tab(), waitForOptions(),
463 toggle(), // toggle result-a
464 down(), // move to result-b
465 toggle(), // toggle result-b
466 enter(),
467 ),
468 wantResult: []string{"result-a", "result-b"},
469 },
470 {
471 name: "no selection returns empty",
472 ix: newInteraction(tab(), enter()),
473 wantResult: []string{},
474 },
475 {
476 name: "persistent options are shown and selectable",
477 persistent: []string{"persistent-1"},
478 ix: newInteraction(
479 tab(), waitForOptions(),
480 down(), // skip result-a
481 down(), // skip result-b
482 toggle(), // toggle persistent-1
483 enter(),
484 ),

Callers

nothing calls this directly

Calls 12

newInteractionFunction · 0.85
tabFunction · 0.85
enterFunction · 0.85
waitForOptionsFunction · 0.85
toggleFunction · 0.85
downFunction · 0.85
newTestHuhPrompterFunction · 0.85
runFormFunction · 0.85
EqualMethod · 0.80
selectedKeysMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected