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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Merge request > Batch comments', :js do
include MergeRequestDiffHelpers
include RepoHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:merge_request) do
create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test')
end
before do
project.add_maintainer(user)
sign_in(user)
end
context 'Feature is enabled' do
before do
visit_diffs
end
it 'has review bar' do
expect(page).to have_css('.review-bar-component', visible: false)
end
it 'adds draft note' do
write_comment
expect(find('.draft-note-component')).to have_content('Line is wrong')
expect(page).to have_css('.review-bar-component')
expect(find('.review-bar-content .btn-success')).to have_content('1')
end
it 'publishes review' do
write_comment
page.within('.review-bar-content') do
click_button 'Submit review'
end
wait_for_requests
expect(page).not_to have_selector('.draft-note-component', text: 'Line is wrong')
expect(page).to have_selector('.note:not(.draft-note)', text: 'Line is wrong')
end
it 'publishes single comment' do
write_comment
click_button 'Add comment now'
wait_for_requests
expect(page).not_to have_selector('.draft-note-component', text: 'Line is wrong')
expect(page).to have_selector('.note:not(.draft-note)', text: 'Line is wrong')
end
it 'deletes draft note' do
write_comment
accept_alert { find('.js-note-delete').click }
wait_for_requests
expect(page).not_to have_selector('.draft-note-component', text: 'Line is wrong')
end
it 'edits draft note' do
write_comment
find('.js-note-edit').click
# make sure comment form is in view
execute_script("window.scrollBy(0, 200)")
page.within('.js-discussion-note-form') do
fill_in('note_note', with: 'Testing update')
click_button('Save comment')
end
wait_for_requests
expect(page).to have_selector('.draft-note-component', text: 'Testing update')
end
context 'in parallel diff' do
before do
find('.js-show-diff-settings').click
click_button 'Side-by-side'
end
it 'adds draft comments to both sides' do
write_parallel_comment('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9')
# make sure line 9 is in the view
execute_script("window.scrollBy(0, -200)")
write_parallel_comment('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9', button_text: 'Add to review', text: 'Another wrong line')
expect(find('.new .draft-note-component')).to have_content('Line is wrong')
expect(find('.old .draft-note-component')).to have_content('Another wrong line')
expect(find('.review-bar-content .btn-success')).to have_content('2')
end
end
context 'thread is unresolved' do
let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
before do
visit_diffs
end
it 'publishes comment right away and resolves the thread' do
expect(active_discussion.resolved?).to eq(false)
write_reply_to_discussion(button_text: 'Add comment now', resolve: true)
page.within '.line-resolve-all-container' do
expect(page).to have_content('All threads resolved')
expect(page).to have_selector('.line-resolve-btn.is-active')
end
end
it 'publishes review and resolves the thread' do
expect(active_discussion.resolved?).to eq(false)
write_reply_to_discussion(resolve: true)
page.within('.review-bar-content') do
click_button 'Submit review'
end
wait_for_requests
page.within '.line-resolve-all-container' do
expect(page).to have_content('All threads resolved')
expect(page).to have_selector('.line-resolve-btn.is-active')
end
end
end
context 'thread is resolved' do
let!(:active_discussion) { create(:diff_note_on_merge_request, :resolved, noteable: merge_request, project: project).to_discussion }
before do
active_discussion.resolve!(@current_user)
visit_diffs
page.find('.js-diff-comment-avatar').click
end
it 'publishes comment right away and unresolves the thread' do
expect(active_discussion.resolved?).to eq(true)
write_reply_to_discussion(button_text: 'Add comment now', unresolve: true)
page.within '.line-resolve-all-container' do
expect(page).to have_content('1 unresolved thread')
expect(page).not_to have_selector('.line-resolve-btn.is-active')
end
end
it 'publishes review and unresolves the thread' do
expect(active_discussion.resolved?).to eq(true)
wait_for_requests
write_reply_to_discussion(button_text: 'Start a review', unresolve: true)
page.within('.review-bar-content') do
click_button 'Submit review'
end
wait_for_requests
page.within '.line-resolve-all-container' do
expect(page).to have_content('1 unresolved thread')
expect(page).not_to have_selector('.line-resolve-btn.is-active')
end
end
end
end
def visit_diffs
visit diffs_project_merge_request_path(merge_request.project, merge_request)
wait_for_requests
end
def write_comment(button_text: 'Start a review', text: 'Line is wrong')
click_diff_line(find("[id='#{sample_compare.changes[0][:line_code]}']"))
page.within('.js-discussion-note-form') do
fill_in('note_note', with: text)
click_button(button_text)
end
wait_for_requests
end
def write_parallel_comment(line, button_text: 'Start a review', text: 'Line is wrong')
find("td[id='#{line}']").hover
find(".is-over button").click
page.within("form[data-line-code='#{line}']") do
fill_in('note_note', with: text)
click_button(button_text)
end
wait_for_requests
end
end
def write_reply_to_discussion(button_text: 'Start a review', text: 'Line is wrong', resolve: false, unresolve: false)
page.within(first('.diff-files-holder .discussion-reply-holder')) do
click_button('Reply...')
fill_in('note_note', with: text)
if resolve
page.check('Resolve thread')
end
if unresolve
page.check('Unresolve thread')
end
click_button(button_text)
end
wait_for_requests
end
|