Codebase list golang-github-nlopes-slack / 59cd614
Correct select dialog items' SelectedOptions type According to https://api.slack.com/dialogs#select_default_values, this field can't be a string: it may hold an array with at most one value, giving an option that comes pre-selected on a select field with an "external" data source. Andreas Fuchs authored 4 years ago James committed 4 years ago
2 changed file(s) with 17 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
2020 DialogInput
2121 Value string `json:"value,omitempty"` //Optional.
2222 DataSource SelectDataSource `json:"data_source,omitempty"` //Optional. Allowed values: "users", "channels", "conversations", "external".
23 SelectedOptions string `json:"selected_options,omitempty"` //Optional. Default value for "external" only
23 SelectedOptions []DialogSelectOption `json:"selected_options,omitempty"` //Optional. May hold at most one element, for use with "external" only.
2424 Options []DialogSelectOption `json:"options,omitempty"` //One of options or option_groups is required.
2525 OptionGroups []DialogOptionGroup `json:"option_groups,omitempty"` //Provide up to 100 options.
2626 MinQueryLength int `json:"min_query_length,omitempty"` //Optional. minimum characters before query is sent.
3838 "optional": true,
3939 "value": "testing value",
4040 "data_source": "users",
41 "selected_options": "",
41 "selected_options": [],
4242 "options": [{"label": "option 1", "value": "1"}],
4343 "option_groups": []
4444 }`
103103 selectElement.Optional = true
104104 selectElement.Value = "testing value"
105105 selectElement.DataSource = "users"
106 selectElement.SelectedOptions = ""
106 selectElement.SelectedOptions = []DialogSelectOption{}
107107 selectElement.Options = []DialogSelectOption{
108108 {Label: "option 1", Value: "1"},
109109 }
148148 assert.Equal(t, true, selectElement.Optional)
149149 assert.Equal(t, "testing value", selectElement.Value)
150150 assert.Equal(t, DialogDataSourceUsers, selectElement.DataSource)
151 assert.Equal(t, "", selectElement.SelectedOptions)
151 assert.Equal(t, []DialogSelectOption{}, selectElement.SelectedOptions)
152152 assert.Equal(t, "option 1", selectElement.Options[0].Label)
153153 assert.Equal(t, "1", selectElement.Options[0].Value)
154154 assert.Equal(t, 0, len(selectElement.OptionGroups))
158158 var simpleCallback = `{
159159 "type": "dialog_submission",
160160 "submission": {
161 "name": "Sigourney Dreamweaver",
162 "email": "sigdre@example.com",
163 "phone": "+1 800-555-1212",
164 "meal": "burrito",
165 "comment": "No sour cream please",
166 "team_channel": "C0LFFBKPB",
167 "who_should_sing": "U0MJRG1AL"
161 "name": "Sigourney Dreamweaver",
162 "email": "sigdre@example.com",
163 "phone": "+1 800-555-1212",
164 "meal": "burrito",
165 "comment": "No sour cream please",
166 "team_channel": "C0LFFBKPB",
167 "who_should_sing": "U0MJRG1AL"
168168 },
169169 "callback_id": "employee_offsite_1138b",
170170 "team": {
171 "id": "T1ABCD2E12",
172 "domain": "coverbands"
171 "id": "T1ABCD2E12",
172 "domain": "coverbands"
173173 },
174174 "user": {
175 "id": "W12A3BCDEF",
176 "name": "dreamweaver"
175 "id": "W12A3BCDEF",
176 "name": "dreamweaver"
177177 },
178178 "channel": {
179 "id": "C1AB2C3DE",
180 "name": "coverthon-1999"
179 "id": "C1AB2C3DE",
180 "name": "coverthon-1999"
181181 },
182182 "action_ts": "936893340.702759",
183183 "token": "M1AqUUw3FqayAbqNtsGMch72",