merge_requests.rb 17.1 KB
Newer Older
1
class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
Nihad Abbasov's avatar
Nihad Abbasov committed
2
  include SharedAuthentication
3
  include SharedIssuable
Nihad Abbasov's avatar
Nihad Abbasov committed
4 5 6
  include SharedProject
  include SharedNote
  include SharedPaths
7
  include SharedMarkdown
8
  include SharedDiffNote
9
  include SharedUser
Nihad Abbasov's avatar
Nihad Abbasov committed
10

11
  step 'I click link "New Merge Request"' do
12
    click_link "New Merge Request"
13 14
  end

15
  step 'I click link "Bug NS-04"' do
16 17 18
    click_link "Bug NS-04"
  end

19 20 21 22
  step 'I click link "Feature NS-05"' do
    click_link "Feature NS-05"
  end

23
  step 'I click link "All"' do
24
    click_link "All"
25 26
  end

27 28 29 30
  step 'I click link "Merged"' do
    click_link "Merged"
  end

31 32
  step 'I click link "Closed"' do
    click_link "Closed"
33 34
  end

35
  step 'I should see merge request "Wiki Feature"' do
36
    page.within '.merge-request' do
37
      expect(page).to have_content "Wiki Feature"
38
    end
39 40
  end

41
  step 'I should see closed merge request "Bug NS-04"' do
skv's avatar
skv committed
42
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
Robert Speicher's avatar
Robert Speicher committed
43
    expect(merge_request).to be_closed
44
    expect(page).to have_content "Closed by"
45 46
  end

47
  step 'I should see merge request "Bug NS-04"' do
48
    expect(page).to have_content "Bug NS-04"
49 50
  end

51 52 53 54
  step 'I should see merge request "Feature NS-05"' do
    expect(page).to have_content "Feature NS-05"
  end

55
  step 'I should not see "master" branch' do
56
    expect(find('.merge-request-info')).not_to have_content "master"
57 58 59 60 61 62
  end

  step 'I should see "other_branch" branch' do
    expect(page).to have_content "other_branch"
  end

63
  step 'I should see "Bug NS-04" in merge requests' do
64
    expect(page).to have_content "Bug NS-04"
65 66
  end

67
  step 'I should see "Feature NS-03" in merge requests' do
68
    expect(page).to have_content "Feature NS-03"
69 70
  end

71
  step 'I should not see "Feature NS-03" in merge requests' do
72
    expect(page).not_to have_content "Feature NS-03"
73 74
  end

75
  step 'I should not see "Bug NS-04" in merge requests' do
76
    expect(page).not_to have_content "Bug NS-04"
77 78
  end

Valery Sizov's avatar
tests  
Valery Sizov committed
79
  step 'I should see that I am subscribed' do
80
    expect(find('.issuable-subscribe-button span')).to have_content 'Unsubscribe'
Valery Sizov's avatar
tests  
Valery Sizov committed
81 82 83
  end

  step 'I should see that I am unsubscribed' do
84
    expect(find('.issuable-subscribe-button span')).to have_content 'Subscribe'
Valery Sizov's avatar
tests  
Valery Sizov committed
85 86 87 88 89 90
  end

  step 'I click button "Unsubscribe"' do
    click_on "Unsubscribe"
  end

91
  step 'I click link "Close"' do
92
    first(:css, '.close-mr-link').click
93 94
  end

95
  step 'I submit new merge request "Wiki Feature"' do
Phil Hughes's avatar
Phil Hughes committed
96 97 98 99 100 101
    find('.js-source-branch').click
    find('.dropdown-source-branch .dropdown-content a', text: 'fix').click

    find('.js-target-branch').click
    first('.dropdown-target-branch .dropdown-content a', text: 'feature').click

102 103
    click_button "Compare branches"
    fill_in "merge_request_title", with: "Wiki Feature"
104
    click_button "Submit merge request"
105 106
  end

107
  step 'project "Shop" have "Bug NS-04" open merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
