(t *testing.T)
| 214 | } |
| 215 | |
| 216 | func TestHuhPrompterMultiSelect(t *testing.T) { |
| 217 | tests := []struct { |
| 218 | name string |
| 219 | options []string |
| 220 | defaults []string |
| 221 | ix interaction |
| 222 | wantResult []int |
| 223 | }{ |
| 224 | { |
| 225 | name: "no defaults and no toggles returns empty", |
| 226 | options: []string{"a", "b", "c"}, |
| 227 | ix: newInteraction(enter()), |
| 228 | wantResult: []int{}, |
| 229 | }, |
| 230 | { |
| 231 | name: "defaults are pre-selected", |
| 232 | options: []string{"a", "b", "c"}, |
| 233 | defaults: []string{"a", "c"}, |
| 234 | ix: newInteraction(enter()), |
| 235 | wantResult: []int{0, 2}, |
| 236 | }, |
| 237 | { |
| 238 | name: "toggle first option", |
| 239 | options: []string{"a", "b", "c"}, |
| 240 | ix: newInteraction(toggle(), enter()), |
| 241 | wantResult: []int{0}, |
| 242 | }, |
| 243 | { |
| 244 | name: "toggle multiple options", |
| 245 | options: []string{"a", "b", "c"}, |
| 246 | ix: newInteraction( |
| 247 | toggle(), // toggle a |
| 248 | down(), // move to b |
| 249 | down(), // move to c |
| 250 | toggle(), // toggle c |
| 251 | enter(), |
| 252 | ), |
| 253 | wantResult: []int{0, 2}, |
| 254 | }, |
| 255 | { |
| 256 | name: "invalid defaults are excluded", |
| 257 | options: []string{"a", "b"}, |
| 258 | defaults: []string{"z"}, |
| 259 | ix: newInteraction(enter()), |
| 260 | wantResult: []int{}, |
| 261 | }, |
| 262 | } |
| 263 | |
| 264 | for _, tt := range tests { |
| 265 | t.Run(tt.name, func(t *testing.T) { |
| 266 | p := newTestHuhPrompter() |
| 267 | f, result := p.buildMultiSelectForm("Pick:", tt.defaults, tt.options) |
| 268 | runForm(t, f, tt.ix) |
| 269 | require.Equal(t, tt.wantResult, *result) |
| 270 | }) |
| 271 | } |
| 272 | } |
| 273 |
nothing calls this directly
no test coverage detected