summaryrefslogtreecommitdiff
path: root/spec/features/merge_requests/diff_notes_spec.rb
blob: f5bc05436618330030214b28f4a5e98964deb73d (plain)
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
require 'spec_helper'

feature 'Diff notes', js: true, feature: true do
  include WaitForAjax

  before do
    login_as :admin
    @merge_request = create(:merge_request)
    @project = @merge_request.source_project
  end

  context 'merge request diffs' do
    let(:comment_button_class) { '.add-diff-note' }
    let(:notes_holder_input_class) { 'js-temp-notes-holder' }
    let(:notes_holder_input_xpath) { './following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' }
    let(:test_note_comment) { 'this is a test note!' }

    context 'when hovering over the parallel view diff file' do
      before(:each) do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'parallel')
      end

      context 'with an old line on the left and no line on the right' do
        it 'should allow commenting on the left side' do
          should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'left')
        end

        it 'should not allow commenting on the right side' do
          should_not_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'right')
=======
        visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
        click_link 'Side-by-side'
      end

      context 'with an old line on the left and no line on the right' do
        let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..') }

        it 'should allow commenting on the left side' do
          should_allow_commenting line_holder, 'left'
        end

        it 'should not allow commenting on the right side' do
          should_not_allow_commenting line_holder, 'right'
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with no line on the left and a new line on the right' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should not allow commenting on the left side' do
          should_not_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'left')
        end

        it 'should allow commenting on the right side' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'right')
=======
        let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..') }

        it 'should not allow commenting on the left side' do
          should_not_allow_commenting line_holder, 'left'
        end

        it 'should allow commenting on the right side' do
          should_allow_commenting line_holder, 'right'
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with an old line on the left and a new line on the right' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should allow commenting on the left side' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'left')
        end

        it 'should allow commenting on the right side' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'right')
=======
        let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..') }

        it 'should allow commenting on the left side' do
          should_allow_commenting line_holder, 'left'
        end

        it 'should allow commenting on the right side' do
          should_allow_commenting line_holder, 'right'
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with an unchanged line on the left and an unchanged line on the right' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should allow commenting on the left side' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left')
        end

        it 'should allow commenting on the right side' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right')
=======
        let(:line_holder) { first('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]').find(:xpath, '..') }

        it 'should allow commenting on the left side' do
          should_allow_commenting line_holder, 'left'
        end

        it 'should allow commenting on the right side' do
          should_allow_commenting line_holder, 'right'
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with a match line' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should not allow commenting on the left side' do
          should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'left')
        end

        it 'should not allow commenting on the right side' do
          should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'right')
=======
        let(:line_holder) { first('.match').find(:xpath, '..') }

        it 'should not allow commenting on the left side' do
          should_not_allow_commenting line_holder, 'left'
        end

        it 'should not allow commenting on the right side' do
          should_not_allow_commenting line_holder, 'right'
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end
    end

    context 'when hovering over the inline view diff file' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
      before do
        visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'inline')
      end

      context 'with a new line' do
        it 'should allow commenting' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
=======
      let(:comment_button_class) { '.add-diff-note' }

      before(:each) do
        visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
        click_link 'Inline'
      end

      context 'with a new line' do
        let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]') }

        it 'should allow commenting' do
          should_allow_commenting line_holder
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with an old line' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should allow commenting' do
          should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
=======
        let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]') }

        it 'should allow commenting' do
          should_allow_commenting line_holder
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with an unchanged line' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should allow commenting' do
          should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
=======
        let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]') }

        it 'should allow commenting' do
          should_allow_commenting line_holder
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end

      context 'with a match line' do
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        it 'should not allow commenting' do
          should_not_allow_commenting(find('.match', match: :first))
=======
        let(:line_holder) { first('.match') }

        it 'should not allow commenting' do
          should_not_allow_commenting line_holder
        end
      end

      context 'with an unfolded line' do
        before(:each) do
          first('.js-unfold').click
          wait_for_ajax
        end

        # The first `.js-unfold` unfolds upwards, therefore the first
        # `.line_holder` will be an unfolded line.
        let(:line_holder) { first('.line_holder[id="1"]') }

        it 'should not allow commenting' do
          should_not_allow_commenting line_holder
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
        end
      end
    end

    def should_allow_commenting(line_holder, diff_side = nil)
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
      line = get_line_components(line_holder, diff_side)
      line[:content].hover
      expect(line[:num]).to have_css comment_button_class

      comment_on_line(line_holder, line)

      assert_comment_persistence(line_holder)
    end

    def should_not_allow_commenting(line_holder, diff_side = nil)
      line = get_line_components(line_holder, diff_side)
=======
      line = get_line_components line_holder, diff_side
      line[:content].hover
      expect(line[:num]).to have_css comment_button_class

      comment_on_line line_holder, line
      wait_for_ajax

      assert_comment_persistence line_holder
    end

    def should_not_allow_commenting(line_holder, diff_side = nil)
      line = get_line_components line_holder, diff_side
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
      line[:content].hover
      expect(line[:num]).not_to have_css comment_button_class
    end

    def get_line_components(line_holder, diff_side = nil)
      if diff_side.nil?
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
        get_inline_line_components(line_holder)
      else
        get_parallel_line_components(line_holder, diff_side)
=======
        get_inline_line_components line_holder
      else
        get_parallel_line_components line_holder, diff_side
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
      end
    end

    def get_inline_line_components(line_holder)
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
      { content: line_holder.find('.line_content', match: :first), num: line_holder.find('.diff-line-num', match: :first) }
=======
      { content: line_holder.first('.line_content'), num: line_holder.first('.diff-line-num') }
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
    end

    def get_parallel_line_components(line_holder, diff_side = nil)
      side_index = diff_side == 'left' ? 0 : 1
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
      # Wait for `.line_content`
      line_holder.find('.line_content', match: :first)
      # Wait for `.diff-line-num`
      line_holder.find('.diff-line-num', match: :first)
=======
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
      { content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] }
    end

    def comment_on_line(line_holder, line)
      line[:num].find(comment_button_class).trigger 'click'
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
      line_holder.find(:xpath, notes_holder_input_xpath)

      notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath)
      expect(notes_holder_input[:class]).to include(notes_holder_input_class)

      notes_holder_input.fill_in 'note[note]', with: test_note_comment
      click_button 'Comment'
      wait_for_ajax
=======
      expect(line_holder).to have_xpath notes_holder_input_xpath

      notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath)
      expect(notes_holder_input[:class].include? notes_holder_input_class).to be true

      notes_holder_input.fill_in 'note[note]', with: test_note_comment
      click_button 'Comment'
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
    end

    def assert_comment_persistence(line_holder)
      expect(line_holder).to have_xpath notes_holder_input_xpath

      notes_holder_saved = line_holder.find(:xpath, notes_holder_input_xpath)
<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42
      expect(notes_holder_saved[:class]).not_to include(notes_holder_input_class)
=======
      expect(notes_holder_saved[:class].include? notes_holder_input_class).to be false
>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125)
      expect(notes_holder_saved).to have_content test_note_comment
    end
  end
end