108
    create(:merge_request,
109
           title: "Bug NS-04",
110 111
           source_project: project,
           target_project: project,
112
           source_branch: 'fix',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
113
           target_branch: 'master',
114 115 116
           author: project.users.first,
           description: "# Description header"
          )
117 118
  end

119 120 121 122 123 124 125 126 127 128 129 130
  step 'project "Shop" have "Bug NS-06" open merge request' do
    create(:merge_request,
           title: "Bug NS-06",
           source_project: project,
           target_project: project,
           source_branch: 'fix',
           target_branch: 'other_branch',
           author: project.users.first,
           description: "# Description header"
          )
  end

131
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
132 133
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
134 135
           source_project: project,
           target_project: project,
136
           author: project.users.first)
137 138 139 140 141 142 143
  end

  step 'project "Shop" have "Feature NS-05" merged merge request' do
    create(:merged_merge_request,
           title: "Feature NS-05",
           source_project: project,
           target_project: project,
144
           author: project.users.first)
145 146
  end

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  step 'project "Shop" have "Bug NS-07" open merge request with rebased branch' do
    create(:merge_request, :rebased,
      title: "Bug NS-07",
      source_project: project,
      target_project: project,
      author: project.users.first)
  end

  step 'project "Shop" have "Bug NS-08" open merge request with diverged branch' do
    create(:merge_request, :diverged,
      title: "Bug NS-08",
      source_project: project,
      target_project: project,
      author: project.users.first)
  end

163
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
164
    create(:closed_merge_request,
165
           title: "Feature NS-03",
166 167
           source_project: project,
           target_project: project,
Andrew8xx8's avatar
Andrew8xx8 committed
168
           author: project.users.first)
169 170
  end

171 172 173 174 175 176 177 178 179
  step 'project "Community" has "Bug CO-01" open merge request with diffs inside' do
    project = Project.find_by(name: "Community")
    create(:merge_request_with_diffs,
           title: "Bug CO-01",
           source_project: project,
           target_project: project,
           author: project.users.first)
  end

180 181
  step 'merge request "Bug NS-04" have 2 upvotes and 1 downvote' do
    merge_request = MergeRequest.find_by(title: 'Bug NS-04')
182 183
    create_list(:award_emoji, 2, awardable: merge_request)
    create(:award_emoji, :downvote, awardable: merge_request)
184 185 186
  end

  step 'merge request "Bug NS-06" have 1 upvote and 2 downvotes' do
187
    awardable = MergeRequest.find_by(title: 'Bug NS-06')
188
    create(:award_emoji, awardable: awardable)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
189
    create_list(:award_emoji, 2, :downvote, awardable: awardable)
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
  end

  step 'The list should be sorted by "Least popular"' do
    page.within '.mr-list' do
      page.within 'li.merge-request:nth-child(1)' do
        expect(page).to have_content 'Bug NS-06'
        expect(page).to have_content '1 2'
      end

      page.within 'li.merge-request:nth-child(2)' do
        expect(page).to have_content 'Bug NS-04'
        expect(page).to have_content '2 1'
      end

      page.within 'li.merge-request:nth-child(3)' do
        expect(page).to have_content 'Bug NS-05'
206
        expect(page).not_to have_content '0 0'
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
      end
    end
  end

  step 'The list should be sorted by "Most popular"' do
    page.within '.mr-list' do
      page.within 'li.merge-request:nth-child(1)' do
        expect(page).to have_content 'Bug NS-04'
        expect(page).to have_content '2 1'
      end

      page.within 'li.merge-request:nth-child(2)' do
        expect(page).to have_content 'Bug NS-06'
        expect(page).to have_content '1 2'
      end

      page.within 'li.merge-request:nth-child(3)' do
        expect(page).to have_content 'Bug NS-05'
225
        expect(page).not_to have_content '0 0'
226 227 228 229
      end
    end
  end

230
  step 'I click on the Changes tab' do
