Skip to content

Commit a4431a6

Browse files
committed
select ui tests
1 parent 3e2d733 commit a4431a6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cli/cliui/select_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,36 @@ func newRichSelect(ptty *ptytest.PTY, opts cliui.RichSelectOptions) (string, err
8686
cmd.SetIn(ptty.Input())
8787
return value, cmd.ExecuteContext(context.Background())
8888
}
89+
90+
func TestMultiSelect(t *testing.T) {
91+
t.Parallel()
92+
t.Run("MultiSelect", func(t *testing.T) {
93+
items := []string{"aaa", "bbb", "ccc"}
94+
95+
t.Parallel()
96+
ptty := ptytest.New(t)
97+
msgChan := make(chan []string)
98+
go func() {
99+
resp, err := newMultiSelect(ptty, items)
100+
assert.NoError(t, err)
101+
msgChan <- resp
102+
}()
103+
require.Equal(t, items, <-msgChan)
104+
})
105+
}
106+
107+
func newMultiSelect(ptty *ptytest.PTY, items []string) ([]string, error) {
108+
var values []string
109+
cmd := &cobra.Command{
110+
RunE: func(cmd *cobra.Command, args []string) error {
111+
selectedItems, err := cliui.MultiSelect(cmd, items)
112+
if err == nil {
113+
values = selectedItems
114+
}
115+
return err
116+
},
117+
}
118+
cmd.SetOutput(ptty.Output())
119+
cmd.SetIn(ptty.Input())
120+
return values, cmd.ExecuteContext(context.Background())
121+
}

0 commit comments

Comments
 (0)