(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func 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 | }) |
nothing calls this directly
no test coverage detected