231
    page.within '.merge-request-tabs' do
232 233 234
      click_link 'Changes'
    end

235 236
    # Waits for load
    expect(page).to have_css('.tab-content #diffs.active')
237 238 239
  end

  step 'I should see the proper Inline and Side-by-side links' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
240 241
    expect(page).to have_css('#parallel-diff-btn', count: 1)
    expect(page).to have_css('#inline-diff-btn', count: 1)
242 243
  end

244
  step 'I switch to the merge request\'s comments tab' do
Vinnie Okada's avatar
Vinnie Okada committed
245
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
246 247
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
248
  step 'I click on the commit in the merge request' do
249
    page.within '.merge-request-tabs' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
250 251 252
      click_link 'Commits'
    end

253
    page.within '.commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
254
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
255
    end
256 257
  end

258
  step 'I leave a comment on the diff page' do
259
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
260 261
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
262

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
263
  step 'I leave a comment on the diff page in commit' do
264
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
265
    leave_comment "One comment to rule them all"
266 267
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
268
  step 'I leave a comment like "Line is wrong" on diff' do
269
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
270 271
    leave_comment "Line is wrong"
  end
272

273 274
  step 'user "John Doe" leaves a comment like "Line is wrong" on diff' do
    mr = MergeRequest.find_by(title: "Bug NS-05")
Douwe Maan's avatar
Douwe Maan committed
275
    create(:diff_note_on_merge_request, project: project,
Grzegorz Bizon's avatar
Grzegorz Bizon committed
276
                                        noteable: mr,
277 278 279 280
                                        author: user_exists("John Doe"),
                                        note: 'Line is wrong')
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
281
  step 'I leave a comment like "Line is wrong" on diff in commit' do
282
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
283
    leave_comment "Line is wrong"
284 285
  end

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
  step 'I change the comment "Line is wrong" to "Typo, please fix" on diff' do
    page.within('.diff-file:nth-of-type(5) .note') do
      find('.js-note-edit').click

      page.within('.current-note-edit-form', visible: true) do
        fill_in 'note_note', with: 'Typo, please fix'
        click_button 'Save Comment'
      end

      expect(page).not_to have_button 'Save Comment', disabled: true, visible: true
    end
  end

  step 'I should not see a diff comment saying "Line is wrong"' do
    page.within('.diff-file:nth-of-type(5) .note') do
      expect(page).not_to have_visible_content 'Line is wrong'
    end
  end

  step 'I should see a diff comment saying "Typo, please fix"' do
    page.within('.diff-file:nth-of-type(5) .note') do
      expect(page).to have_visible_content 'Typo, please fix'
    end
  end

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
  step 'I delete the comment "Line is wrong" on diff' do
    page.within('.diff-file:nth-of-type(5) .note') do
      find('.js-note-delete').click
    end
  end

  step 'I click on the Discussion tab' do
    page.within '.merge-request-tabs' do
      click_link 'Discussion'
    end

    # Waits for load
    expect(page).to have_css('.tab-content #notes.active')
  end

  step 'I should not see any discussion' do
    expect(page).not_to have_css('.notes .discussion')
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
330
  step 'I should see a discussion has started on diff' do
Robert Speicher's avatar
Robert Speicher committed
331
    page.within(".notes .discussion") do
Phil Hughes's avatar
Phil Hughes committed
332
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion"
Robert Speicher's avatar
Robert Speicher committed
333 334 335
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
336 337
  end

338 339
  step 'I should see a discussion by user "John Doe" has started on diff' do
    page.within(".notes .discussion") do
Phil Hughes's avatar
Phil Hughes committed
340
      page.should have_content "#{user_exists("John Doe").name} #{user_exists("John Doe").to_reference} started a discussion"
341 342 343 344 345 346 347 348 349 350 351 352 353
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
  end

  step 'I should see a badge of "1" next to the discussion link' do
    expect_discussion_badge_to_have_counter("1")
  end

  step 'I should see a badge of "0" next to the discussion link' do
    expect_discussion_badge_to_have_counter("0")
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
354
  step 'I should see a discussion has started on commit diff' do
