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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Issues > Labels bulk assignment' do
let(:user) { create(:user) }
let!(:project) { create(:project) }
let!(:bug) { create(:label, project: project, title: 'bug') }
let!(:feature) { create(:label, project: project, title: 'feature') }
let!(:frontend) { create(:label, project: project, title: 'frontend') }
let!(:wontfix) { create(:label, project: project, title: 'wontfix') }
let!(:issue1) { create(:issue, project: project, title: "Issue 1", labels: [frontend]) }
let!(:issue2) { create(:issue, project: project, title: "Issue 2") }
let(:issue_1_selector) { "#issuable_#{issue1.id}" }
let(:issue_2_selector) { "#issuable_#{issue2.id}" }
context 'as an allowed user', :js do
before do
project.add_maintainer(user)
sign_in user
end
context 'sidebar' do
it 'is present when bulk edit is enabled' do
enable_bulk_update
expect(page).to have_css 'aside[aria-label="Bulk update"]'
end
it 'is not present when bulk edit is disabled' do
expect(page).not_to have_css 'aside[aria-label="Bulk update"]'
end
end
context 'can bulk assign' do
before do
enable_bulk_update
end
context 'a label' do
context 'to all issues' do
before do
check 'Select all'
open_labels_dropdown ['bug']
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
end
end
context 'to some issues' do
before do
check issue1.title
check issue2.title
open_labels_dropdown ['bug']
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
end
end
context 'to an issue' do
before do
check issue1.title
open_labels_dropdown ['bug']
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
end
end
context 'to an issue by selecting the label first' do
before do
open_labels_dropdown ['bug']
check issue1.title
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
end
end
end
context 'multiple labels' do
context 'to all issues' do
before do
check 'Select all'
open_labels_dropdown %w(bug feature)
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
end
end
context 'to a issue' do
before do
check issue1.title
open_labels_dropdown %w(bug feature)
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'feature'
end
end
end
end
context 'can assign a label to all issues when label is present' do
before do
issue2.labels << bug
issue2.labels << feature
enable_bulk_update
check 'Select all'
open_labels_dropdown ['bug']
update_issues
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'bug'
end
end
context 'can bulk un-assign' do
context 'all labels to all issues' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
issue2.labels << feature
enable_bulk_update
check 'Select all'
unmark_labels_in_dropdown %w(bug feature)
update_issues
end
it do
expect(find(issue_1_selector)).not_to have_content 'bug'
expect(find(issue_1_selector)).not_to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'feature'
end
end
context 'a label to a issue' do
before do
issue1.labels << bug
issue2.labels << feature
enable_bulk_update
check_issue issue1
unmark_labels_in_dropdown ['bug']
update_issues
end
it do
expect(find(issue_1_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
end
end
context 'a label and keep the others label' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
issue2.labels << feature
enable_bulk_update
check_issue issue1
check_issue issue2
unmark_labels_in_dropdown ['bug']
update_issues
end
it do
expect(find(issue_1_selector)).not_to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
end
end
end
context 'toggling a milestone' do
let!(:milestone) { create(:milestone, project: project, title: 'First Release') }
context 'setting a milestone' do
before do
issue1.labels << bug
issue2.labels << feature
enable_bulk_update
end
it 'keeps labels' do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
check 'Select all'
open_milestone_dropdown(['First Release'])
update_issues
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
end
end
context 'setting a milestone and adding another label' do
before do
issue1.labels << bug
enable_bulk_update
end
it 'keeps existing label and new label is present' do
expect(find(issue_1_selector)).to have_content 'bug'
check 'Select all'
open_milestone_dropdown ['First Release']
open_labels_dropdown ['feature']
update_issues
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
end
end
context 'setting a milestone and removing existing label' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << feature
enable_bulk_update
end
it 'keeps existing label and new label is present' do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
check 'Select all'
open_milestone_dropdown ['First Release']
unmark_labels_in_dropdown ['feature']
update_issues
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).not_to have_content 'feature'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).not_to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
end
end
context 'unsetting a milestone' do
before do
issue1.milestone = milestone
issue2.milestone = milestone
issue1.save!
issue2.save!
issue1.labels << bug
issue2.labels << feature
enable_bulk_update
end
it 'keeps labels' do
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
check 'Select all'
open_milestone_dropdown(['No milestone'])
update_issues
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).not_to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'First Release'
end
end
end
context 'toggling checked issues' do
before do
issue1.labels << bug
enable_bulk_update
end
it do
expect(find(issue_1_selector)).to have_content 'bug'
check_issue issue1
open_labels_dropdown ['feature']
uncheck_issue issue1
check_issue issue1
update_issues
sleep 1 # needed
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
end
end
context 'mark previously toggled label' do
before do
enable_bulk_update
end
it do
open_labels_dropdown ['feature']
check_issue issue1
update_issues
expect(find(issue_1_selector)).to have_content 'feature'
end
end
# Special case https://gitlab.com/gitlab-org/gitlab-foss/issues/24877
context 'unmarking common label' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
enable_bulk_update
end
it 'applies label from filtered results' do
check 'Select all'
within('aside[aria-label="Bulk update"]') do
click_button 'Select labels'
wait_for_requests
expect(page).to have_link 'bug', class: 'is-active'
expect(page).to have_link 'feature', class: 'is-indeterminate'
click_link 'bug'
fill_in 'Search', with: 'wontfix'
click_link 'wontfix'
end
update_issues
first_issue = find(issue_1_selector)
expect(first_issue).not_to have_content 'bug'
expect(first_issue).to have_content 'feature'
expect(first_issue).to have_content 'wontfix'
second_issue = find(issue_2_selector)
expect(second_issue).not_to have_content 'bug'
expect(second_issue).not_to have_content 'feature'
expect(second_issue).to have_content 'wontfix'
end
end
end
context 'as a guest' do
before do
sign_in user
visit project_issues_path(project)
end
context 'cannot bulk assign labels' do
it do
expect(page).not_to have_button 'Edit issues'
expect(page).not_to have_unchecked_field 'Select all'
expect(page).not_to have_unchecked_field issue1.title
end
end
end
def open_milestone_dropdown(items = [])
click_button 'Select milestone'
wait_for_requests
items.map do |item|
click_button item
end
end
def open_labels_dropdown(items = [], unmark = false)
within('aside[aria-label="Bulk update"]') do
click_button 'Select labels'
wait_for_requests
items.map do |item|
click_link item
end
if unmark
items.map do |item|
# Make sure we are unmarking the item no matter the state it has currently
click_link item until find('a', text: item)[:class].include? 'label-item'
end
end
end
end
def unmark_labels_in_dropdown(items = [])
open_labels_dropdown(items, true)
end
def check_issue(issue, uncheck = false)
if uncheck
uncheck issue.title
else
check issue.title
end
end
def uncheck_issue(issue)
check_issue(issue, true)
end
def update_issues
click_button 'Update all'
wait_for_requests
end
def enable_bulk_update
visit project_issues_path(project)
wait_for_requests
click_button 'Edit issues'
end
def disable_bulk_update
click_button 'Cancel'
end
end
|