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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Merge request > User resolves diff notes and threads', :js, feature_category: :code_review_workflow do
include ContentEditorHelpers
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let(:guest) { create(:user) }
let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user, title: "Bug NS-04") }
let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, note: "| Markdown | Table |\n|-------|---------|\n| first | second |") }
let(:path) { "files/ruby/popen.rb" }
let(:position) do
build(:text_diff_position, file: path, old_line: nil, new_line: 9, diff_refs: merge_request.diff_refs)
end
before do
stub_feature_flags(moved_mr_sidebar: false)
end
context 'no threads' do
before do
project.add_maintainer(user)
sign_in(user)
note.destroy!
visit_merge_request
end
it 'displays no thread resolved data' do
expect(page).not_to have_content('thread resolved')
expect(page).not_to have_selector('.discussion-next-btn')
end
end
context 'as authorized user' do
before do
project.add_maintainer(user)
sign_in(user)
visit_merge_request
end
context 'single thread' do
it 'shows text with how many threads' do
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
it 'allows user to mark a note as resolved' do
page.within '.diff-content .note' do
find('.line-resolve-btn').click
expect(page).to have_selector('.line-resolve-btn.is-active')
expect(find('.line-resolve-btn')['aria-label']).to eq("Resolved by #{user.name}")
end
page.within '.diff-content' do
expect(page).to have_selector('.btn', text: 'Unresolve thread')
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to mark thread as resolved' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
end
expect(page).to have_selector('.discussion-body', visible: false)
page.within '.diff-content .note' do
expect(page).to have_selector('.line-resolve-btn.is-active')
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to unresolve thread' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
click_button 'Unresolve thread'
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
describe 'resolved thread' do
before do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
end
visit_merge_request
end
describe 'timeline view' do
it 'hides when resolve thread is clicked' do
expect(page).to have_selector('.discussion-header')
expect(page).not_to have_selector('.discussion-body')
end
it 'shows resolved thread when toggled' do
find(".timeline-content .discussion[data-discussion-id='#{note.discussion_id}'] .discussion-toggle-button").click
expect(page.find(".timeline-content #note_#{note.id}")).to be_visible
end
it 'renders tables in lazy-loaded resolved diff dicussions' do
find(".timeline-content .discussion[data-discussion-id='#{note.discussion_id}'] .discussion-toggle-button").click
wait_for_requests
expect(page.find(".timeline-content #note_#{note.id}")).not_to have_css(".line_holder")
expect(page.find(".timeline-content #note_#{note.id}")).to have_css("tr", count: 2)
end
end
describe 'side-by-side view' do
before do
page.within('.merge-request-tabs') { click_link 'Changes' }
find('.js-show-diff-settings').click
page.find('#parallel-diff-btn').click
end
it 'hides when resolve thread is clicked' do
expect(page).not_to have_selector('.diffs .diff-file .notes_holder')
end
it 'shows resolved thread when toggled', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/327439' do
find('.diff-comment-avatar-holders').click
expect(find('.diffs .diff-file .notes_holder')).to be_visible
end
end
describe 'reply form' do
before do
click_button _('Show thread')
end
it 'allows user to comment' do
page.within '.diff-content' do
find_field('Reply…').click
find(".js-unresolve-checkbox").set false
find('.js-note-text').set 'testing'
click_button 'Add comment now'
wait_for_requests
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to unresolve from reply form without a comment' do
page.within '.diff-content' do
click_button 'Unresolve thread'
wait_for_requests
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
it 'allows user to comment & unresolve thread' do
page.within '.diff-content' do
find_field('Reply…').click
find('.js-note-text').set 'testing'
click_button 'Add comment now'
wait_for_requests
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
end
end
it 'allows user to resolve from reply form without a comment' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to comment & resolve thread' do
page.within '.diff-content' do
find_field('Reply…').click
find('.js-note-text').set 'testing'
find('.js-resolve-checkbox').set(true)
click_button 'Add comment now'
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to quickly scroll to next unresolved thread', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/410109' do
page.within '.discussions-counter' do
page.find('.discussion-next-btn').click
end
expect(page).to have_button('Resolve thread', visible: true)
expect(page.evaluate_script("window.pageYOffset")).to be > 0
end
it 'hides jump to next button when all resolved' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
end
expect(page).to have_selector('.discussion-next-btn', visible: false)
end
it 'updates updated text after resolving note' do
page.within '.diff-content .note' do
resolve_button = find('.line-resolve-btn')
resolve_button.click
wait_for_requests
expect(resolve_button['aria-label']).to eq("Resolved by #{user.name}")
end
end
it 'hides jump to next thread button' do
page.within '.discussion-reply-holder' do
expect(page).not_to have_selector('.discussion-next-btn')
end
end
end
context 'multiple notes' do
before do
create(:diff_note_on_merge_request, project: project, noteable: merge_request, in_reply_to: note)
visit_merge_request
end
it 'marks thread as resolved when resolving single note' do
page.within("#note_#{note.id}") do
first('.line-resolve-btn').click
wait_for_requests
expect(first('.line-resolve-btn')['aria-label']).to eq("Resolved by #{user.name}")
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'resolves thread' do
resolve_buttons = page.all('.note .line-resolve-btn', count: 1)
resolve_buttons.each do |button|
button.click
end
wait_for_requests
resolve_buttons.each do |button|
expect(button['aria-label']).to eq("Resolved by #{user.name}")
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
end
context 'muliple threads' do
before do
create(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request)
visit_merge_request
end
it 'shows text with how many threads' do
page.within '.discussions-counter' do
expect(page).to have_content('2 unresolved threads')
end
end
it 'allows user to mark a single note as resolved' do
click_button('Resolve thread', match: :first)
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
it 'allows user to mark all notes as resolved' do
page.all('.note .line-resolve-btn', count: 2).each do |btn|
btn.click
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to mark all threads as resolved' do
page.all('.discussion-reply-holder', count: 2).each do |reply_holder|
page.within reply_holder do
find('button[data-testid="resolve-discussion-button"]').click
end
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to quickly scroll to next unresolved thread' do
page.within('.discussion-reply-holder', match: :first) do
find('button[data-testid="resolve-discussion-button"]').click
end
page.within '.discussions-counter' do
page.find('.discussion-next-btn').click
end
expect(page.evaluate_script("window.pageYOffset")).to be > 0
end
it 'updates updated text after resolving note' do
page.within('.diff-content .note', match: :first) do
resolve_button = find('.line-resolve-btn')
resolve_button.click
wait_for_requests
expect(resolve_button['aria-label']).to eq("Resolved by #{user.name}")
end
end
it 'displays next thread even if hidden' do
page.all('.note-discussion', count: 2).each do |discussion|
page.within discussion do
click_button _('Hide thread')
end
end
page.within('.issuable-discussion #notes') do
expect(page).not_to have_selector('.btn', text: 'Resolve thread')
end
page.within '.discussions-counter' do
page.find('.discussion-next-btn').click
end
page.all('.note-discussion').first do
expect(page.find('.discussion-with-resolve-btn')).to have_selector('.btn', text: 'Resolve thread')
end
page.all('.note-discussion').last do
expect(page.find('.discussion-with-resolve-btn')).not.to have_selector('.btn', text: 'Resolve thread')
end
end
end
context 'changes tab' do
it 'shows text with how many threads' do
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
it 'allows user to mark a note as resolved' do
page.within '.diff-content .note' do
find('.line-resolve-btn').click
expect(page).to have_selector('.line-resolve-btn.is-active')
end
page.within '.diff-content' do
expect(page).to have_selector('.btn', text: 'Unresolve thread')
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to mark thread as resolved' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
end
page.within '.diff-content .note' do
expect(page).to have_selector('.line-resolve-btn.is-active')
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to unresolve thread' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
click_button 'Unresolve thread'
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
it 'allows user to comment & resolve thread' do
page.within '.diff-content' do
find_field('Reply…').click
find('.js-note-text').set 'testing'
find('.js-resolve-checkbox').set(true)
click_button 'Add comment now'
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
it 'allows user to comment & unresolve thread' do
page.within '.diff-content' do
find('button[data-testid="resolve-discussion-button"]').click
wait_for_requests
find_field('Reply…').click
find('.js-unresolve-checkbox')
find('.js-note-text').set 'testing'
click_button 'Add comment now'
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
end
end
context 'as a guest' do
before do
project.add_guest(guest)
sign_in(guest)
end
context 'someone elses merge request' do
before do
visit_merge_request
end
it 'does not allow user to mark note as resolved' do
page.within '.diff-content .note' do
expect(page).not_to have_selector('.line-resolve-btn')
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
it 'does not allow user to mark thread as resolved' do
page.within '.diff-content .note' do
expect(page).not_to have_selector('.btn', text: 'Resolve thread')
end
end
end
context 'guest users merge request' do
let(:user) { guest }
before do
visit_merge_request
end
it 'allows user to mark a note as resolved' do
page.within '.diff-content .note' do
find('.line-resolve-btn').click
expect(page).to have_selector('.line-resolve-btn.is-active')
end
page.within '.diff-content' do
expect(page).to have_selector('.btn', text: 'Unresolve thread')
end
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
end
end
end
end
context 'unauthorized user' do
context 'no resolved comments' do
before do
visit_merge_request
end
it 'does not allow user to mark note as resolved' do
page.within '.diff-content .note' do
expect(page).not_to have_selector('.line-resolve-btn')
end
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
end
end
end
end
def visit_merge_request(mr = nil)
mr ||= merge_request
visit project_merge_request_path(mr.project, mr)
# Wait for MR widget to load
wait_for_requests
close_rich_text_promo_popover_if_present
end
end
|