Robert Speicher's avatar
Robert Speicher committed
355
    page.within(".notes .discussion") do
Phil Hughes's avatar
Phil Hughes committed
356
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
Robert Speicher's avatar
Robert Speicher committed
357 358 359
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
360 361
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
362
  step 'I should see a discussion has started on commit' do
Robert Speicher's avatar
Robert Speicher committed
363
    page.within(".notes .discussion") do
Phil Hughes's avatar
Phil Hughes committed
364
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
Robert Speicher's avatar
Robert Speicher committed
365 366
      page.should have_content "One comment to rule them all"
    end
367
  end
368

369
  step 'merge request is mergeable' do
370
    expect(page).to have_button 'Accept Merge Request'
371 372 373 374
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
375
    fill_in 'commit_message', with: 'wow such merge'
376 377 378 379 380 381 382
  end

  step 'merge request "Bug NS-05" is mergeable' do
    merge_request.mark_as_mergeable
  end

  step 'I accept this merge request' do
383
    page.within '.mr-state-widget' do
384 385
      click_button "Accept Merge Request"
    end
386 387 388
  end

  step 'I should see merged request' do
389
    page.within '.status-box' do
390
      expect(page).to have_content "Merged"
391 392 393
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
394
  step 'I click link "Reopen"' do
395
    first(:css, '.reopen-mr-link').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
396 397 398
  end

  step 'I should see reopened merge request "Bug NS-04"' do
399
    page.within '.status-box' do
400
      expect(page).to have_content "Open"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
401 402 403
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
404 405
  step 'I click link "Hide inline discussion" of the third file' do
    page.within '.files [id^=diff]:nth-child(3)' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
406
      find('.js-toggle-diff-comments').trigger('click')
407 408 409
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
410 411
  step 'I click link "Show inline discussion" of the third file' do
    page.within '.files [id^=diff]:nth-child(3)' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
412
      find('.js-toggle-diff-comments').trigger('click')
413 414 415
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
416 417
  step 'I should not see a comment like "Line is wrong" in the third file' do
    page.within '.files [id^=diff]:nth-child(3)' do
418
      expect(page).not_to have_visible_content "Line is wrong"
419 420 421
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
422 423
  step 'I should see a comment like "Line is wrong" in the third file' do
    page.within '.files [id^=diff]:nth-child(3) .note-body > .note-text' do
424
      expect(page).to have_visible_content "Line is wrong"
425 426 427
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
428 429
  step 'I should not see a comment like "Line is wrong here" in the third file' do
    page.within '.files [id^=diff]:nth-child(3)' do
430
      expect(page).not_to have_visible_content "Line is wrong here"
431 432 433
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
434 435
  step 'I should see a comment like "Line is wrong here" in the third file' do
    page.within '.files [id^=diff]:nth-child(3) .note-body > .note-text' do
436
      expect(page).to have_visible_content "Line is wrong here"
437 438 439
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
440
  step 'I leave a comment like "Line is correct" on line 12 of the second file' do
441 442
    init_diff_note_first_file

443
    page.within(".js-discussion-note-form") do
444
      fill_in "note_note", with: "Line is correct"
Phil Hughes's avatar
Phil Hughes committed
445
      click_button "Comment"
446 447
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
448
    page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do
449
      expect(page).to have_content "Line is correct"
450 451 452
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
453
  step 'I leave a comment like "Line is wrong" on line 39 of the third file' do
454 455
    init_diff_note_second_file

456
    page.within(".js-discussion-note-form") do
457
      fill_in "note_note", with: "Line is wrong on here"
Phil Hughes's avatar
Phil Hughes committed
458
      click_button "Comment"
459 460 461
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
462 463
  step 'I should still see a comment like "Line is correct" in the second file' do
    page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do
