forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_element_test.go
187 lines (130 loc) · 7.44 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
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 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 TestNewPlainTextInputBlockElement(t *testing.T) {
plainTextInputElement := NewPlainTextInputBlockElement(nil, "test")
assert.Equal(t, string(plainTextInputElement.Type), "plain_text_input")
assert.Equal(t, plainTextInputElement.ActionID, "test")
}
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)
}