(t *testing.T)
| 204 | } |
| 205 | |
| 206 | func TestHuhPrompterSelect(t *testing.T) { |
| 207 | tests := []struct { |
| 208 | name string |
| 209 | options []string |
| 210 | defaultValue string |
| 211 | ix interaction |
| 212 | wantIndex int |
| 213 | }{ |
| 214 | { |
| 215 | name: "selects first option by default", |
| 216 | options: []string{"a", "b", "c"}, |
| 217 | ix: newInteraction(enter()), |
| 218 | wantIndex: 0, |
| 219 | }, |
| 220 | { |
| 221 | name: "respects default value", |
| 222 | options: []string{"a", "b", "c"}, |
| 223 | defaultValue: "b", |
| 224 | ix: newInteraction(enter()), |
| 225 | wantIndex: 1, |
| 226 | }, |
| 227 | { |
| 228 | name: "invalid default selects first", |
| 229 | options: []string{"a", "b", "c"}, |
| 230 | defaultValue: "z", |
| 231 | ix: newInteraction(enter()), |
| 232 | wantIndex: 0, |
| 233 | }, |
| 234 | { |
| 235 | name: "navigate down one", |
| 236 | options: []string{"a", "b", "c"}, |
| 237 | ix: newInteraction(down(), enter()), |
| 238 | wantIndex: 1, |
| 239 | }, |
| 240 | { |
| 241 | name: "navigate down two", |
| 242 | options: []string{"a", "b", "c"}, |
| 243 | ix: newInteraction(down(), down(), enter()), |
| 244 | wantIndex: 2, |
| 245 | }, |
| 246 | } |
| 247 | |
| 248 | for _, tt := range tests { |
| 249 | t.Run(tt.name, func(t *testing.T) { |
| 250 | p := newTestHuhPrompter() |
| 251 | f, result := p.buildSelectForm("Pick:", tt.defaultValue, tt.options) |
| 252 | runForm(t, f, tt.ix) |
| 253 | require.Equal(t, tt.wantIndex, *result) |
| 254 | }) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | func TestHuhPrompterMultiSelect(t *testing.T) { |
| 259 | tests := []struct { |
nothing calls this directly
no test coverage detected