464
      expect(page).to have_visible_content "Line is correct"
465 466 467
    end
  end

skv's avatar
skv committed
468
  step 'I unfold diff' do
469 470
    expect(page).to have_css('.js-unfold')

skv's avatar
skv committed
471 472 473 474 475 476 477
    first('.js-unfold').click
  end

  step 'I should see additional file lines' do
    expect(first('.text-file')).to have_content('.bundle')
  end

Marin Jankovski's avatar
Marin Jankovski committed
478
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
479
    find('a', text: 'Side-by-side').trigger('click')
480 481 482

    # Waits for load
    expect(page).to have_css('.parallel')
Marin Jankovski's avatar
Marin Jankovski committed
483 484 485
  end

  step 'I should see comments on the side-by-side diff page' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
486
    page.within '.files [id^=diff]:nth-child(2) .parallel .note-body > .note-text' do
487
      expect(page).to have_visible_content "Line is correct"
Marin Jankovski's avatar
Marin Jankovski committed
488 489 490
    end
  end

491
  step 'I fill in merge request search with "Fe"' do
Phil Hughes's avatar
Phil Hughes committed
492
    sleep 1
493 494 495
    fill_in 'issue_search', with: "Fe"
  end

496
  step 'I click the "Target branch" dropdown' do
Phil Hughes's avatar
Phil Hughes committed
497
    expect(page).to have_content('Target branch')
498 499 500 501 502 503 504 505 506
    first('.target_branch').click
  end

  step 'I select a new target branch' do
    select "feature", from: "merge_request_target_branch"
    click_button 'Save'
  end

  step 'I should see new target branch changes' do
Douwe Maan's avatar
Douwe Maan committed
507
    expect(page).to have_content 'Request to merge fix into feature'
508
    expect(page).to have_content 'Target branch changed from master to feature'
509 510
  end

511 512 513 514 515 516 517 518 519 520 521 522
  step 'I click on "Email Patches"' do
    click_link "Email Patches"
  end

  step 'I click on "Plain Diff"' do
    click_link "Plain Diff"
  end

  step 'I should see a patch diff' do
    expect(page).to have_content('diff --git')
  end

523 524 525
  step '"Bug NS-05" has CI status' do
    project = merge_request.source_project
    project.enable_ci
526
    pipeline = create :ci_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch
527
    create :ci_build, pipeline: pipeline
528 529
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
530 531
  step 'I should see merge request "Bug NS-05" with CI status' do
    page.within ".mr-list" do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
532
      expect(page).to have_link "Pipeline: pending"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
533 534
    end
  end
535

536 537 538 539 540 541 542 543 544 545 546 547
  step 'I should see the diverged commits count' do
    page.within ".mr-source-target" do
      expect(page).to have_content /([0-9]+ commits behind)/
    end
  end

  step 'I should not see the diverged commits count' do
    page.within ".mr-source-target" do
      expect(page).not_to have_content /([0-9]+ commit[s]? behind)/
    end
  end

548
  def merge_request
skv's avatar
skv committed
549
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
550
  end
551 552

  def init_diff_note
553
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
554 555 556
  end

  def leave_comment(message)
Robert Speicher's avatar
Robert Speicher committed
557
    page.within(".js-discussion-note-form", visible: true) do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
558
      fill_in "note_note", with: message
Phil Hughes's avatar
Phil Hughes committed
559
      click_button "Comment"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
560
    end
Robert Speicher's avatar
Robert Speicher committed
561 562 563
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
564
  end
565 566

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
567
    click_diff_line(sample_compare.changes[0][:line_code])
568 569 570
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
571
    click_diff_line(sample_compare.changes[1][:line_code])
572 573
  end

574
  def have_visible_content(text)
575 576
    have_css("*", text: text, visible: true)
  end
577 578 579 580 581 582

  def expect_discussion_badge_to_have_counter(value)
    page.within(".notes-tab .badge") do
      page.should have_content value
    end
  end
583
end