forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_element_test.go
142 lines (95 loc) · 5.24 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
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 TestNewOptionsSelectBlockElement(t *testing.T) {
testOptionText := NewTextBlockObject("plain_text", "Option One", false, false)
testOption := NewOptionBlockObject("test", testOptionText)
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)
testLabel := NewTextBlockObject("plain_text", "Test Label", false, false)
testGroupOption := NewOptionGroupBlockElement(testLabel, testOption)
optGroup := NewOptionsGroupSelectBlockElement("static_select", nil, "test", testGroupOption)
assert.Equal(t, string(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)
testOption := NewOptionBlockObject("test", testOptionText)
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)
testLabel := NewTextBlockObject("plain_text", "Test Label", false, false)
testGroupOption := NewOptionGroupBlockElement(testLabel, testOption)
optGroup := NewOptionsGroupMultiSelectBlockElement("static_select", nil, "test", testGroupOption)
assert.Equal(t, string(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)
overflowOptionTwo := NewOptionBlockObject("value-1", overflowOptionTextTwo)
overflowOptionThree := NewOptionBlockObject("value-2", overflowOptionTextThree)
// 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 TestNewPlainTextInputBlockElement(t *testing.T) {
plainTextInputElemnet := NewPlainTextInputBlockElement(nil, "test")
assert.Equal(t, string(plainTextInputElemnet.Type), "plain_text_input")
assert.Equal(t, plainTextInputElemnet.ActionID, "test")
}
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)
radioButtonsOptionTwo := NewOptionBlockObject("value-1", radioButtonsOptionTextTwo)
radioButtonsOptionThree := NewOptionBlockObject("value-2", radioButtonsOptionTextThree)
// Build overflow section
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)
}