MCPcopy Index your code
hub / github.com/coder/coder / TestRichMultiSelect

Function TestRichMultiSelect

cli/cliui/select_test.go:82–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestRichMultiSelect(t *testing.T) {
83 t.Parallel()
84
85 tests := []struct {
86 name string
87 options []codersdk.TemplateVersionParameterOption
88 defaults []string
89 allowCustom bool
90 want []string
91 }{
92 {
93 name: "Predefined",
94 options: []codersdk.TemplateVersionParameterOption{
95 {Name: "AAA", Description: "This is AAA", Value: "aaa"},
96 {Name: "BBB", Description: "This is BBB", Value: "bbb"},
97 {Name: "CCC", Description: "This is CCC", Value: "ccc"},
98 },
99 defaults: []string{"bbb", "ccc"},
100 allowCustom: false,
101 want: []string{"bbb", "ccc"},
102 },
103 {
104 name: "Custom",
105 options: []codersdk.TemplateVersionParameterOption{
106 {Name: "AAA", Description: "This is AAA", Value: "aaa"},
107 {Name: "BBB", Description: "This is BBB", Value: "bbb"},
108 {Name: "CCC", Description: "This is CCC", Value: "ccc"},
109 },
110 defaults: []string{"aaa", "bbb"},
111 allowCustom: true,
112 want: []string{"aaa", "bbb"},
113 },
114 {
115 name: "NoOptionSelected",
116 options: []codersdk.TemplateVersionParameterOption{
117 {Name: "AAA", Description: "This is AAA", Value: "aaa"},
118 {Name: "BBB", Description: "This is BBB", Value: "bbb"},
119 {Name: "CCC", Description: "This is CCC", Value: "ccc"},
120 },
121 defaults: []string{},
122 allowCustom: false,
123 want: []string{},
124 },
125 }
126
127 for _, tt := range tests {
128 t.Run(tt.name, func(t *testing.T) {
129 t.Parallel()
130
131 var selectedItems []string
132 var err error
133 cmd := &serpent.Command{
134 Handler: func(inv *serpent.Invocation) error {
135 selectedItems, err = cliui.RichMultiSelect(inv, cliui.RichMultiSelectOptions{
136 Options: tt.options,
137 Defaults: tt.defaults,
138 EnableCustomInput: tt.allowCustom,
139 })

Callers

nothing calls this directly

Calls 4

RichMultiSelectFunction · 0.92
RunMethod · 0.65
InvokeMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected