-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
block_element_test.go
249 lines (173 loc) · 9.56 KB
/
block_element_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package slack
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewImageBlockElement(t *testing.T) {
imageElement := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Location Pin Icon")
assert.Equal(t, string(imageElement.Type), "image")
assert.Contains(t, imageElement.ImageURL, "tripAgentLocationMarker")
assert.Equal(t, imageElement.AltText, "Location Pin Icon")
}
func TestNewButtonBlockElement(t *testing.T) {
btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false)
btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt)
assert.Equal(t, string(btnElement.Type), "button")
assert.Equal(t, btnElement.ActionID, "test")
assert.Equal(t, btnElement.Value, "click_me_123")
assert.Equal(t, btnElement.Text.Text, "Next 2 Results")
}
func TestWithStyleForButtonElement(t *testing.T) {
// these values are irrelevant in this test
btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false)
btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt)
btnElement.WithStyle(StyleDefault)
assert.Equal(t, btnElement.Style, Style(""))
btnElement.WithStyle(StylePrimary)
assert.Equal(t, btnElement.Style, Style("primary"))
btnElement.WithStyle(StyleDanger)
assert.Equal(t, btnElement.Style, Style("danger"))
}
func TestWithURLForButtonElement(t *testing.T) {
btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false)
btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt)
btnElement.WithURL("https://foo.bar")
assert.Equal(t, btnElement.URL, "https://foo.bar")
}
func TestNewOptionsSelectBlockElement(t *testing.T) {
testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, nil)
option := NewOptionsSelectBlockElement("static_select", nil, "test", testOption)
assert.Equal(t, option.Type, "static_select")
assert.Equal(t, len(option.Options), 1)
assert.Nil(t, option.OptionGroups)
}
func TestNewOptionsGroupSelectBlockElement(t *testing.T) {
testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, nil)
testLabel := NewTextBlockObject("plain_text", "Test Label", false, false)
testGroupOption := NewOptionGroupBlockElement(testLabel, testOption)
optGroup := NewOptionsGroupSelectBlockElement("static_select", nil, "test", testGroupOption)
assert.Equal(t, optGroup.Type, "static_select")
assert.Equal(t, optGroup.ActionID, "test")
assert.Equal(t, len(optGroup.OptionGroups), 1)
}
func TestNewOptionsMultiSelectBlockElement(t *testing.T) {
testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testDescriptionText := NewTextBlockObject("plain_text", "Description One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, testDescriptionText)
option := NewOptionsMultiSelectBlockElement("static_select", nil, "test", testOption)
assert.Equal(t, option.Type, "static_select")
assert.Equal(t, len(option.Options), 1)
assert.Nil(t, option.OptionGroups)
}
func TestNewOptionsGroupMultiSelectBlockElement(t *testing.T) {
testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testOption := NewOptionBlockObject("test", testOptionText, nil)
testLabel := NewTextBlockObject("plain_text", "Test Label", false, false)
testGroupOption := NewOptionGroupBlockElement(testLabel, testOption)
optGroup := NewOptionsGroupMultiSelectBlockElement("static_select", nil, "test", testGroupOption)
assert.Equal(t, optGroup.Type, "static_select")
assert.Equal(t, optGroup.ActionID, "test")
assert.Equal(t, len(optGroup.OptionGroups), 1)
}
func TestNewOverflowBlockElement(t *testing.T) {
// Build Text Objects associated with each option
overflowOptionTextOne := NewTextBlockObject("plain_text", "Option One", false, false)
overflowOptionTextTwo := NewTextBlockObject("plain_text", "Option Two", false, false)
overflowOptionTextThree := NewTextBlockObject("plain_text", "Option Three", false, false)
// Build each option, providing a value for the option
overflowOptionOne := NewOptionBlockObject("value-0", overflowOptionTextOne, nil)
overflowOptionTwo := NewOptionBlockObject("value-1", overflowOptionTextTwo, nil)
overflowOptionThree := NewOptionBlockObject("value-2", overflowOptionTextThree, nil)
// Build overflow section
overflowElement := NewOverflowBlockElement("test", overflowOptionOne, overflowOptionTwo, overflowOptionThree)
assert.Equal(t, string(overflowElement.Type), "overflow")
assert.Equal(t, overflowElement.ActionID, "test")
assert.Equal(t, len(overflowElement.Options), 3)
}
func TestNewDatePickerBlockElement(t *testing.T) {
datepickerElement := NewDatePickerBlockElement("test")
assert.Equal(t, string(datepickerElement.Type), "datepicker")
assert.Equal(t, datepickerElement.ActionID, "test")
}
func TestNewTimePickerBlockElement(t *testing.T) {
timepickerElement := NewTimePickerBlockElement("test")
assert.Equal(t, string(timepickerElement.Type), "timepicker")
assert.Equal(t, timepickerElement.ActionID, "test")
}
func TestNewDateTimePickerBlockElement(t *testing.T) {
datetimepickerElement := NewDateTimePickerBlockElement("test")
assert.Equal(t, string(datetimepickerElement.Type), "datetimepicker")
assert.Equal(t, datetimepickerElement.ActionID, "test")
}
func TestNewPlainTextInputBlockElement(t *testing.T) {
plainTextInputElement := NewPlainTextInputBlockElement(nil, "test")
assert.Equal(t, string(plainTextInputElement.Type), "plain_text_input")
assert.Equal(t, plainTextInputElement.ActionID, "test")
}
func TestNewRichTextInputBlockElement(t *testing.T) {
richTextInputElement := NewRichTextInputBlockElement(nil, "test")
assert.Equal(t, string(richTextInputElement.Type), "rich_text_input")
assert.Equal(t, richTextInputElement.ActionID, "test")
}
func TestNewEmailTextInputBlockElement(t *testing.T) {
emailTextInputElement := NewEmailTextInputBlockElement(nil, "[email protected]")
assert.Equal(t, string(emailTextInputElement.Type), "email_text_input")
assert.Equal(t, emailTextInputElement.ActionID, "[email protected]")
}
func TestNewURLTextInputBlockElement(t *testing.T) {
urlTextInputElement := NewURLTextInputBlockElement(nil, "www.example.com")
assert.Equal(t, string(urlTextInputElement.Type), "url_text_input")
assert.Equal(t, urlTextInputElement.ActionID, "www.example.com")
}
func TestNewCheckboxGroupsBlockElement(t *testing.T) {
// Build Text Objects associated with each option
checkBoxOptionTextOne := NewTextBlockObject("plain_text", "Check One", false, false)
checkBoxOptionTextTwo := NewTextBlockObject("plain_text", "Check Two", false, false)
checkBoxOptionTextThree := NewTextBlockObject("plain_text", "Check Three", false, false)
checkBoxDescriptionTextOne := NewTextBlockObject("plain_text", "Description One", false, false)
checkBoxDescriptionTextTwo := NewTextBlockObject("plain_text", "Description Two", false, false)
checkBoxDescriptionTextThree := NewTextBlockObject("plain_text", "Description Three", false, false)
// Build each option, providing a value for the option
checkBoxOptionOne := NewOptionBlockObject("value-0", checkBoxOptionTextOne, checkBoxDescriptionTextOne)
checkBoxOptionTwo := NewOptionBlockObject("value-1", checkBoxOptionTextTwo, checkBoxDescriptionTextTwo)
checkBoxOptionThree := NewOptionBlockObject("value-2", checkBoxOptionTextThree, checkBoxDescriptionTextThree)
// Build checkbox-group element
checkBoxGroupElement := NewCheckboxGroupsBlockElement("test", checkBoxOptionOne, checkBoxOptionTwo, checkBoxOptionThree)
assert.Equal(t, string(checkBoxGroupElement.Type), "checkboxes")
assert.Equal(t, checkBoxGroupElement.ActionID, "test")
assert.Equal(t, len(checkBoxGroupElement.Options), 3)
}
func TestNewRadioButtonsBlockElement(t *testing.T) {
// Build Text Objects associated with each option
radioButtonsOptionTextOne := NewTextBlockObject("plain_text", "Option One", false, false)
radioButtonsOptionTextTwo := NewTextBlockObject("plain_text", "Option Two", false, false)
radioButtonsOptionTextThree := NewTextBlockObject("plain_text", "Option Three", false, false)
// Build each option, providing a value for the option
radioButtonsOptionOne := NewOptionBlockObject("value-0", radioButtonsOptionTextOne, nil)
radioButtonsOptionTwo := NewOptionBlockObject("value-1", radioButtonsOptionTextTwo, nil)
radioButtonsOptionThree := NewOptionBlockObject("value-2", radioButtonsOptionTextThree, nil)
// Build radio button element
radioButtonsElement := NewRadioButtonsBlockElement("test", radioButtonsOptionOne, radioButtonsOptionTwo, radioButtonsOptionThree)
assert.Equal(t, string(radioButtonsElement.Type), "radio_buttons")
assert.Equal(t, radioButtonsElement.ActionID, "test")
assert.Equal(t, len(radioButtonsElement.Options), 3)
}
func TestNewNumberInputBlockElement(t *testing.T) {
numberInputElement := NewNumberInputBlockElement(nil, "test", true)
assert.Equal(t, string(numberInputElement.Type), "number_input")
assert.Equal(t, numberInputElement.ActionID, "test")
assert.Equal(t, numberInputElement.IsDecimalAllowed, true)
}
func TestNewFileInputBlockElement(t *testing.T) {
fileInputElement := NewFileInputBlockElement("test")
assert.Equal(t, string(fileInputElement.Type), "file_input")
assert.Equal(t, fileInputElement.ActionID, "test")
fileInputElement.WithFileTypes("jpg", "png")
assert.Equal(t, len(fileInputElement.FileTypes), 2)
assert.Contains(t, fileInputElement.FileTypes, "jpg")
assert.Contains(t, fileInputElement.FileTypes, "png")
fileInputElement.WithMaxFiles(10)
assert.Equal(t, fileInputElement.MaxFiles, 10)
}