(t *testing.T)
| 383 | } |
| 384 | |
| 385 | func TestHuhPrompterMultiSelectWithSearch(t *testing.T) { |
| 386 | staticSearchFunc := func(query string) MultiSelectSearchResult { |
| 387 | if query == "" { |
| 388 | return MultiSelectSearchResult{ |
| 389 | Keys: []string{"result-a", "result-b"}, |
| 390 | Labels: []string{"Result A", "Result B"}, |
| 391 | } |
| 392 | } |
| 393 | return MultiSelectSearchResult{ |
| 394 | Keys: []string{"search-1", "search-2"}, |
| 395 | Labels: []string{"Search 1", "Search 2"}, |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | tests := []struct { |
| 400 | name string |
| 401 | defaults []string |
| 402 | persistent []string |
| 403 | ix interaction |
| 404 | wantResult []string |
| 405 | }{ |
| 406 | { |
| 407 | name: "defaults are pre-selected and returned on immediate submit", |
| 408 | defaults: []string{"result-a"}, |
| 409 | ix: newInteraction(tab(), enter()), |
| 410 | wantResult: []string{"result-a"}, |
| 411 | }, |
| 412 | { |
| 413 | name: "toggle an option from search results", |
| 414 | ix: newInteraction(tab(), waitForOptions(), toggle(), enter()), |
| 415 | wantResult: []string{"result-a"}, |
| 416 | }, |
| 417 | { |
| 418 | name: "toggle multiple options", |
| 419 | ix: newInteraction( |
| 420 | tab(), waitForOptions(), |
| 421 | toggle(), // toggle result-a |
| 422 | down(), // move to result-b |
| 423 | toggle(), // toggle result-b |
| 424 | enter(), |
| 425 | ), |
| 426 | wantResult: []string{"result-a", "result-b"}, |
| 427 | }, |
| 428 | { |
| 429 | name: "no selection returns empty", |
| 430 | ix: newInteraction(tab(), enter()), |
| 431 | wantResult: []string{}, |
| 432 | }, |
| 433 | { |
| 434 | name: "persistent options are shown and selectable", |
| 435 | persistent: []string{"persistent-1"}, |
| 436 | ix: newInteraction( |
| 437 | tab(), waitForOptions(), |
| 438 | down(), // skip result-a |
| 439 | down(), // skip result-b |
| 440 | toggle(), // toggle persistent-1 |
| 441 | enter(), |
| 442 | ), |
nothing calls this directly
no test coverage detected