(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func TestHuhPrompterSelect(t *testing.T) { |
| 165 | tests := []struct { |
| 166 | name string |
| 167 | options []string |
| 168 | defaultValue string |
| 169 | ix interaction |
| 170 | wantIndex int |
| 171 | }{ |
| 172 | { |
| 173 | name: "selects first option by default", |
| 174 | options: []string{"a", "b", "c"}, |
| 175 | ix: newInteraction(enter()), |
| 176 | wantIndex: 0, |
| 177 | }, |
| 178 | { |
| 179 | name: "respects default value", |
| 180 | options: []string{"a", "b", "c"}, |
| 181 | defaultValue: "b", |
| 182 | ix: newInteraction(enter()), |
| 183 | wantIndex: 1, |
| 184 | }, |
| 185 | { |
| 186 | name: "invalid default selects first", |
| 187 | options: []string{"a", "b", "c"}, |
| 188 | defaultValue: "z", |
| 189 | ix: newInteraction(enter()), |
| 190 | wantIndex: 0, |
| 191 | }, |
| 192 | { |
| 193 | name: "navigate down one", |
| 194 | options: []string{"a", "b", "c"}, |
| 195 | ix: newInteraction(down(), enter()), |
| 196 | wantIndex: 1, |
| 197 | }, |
| 198 | { |
| 199 | name: "navigate down two", |
| 200 | options: []string{"a", "b", "c"}, |
| 201 | ix: newInteraction(down(), down(), enter()), |
| 202 | wantIndex: 2, |
| 203 | }, |
| 204 | } |
| 205 | |
| 206 | for _, tt := range tests { |
| 207 | t.Run(tt.name, func(t *testing.T) { |
| 208 | p := newTestHuhPrompter() |
| 209 | f, result := p.buildSelectForm("Pick:", tt.defaultValue, tt.options) |
| 210 | runForm(t, f, tt.ix) |
| 211 | require.Equal(t, tt.wantIndex, *result) |
| 212 | }) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestHuhPrompterMultiSelect(t *testing.T) { |
| 217 | tests := []struct { |
nothing calls this directly
no test coverage detected