(t *testing.T)
| 256 | } |
| 257 | |
| 258 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…