forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dialog_select_test.go
127 lines (102 loc) · 3.73 KB
/
dialog_select_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package slack
import (
"testing"
"github.com/stretchr/testify/assert"
)
func selectOptionsFromArray(options ...string) []DialogSelectOption {
selectOptions := make([]DialogSelectOption, len(options))
for idx, value := range options {
selectOptions[idx] = DialogSelectOption{
Label: value,
Value: value,
}
}
return selectOptions
}
func selectOptionsFromMap(options map[string]string) []DialogSelectOption {
selectOptions := make([]DialogSelectOption, len(options))
idx := 0
var option DialogSelectOption
for key, value := range options {
option = DialogSelectOption{
Label: key,
Value: value,
}
selectOptions[idx] = option
idx++
}
return selectOptions
}
func TestSelectOptionsFromArray(t *testing.T) {
options := []string{"opt 1"}
expectedOptions := selectOptionsFromArray(options...)
assert.Equal(t, len(options), len(expectedOptions))
firstOption := expectedOptions[0]
assert.Equal(t, "opt 1", firstOption.Label)
assert.Equal(t, "opt 1", firstOption.Value)
}
func TestOptionsFromMap(t *testing.T) {
options := make(map[string]string)
options["key"] = "myValue"
selectOptions := selectOptionsFromMap(options)
assert.Equal(t, 1, len(selectOptions))
firstOption := selectOptions[0]
assert.Equal(t, "key", firstOption.Label)
assert.Equal(t, "myValue", firstOption.Value)
}
func TestStaticSelectFromArray(t *testing.T) {
name := "static select"
label := "Static Select Label"
expectedOptions := selectOptionsFromArray("opt 1", "opt 2", "opt 3")
selectInput := NewStaticSelectDialogInput(name, label, expectedOptions)
assert.Equal(t, name, selectInput.Name)
assert.Equal(t, label, selectInput.Label)
assert.Equal(t, expectedOptions, selectInput.Options)
}
func TestStaticSelectFromDictionary(t *testing.T) {
name := "static select"
label := "Static Select Label"
optionsMap := make(map[string]string)
optionsMap["option_1"] = "First"
optionsMap["option_2"] = "Second"
optionsMap["option_3"] = "Third"
expectedOptions := selectOptionsFromMap(optionsMap)
selectInput := NewStaticSelectDialogInput(name, label, expectedOptions)
assert.Equal(t, name, selectInput.Name)
assert.Equal(t, label, selectInput.Label)
assert.Equal(t, expectedOptions, selectInput.Options)
}
func TestNewDialogOptionGroup(t *testing.T) {
expectedOptions := selectOptionsFromArray("option_1", "option_2")
label := "GroupLabel"
optionGroup := NewDialogOptionGroup(label, expectedOptions...)
assert.Equal(t, label, optionGroup.Label)
assert.Equal(t, expectedOptions, optionGroup.Options)
}
func TestStaticGroupedSelect(t *testing.T) {
groupOpt1 := NewDialogOptionGroup("group1", selectOptionsFromArray("G1_01", "G1_02")...)
groupOpt2 := NewDialogOptionGroup("group2", selectOptionsFromArray("G2_01", "G2_02", "G2_03")...)
options := []DialogOptionGroup{groupOpt1, groupOpt2}
groupSelect := NewGroupedSelectDialogInput("groupSelect", "User Label", options)
assert.Equal(t, InputTypeSelect, groupSelect.Type)
assert.Equal(t, "groupSelect", groupSelect.Name)
assert.Equal(t, "User Label", groupSelect.Label)
assert.Nil(t, groupSelect.Options)
assert.NotNil(t, groupSelect.OptionGroups)
assert.Equal(t, 2, len(groupSelect.OptionGroups))
}
func TestConversationSelect(t *testing.T) {
convoSelect := NewConversationsSelect("", "")
assert.Equal(t, InputTypeSelect, convoSelect.Type)
assert.Equal(t, DialogDataSourceConversations, convoSelect.DataSource)
}
func TestChannelSelect(t *testing.T) {
convoSelect := NewChannelsSelect("", "")
assert.Equal(t, InputTypeSelect, convoSelect.Type)
assert.Equal(t, DialogDataSourceChannels, convoSelect.DataSource)
}
func TestUserSelect(t *testing.T) {
convoSelect := NewUsersSelect("", "")
assert.Equal(t, InputTypeSelect, convoSelect.Type)
assert.Equal(t, DialogDataSourceUsers, convoSelect.DataSource)
}