forked from winston-stripe/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_object_test.go
135 lines (105 loc) · 3.74 KB
/
block_object_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
package slack
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewImageBlockObject(t *testing.T) {
imageObject := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/beagle.png", "Beagle")
assert.Equal(t, string(imageObject.Type), "image")
assert.Equal(t, imageObject.AltText, "Beagle")
assert.Contains(t, imageObject.ImageURL, "beagle.png")
}
func TestNewTextBlockObject(t *testing.T) {
textObject := NewTextBlockObject("plain_text", "test", true, false)
assert.Equal(t, textObject.Type, "plain_text")
assert.Equal(t, textObject.Text, "test")
assert.True(t, textObject.Emoji, "Emoji property should be true")
assert.False(t, textObject.Verbatim, "Verbatim should be false")
}
func TestNewConfirmationBlockObject(t *testing.T) {
titleObj := NewTextBlockObject("plain_text", "testTitle", false, false)
textObj := NewTextBlockObject("plain_text", "testText", false, false)
confirmObj := NewTextBlockObject("plain_text", "testConfirm", false, false)
confirmation := NewConfirmationBlockObject(titleObj, textObj, confirmObj, nil)
assert.Equal(t, confirmation.Title.Text, "testTitle")
assert.Equal(t, confirmation.Text.Text, "testText")
assert.Equal(t, confirmation.Confirm.Text, "testConfirm")
assert.Nil(t, confirmation.Deny, "Deny should be nil")
}
func TestWithStyleForConfirmation(t *testing.T) {
// these values are irrelevant in this test
titleObj := NewTextBlockObject("plain_text", "testTitle", false, false)
textObj := NewTextBlockObject("plain_text", "testText", false, false)
confirmObj := NewTextBlockObject("plain_text", "testConfirm", false, false)
confirmation := NewConfirmationBlockObject(titleObj, textObj, confirmObj, nil)
confirmation.WithStyle(StyleDefault)
assert.Equal(t, confirmation.Style, Style(""))
confirmation.WithStyle(StylePrimary)
assert.Equal(t, confirmation.Style, Style("primary"))
confirmation.WithStyle(StyleDanger)
assert.Equal(t, confirmation.Style, Style("danger"))
}
func TestNewOptionBlockObject(t *testing.T) {
valTextObj := NewTextBlockObject("plain_text", "testText", false, false)
valDescriptionObj := NewTextBlockObject("plain_text", "testDescription", false, false)
optObj := NewOptionBlockObject("testOpt", valTextObj, valDescriptionObj)
assert.Equal(t, optObj.Text.Text, "testText")
assert.Equal(t, optObj.Description.Text, "testDescription")
assert.Equal(t, optObj.Value, "testOpt")
}
func TestNewOptionGroupBlockElement(t *testing.T) {
labelObj := NewTextBlockObject("plain_text", "testLabel", false, false)
valTextObj := NewTextBlockObject("plain_text", "testText", false, false)
optObj := NewOptionBlockObject("testOpt", valTextObj, nil)
optGroup := NewOptionGroupBlockElement(labelObj, optObj)
assert.Equal(t, optGroup.Label.Text, "testLabel")
assert.Len(t, optGroup.Options, 1, "Options should contain one element")
}
func TestValidateTextBlockObject(t *testing.T) {
tests := []struct {
input TextBlockObject
expected error
}{
{
input: TextBlockObject{
Type: "plain_text",
Text: "testText",
Emoji: false,
Verbatim: false,
},
expected: nil,
},
{
input: TextBlockObject{
Type: "mrkdwn",
Text: "testText",
Emoji: false,
Verbatim: false,
},
expected: nil,
},
{
input: TextBlockObject{
Type: "invalid",
Text: "testText",
Emoji: false,
Verbatim: false,
},
expected: errors.New("type must be either of plain_text or mrkdwn"),
},
{
input: TextBlockObject{
Type: "mrkdwn",
Text: "testText",
Emoji: true,
Verbatim: false,
},
expected: errors.New("emoji cannot be true in mrkdown"),
},
}
for _, test := range tests {
err := test.input.Validate()
assert.Equal(t, err, test.expected)
}
}