-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
workflow_step_test.go
190 lines (165 loc) · 4.76 KB
/
workflow_step_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
package slack
import (
"testing"
"github.com/google/go-cmp/cmp"
)
const (
IDExampleSelectInput = "ae9642ae-a9ef-4394-904b-a5c7a83bf4a6"
IDSelectOptionBlock = "832bf7af-22ea-4acb-82e3-a0cc3722052b"
)
func TestNewConfigurationModalRequest(t *testing.T) {
blocks := configModalBlocks()
privateMetaData := "An optional string that will be sent to your app in view_submission and block_actions events. Max length of 3000 characters."
externalID := "c4baf441-fbc1-4131-b349-7c8df0ae7df6"
result := NewConfigurationModalRequest(blocks, privateMetaData, externalID)
if result.ModalViewRequest.Title != nil {
t.Fail()
}
if result.PrivateMetadata != privateMetaData {
t.Fail()
}
if result.ExternalID != externalID {
t.Fail()
}
}
func TestGetInitialOptionFromWorkflowStepInput(t *testing.T) {
options, testOption := createOptionBlockObjects()
selection := createSelection(options)
scenarios := []struct {
options []*OptionBlockObject
inputs *WorkflowStepInputs
expectedResult *OptionBlockObject
expectedFlag bool
}{
{
options: options,
inputs: createWorkflowStepInputs1(),
expectedResult: &OptionBlockObject{},
expectedFlag: false,
},
{
options: []*OptionBlockObject{},
inputs: createWorkflowStepInputs4(testOption.Value),
expectedResult: &OptionBlockObject{},
expectedFlag: false,
},
{
options: options,
inputs: createWorkflowStepInputs2(),
expectedResult: &OptionBlockObject{},
expectedFlag: false,
},
{
options: options,
inputs: createWorkflowStepInputs3(),
expectedResult: &OptionBlockObject{},
expectedFlag: false,
},
{
options: options,
inputs: createWorkflowStepInputs4(testOption.Value),
expectedResult: testOption,
expectedFlag: true,
},
}
for _, scenario := range scenarios {
result, ok := GetInitialOptionFromWorkflowStepInput(selection, scenario.inputs, scenario.options)
if ok != scenario.expectedFlag {
t.Fail()
}
if !cmp.Equal(result, scenario.expectedResult) {
t.Fail()
}
}
}
func createOptionBlockObjects() ([]*OptionBlockObject, *OptionBlockObject) {
var options []*OptionBlockObject
options = append(
options,
NewOptionBlockObject("one", NewTextBlockObject("plain_text", "One", false, false), nil),
)
option2 := NewOptionBlockObject("two", NewTextBlockObject("plain_text", "Two", false, false), nil)
options = append(
options,
option2,
)
options = append(
options,
NewOptionBlockObject("three", NewTextBlockObject("plain_text", "Three", false, false), nil),
)
return options, option2
}
func createSelection(options []*OptionBlockObject) *SelectBlockElement {
return NewOptionsSelectBlockElement(
"static_select",
NewTextBlockObject("plain_text", "your choice", false, false),
IDExampleSelectInput,
options...,
)
}
func configModalBlocks() Blocks {
headerText := NewTextBlockObject("mrkdwn", "Hello World!\nThis is your workflow step app configuration view", false, false)
headerSection := NewSectionBlock(headerText, nil, nil)
options, _ := createOptionBlockObjects()
selection := createSelection(options)
inputBlock := NewInputBlock(
IDSelectOptionBlock,
NewTextBlockObject("plain_text", "Select an option", false, false),
NewTextBlockObject("plain_text", "Hint", false, false),
selection,
)
blocks := Blocks{
BlockSet: []Block{
headerSection,
inputBlock,
},
}
return blocks
}
func createWorkflowStepInputs1() *WorkflowStepInputs {
return &WorkflowStepInputs{}
}
func createWorkflowStepInputs2() *WorkflowStepInputs {
return &WorkflowStepInputs{
"test": WorkflowStepInputElement{
Value: "random-string",
SkipVariableReplacement: false,
},
"123-test": WorkflowStepInputElement{
Value: "another-string",
SkipVariableReplacement: false,
},
}
}
func createWorkflowStepInputs3() *WorkflowStepInputs {
return &WorkflowStepInputs{
"test": WorkflowStepInputElement{
Value: "random-string",
SkipVariableReplacement: false,
},
"123-test": WorkflowStepInputElement{
Value: "another-string",
SkipVariableReplacement: false,
},
IDExampleSelectInput: WorkflowStepInputElement{
Value: "lorem-ipsum",
SkipVariableReplacement: true,
},
}
}
func createWorkflowStepInputs4(optionValue string) *WorkflowStepInputs {
return &WorkflowStepInputs{
"test": WorkflowStepInputElement{
Value: "random-string",
SkipVariableReplacement: false,
},
"123-test": WorkflowStepInputElement{
Value: "another-string",
SkipVariableReplacement: false,
},
IDExampleSelectInput: WorkflowStepInputElement{
Value: optionValue,
SkipVariableReplacement: false,
},
}
}