/
kanban_test.rb
363 lines (305 loc) · 10.9 KB
/
kanban_test.rb
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
require File.dirname(__FILE__) + '/../test_helper'
class KanbanTest < ActiveSupport::TestCase
def shared_setup
@user = User.generate_with_protected!
User.current = @user
end
context "#find" do
setup {
shared_setup
configure_plugin
setup_kanban_issues
make_member({:principal => @user, :project => @public_project}, [Role.last])
}
context "for incoming issues" do
setup {
setup_incoming_issues
@kanban = Kanban.find
}
should "only get incoming issues up to the limit" do
assert_equal 5, @kanban.incoming_issues.size
end
should "only get incoming issues with the configured status" do
@kanban.incoming_issues.each do |issue|
assert_equal 'New', issue.status.name
end
end
end
context "for backlog issues" do
setup {
setup_backlog_issues
@kanban = Kanban.find
}
should "only get backlog issues up to the limit" do
assert_equal 3, @kanban.backlog_issues.size # Priorities
assert_equal 15, @kanban.backlog_issues.collect {|a| a[1]}.flatten.size # Issues
end
should "only get backlog issues with the configured status" do
@kanban.backlog_issues.each do |priority, issues|
issues.each do |issue|
assert_equal 'Unstaffed', issue.status.name
end
end
end
should "not include issues that are already in the Quick Issues list" do
@kanban.backlog_issues.each do |priority, issues|
issues.each do |issue|
assert !@kanban.quick_issue_ids.include?(issue.id)
end
end
end
should "group backlog issues by IssuePriority" do
assert_equal IssuePriority.find_by_name("High"), @kanban.backlog_issues.first.first
assert_equal IssuePriority.find_by_name("Medium"), @kanban.backlog_issues[1].first
assert_equal IssuePriority.find_by_name("Low"), @kanban.backlog_issues[2].first
end
end
context "for quick issues" do
setup {
setup_quick_issues
@kanban = Kanban.find
}
should "only get quick issues up to the limit" do
assert_equal 2, @kanban.quick_issues.size # Priorities
assert_equal 5, @kanban.quick_issues.collect {|a| a[1]}.flatten.size # Issues
end
should "only get quick issues with the configured Backlog status" do
@kanban.quick_issues.each do |priority, issues|
issues.each do |issue|
assert_equal 'Unstaffed', issue.status.name
end
end
end
should "group quick issues by IssuePriority" do
assert_equal IssuePriority.find_by_name("High"), @kanban.quick_issues.first.first
assert_equal IssuePriority.find_by_name("Medium"), @kanban.quick_issues[1].first
end
end
context "for selected issues" do
setup {
setup_selected_issues
@kanban = Kanban.find
}
should "get all selected issues" do
assert_equal 10, @kanban.selected_issues.length
end
should "only get selected issues with the configured status" do
@kanban.selected_issues.each do |kanban_issue|
assert_equal 'Selected', kanban_issue.issue.status.name
end
end
end
context "for active issues" do
setup {
setup_active_issues
setup_unknown_user_issues
@kanban = Kanban.find
}
should "only get all active issues" do
assert_equal 5, @kanban.active_issues.size # Users + Unknown
assert_equal 18, @kanban.active_issues.values.collect.flatten.size # Issues
end
should "only get issues with the configured Active status" do
@kanban.active_issues.each do |user, kanban_issues|
kanban_issues.each do |kanban_issue|
assert_equal 'Active', kanban_issue.issue.status.name
end
end
end
should "group active issues by User" do
@kanban.active_issues.keys.each do |key|
assert key.is_a?(UnknownUser) || key.is_a?(User)
end
end
end
context "for testing issues" do
setup {
setup_testing_issues
setup_unknown_user_issues
@kanban = Kanban.find
}
should "only get all testing issues" do
assert_equal 5, @kanban.testing_issues.size # Users + Unknow
assert_equal 19, @kanban.testing_issues.values.collect.flatten.size # Issues
end
should "only get issues with the configured Testing status" do
@kanban.testing_issues.each do |user, kanban_issues|
kanban_issues.each do |kanban_issue|
assert_equal 'Test-N-Doc', kanban_issue.issue.status.name
end
end
end
should "group testing issues by User" do
@kanban.testing_issues.keys.each do |key|
assert key.is_a?(UnknownUser) || key.is_a?(User)
end
end
end
context "for finished issues" do
setup {
setup_finished_issues
@kanban = Kanban.find
}
should "only get issues with the configured Finished status" do
@kanban.finished_issues.each do |user, issues|
issues.each do |issue|
assert_equal 'Closed', issue.status.name
end
end
end
should "only get issues from the last 7 days" do
@kanban.finished_issues.each do |user, issues|
issues.each do |issue|
assert issue.updated_on > 7.days.ago
end
end
end
should "group issues by User" do
@kanban.finished_issues.keys.each do |key|
assert key.is_a?(UnknownUser) || key.is_a?(User)
end
end
end
context "for canceled issues" do
setup {
setup_canceled_issues
@kanban = Kanban.find
}
should "only get issues with the configured Canceled status" do
@kanban.canceled_issues.each do |user, issues|
issues.each do |issue|
assert_equal 'Rejected', issue.status.name
end
end
end
should "only get issues from the last 7 days" do
@kanban.canceled_issues.each do |user, issues|
issues.each do |issue|
assert issue.updated_on > 7.days.ago
end
end
end
should "group issues by User" do
@kanban.canceled_issues.keys.each do |key|
assert key.is_a?(UnknownUser) || key.is_a?(User)
end
end
end
should "set @users based on the configured role" do
@kanban = Kanban.find
assert_equal 5, @kanban.users.length # +1 Unknown
end
end
context "#update_sorted_issues" do
setup {
shared_setup
setup_kanban_issues
}
context "with 0 issues" do
should 'remove all KanbanIssues for that pane' do
total = KanbanIssue.count(:conditions => {:state => 'selected'}) * -1
assert_difference('KanbanIssue.count', total) do
Kanban.update_sorted_issues('selected',[])
end
end
end
context "with a new KanbanIssue" do
should "create a new KanbanIssue" do
KanbanIssue.destroy_all
issue = Issue.generate!({
:tracker => @public_project.trackers.first,
:project => @public_project
})
assert_difference('KanbanIssue.count') do
Kanban.update_sorted_issues('selected',[issue.id])
end
kanban_issue = KanbanIssue.find_by_issue_id(issue.id)
assert kanban_issue
assert_equal 1, kanban_issue.position
assert_equal 'selected', kanban_issue.state
end
end
context "with an existing KanbanIssue" do
setup {
@issue = Issue.generate!({
:tracker => @public_project.trackers.first,
:project => @public_project
})
@kanban_issue = KanbanIssue.generate!({
:issue => @issue,
:user => nil,
:state => 'none',
:position => 3
})
}
should "change the state to the pane's state" do
Kanban.update_sorted_issues('selected',[@issue.id])
@kanban_issue.reload
assert_equal "selected", @kanban_issue.state
end
should "update the position based on the sorted_issues" do
Kanban.update_sorted_issues('selected',[@issue.id])
@kanban_issue.reload
assert_equal 1, @kanban_issue.position
end
end
end
context "#update_issue_attributes" do
setup {
shared_setup
setup_kanban_issues
@from = "incoming"
@to = "active"
@high_priority = IssuePriority.find_by_name("High")
@high_priority ||= IssuePriority.generate!(:name => "High", :type => 'IssuePriority') if @high_priority.nil?
@issue = Issue.generate!(:tracker => @public_project.trackers.first,
:project => @public_project,
:priority => @high_priority,
:status => IssueStatus.find_by_name('New'))
}
should "update the issue status to the 'to' pane's Status" do
Kanban.update_issue_attributes(@issue, @from, @to, @user)
@issue.reload
assert_equal "Active", @issue.status.name
end
should "return true if the issue was saved" do
assert Kanban.update_issue_attributes(@issue, @from, @to, @user)
end
should "return false if the issue wasn't found" do
assert !Kanban.update_issue_attributes('1234567890', @from, @to, @user)
end
should "return false if the issue didn't save"
context "to a staffed pane" do
should "assign the issue to the target user if the target user is set" do
Kanban.update_issue_attributes(@issue, @from, @to, @user, @user)
@issue.reload
assert_equal @user, @issue.assigned_to
end
should "keep the user assignment if the target user is nil" do
@issue.update_attribute(:assigned_to, @user)
@issue.reload
Kanban.update_issue_attributes(@issue, @from, @to, @user, nil)
@issue.reload
assert_equal @user, @issue.assigned_to
end
end
context "to an unstaffed pane" do
setup {
@to = 'backlog'
@from = 'active'
@issue.update_attribute(:assigned_to, @user)
@issue.reload
}
should "keep the user assignement if the target user is set" do
Kanban.update_issue_attributes(@issue, @from, @to, @user, @user)
@issue.reload
assert_equal @user, @issue.assigned_to
end
should "keep the user assignement if the target user is nil" do
Kanban.update_issue_attributes(@issue, @from, @to, @user, nil)
@issue.reload
assert_equal @user, @issue.assigned_to
end
end
end
end