BigW Consortium Gitlab

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

12
  after do
13
    wait_for_requests if javascript_test?
14 15
  end

16
  step 'I click link "New Merge Request"' do
17 18 19
    page.within '#content-body' do
      page.has_link?('New Merge Request') ? click_link("New Merge Request") : click_link('New merge request')
    end
20 21
  end

22
  step 'I click link "Bug NS-04"' do
23 24 25
    click_link "Bug NS-04"
  end

26 27 28 29
  step 'I click link "Feature NS-05"' do
    click_link "Feature NS-05"
  end

30
  step 'I click link "All"' do
31
    find('.issues-state-filters [data-state="all"] span', text: 'All').click
32 33
    # Waits for load
    expect(find('.issues-state-filters > .active')).to have_content 'All'
34 35
  end

36
  step 'I click link "Merged"' do
Annabel Dunstone Gray committed
37
    find('#state-merged').trigger('click')
38 39
  end

40
  step 'I click link "Closed"' do
41
    find('.issues-state-filters [data-state="closed"] span', text: 'Closed').click
42 43
  end

44
  step 'I should see merge request "Wiki Feature"' do
45
    page.within '.merge-request' do
46
      expect(page).to have_content "Wiki Feature"
47
    end
48
    wait_for_requests
49 50
  end

51
  step 'I should see closed merge request "Bug NS-04"' do
52
    expect(page).to have_content "Bug NS-04"
53
    expect(page).to have_content "Closed by"
54
    wait_for_requests
55 56
  end

57
  step 'I should see merge request "Bug NS-04"' do
58
    expect(page).to have_content "Bug NS-04"
59
    wait_for_requests
60 61
  end

62 63
  step 'I should see merge request "Feature NS-05"' do
    expect(page).to have_content "Feature NS-05"
64
    wait_for_requests
65 66
  end

67
  step 'I should not see "master" branch' do
Taurie Davis committed
68
    expect(find('.issuable-info')).not_to have_content "master"
69 70
  end

71 72
  step 'I should see "feature_conflict" branch' do
    expect(page).to have_content "feature_conflict"
73 74
  end

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

79
  step 'I should see "Feature NS-03" in merge requests' do
80
    expect(page).to have_content "Feature NS-03"
81 82
  end

83
  step 'I should not see "Feature NS-03" in merge requests' do
84
    expect(page).not_to have_content "Feature NS-03"
85 86
  end

87
  step 'I should not see "Bug NS-04" in merge requests' do
88
    expect(page).not_to have_content "Bug NS-04"
89 90
  end

Valery Sizov committed
91
  step 'I should see that I am subscribed' do
92
    expect(find('.issuable-subscribe-button span')).to have_content 'Unsubscribe'
Valery Sizov committed
93 94 95
  end

  step 'I should see that I am unsubscribed' do
96
    expect(find('.issuable-subscribe-button span')).to have_content 'Subscribe'
Valery Sizov committed
97 98 99 100
  end

  step 'I click button "Unsubscribe"' do
    click_on "Unsubscribe"
101
    wait_for_requests
Valery Sizov committed
102 103
  end

104
  step 'I click link "Close"' do
105
    first(:css, '.close-mr-link').click
106 107
  end

108
  step 'I submit new merge request "Wiki Feature"' do
Phil Hughes committed
109 110 111 112 113 114
    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

115 116
    click_button "Compare branches"
    fill_in "merge_request_title", with: "Wiki Feature"
117
    click_button "Submit merge request"
118 119
  end

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

132 133 134 135 136 137
  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',
138
           target_branch: 'feature_conflict',
139 140 141 142 143
           author: project.users.first,
           description: "# Description header"
          )
  end

144
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
145 146
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
147 148
           source_project: project,
           target_project: project,
149 150
           author: project.users.first,
           source_branch: 'merge-test')
151 152 153 154 155 156 157
  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,
158
           author: project.users.first)
159 160
  end

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  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

177
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8 committed
178
    create(:closed_merge_request,
179
           title: "Feature NS-03",
180 181
           source_project: project,
           target_project: project,
Andrew8xx8 committed
182
           author: project.users.first)
183 184
  end

185 186 187 188 189 190 191 192 193
  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

194 195
  step 'merge request "Bug NS-04" have 2 upvotes and 1 downvote' do
    merge_request = MergeRequest.find_by(title: 'Bug NS-04')
196 197
    create_list(:award_emoji, 2, awardable: merge_request)
    create(:award_emoji, :downvote, awardable: merge_request)
198 199 200
  end

  step 'merge request "Bug NS-06" have 1 upvote and 2 downvotes' do
201
    awardable = MergeRequest.find_by(title: 'Bug NS-06')
202
    create(:award_emoji, awardable: awardable)
203
    create_list(:award_emoji, 2, :downvote, awardable: awardable)
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
  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'
220
        expect(page).not_to have_content '0 0'
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
      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'
239
        expect(page).not_to have_content '0 0'
240 241 242 243
      end
    end
  end

244
  step 'I click on the Changes tab' do
245
    page.within '.merge-request-tabs' do
246 247 248
      click_link 'Changes'
    end

249 250
    # Waits for load
    expect(page).to have_css('.tab-content #diffs.active')
251 252 253
  end

  step 'I should see the proper Inline and Side-by-side links' do
Dmitriy Zaporozhets committed
254 255
    expect(page).to have_css('#parallel-diff-btn', count: 1)
    expect(page).to have_css('#inline-diff-btn', count: 1)
256 257
  end

258
  step 'I switch to the merge request\'s comments tab' do
259
    visit project_merge_request_path(project, merge_request)
260 261
  end

Dmitriy Zaporozhets committed
262
  step 'I click on the commit in the merge request' do
263
    page.within '.merge-request-tabs' do
Dmitriy Zaporozhets committed
264 265 266
      click_link 'Commits'
    end

267
    page.within '.commits' do
Dmitriy Zaporozhets committed
268
      click_link Commit.truncate_sha(sample_commit.id)
269
    end
270 271
  end

272
  step 'I leave a comment on the diff page' do
273
    init_diff_note
274 275
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets committed
276

277
  step 'I leave a comment on the diff page in commit' do
278
    click_diff_line(sample_commit.line_code)
279
    leave_comment "One comment to rule them all"
280 281
  end

Dmitriy Zaporozhets committed
282
  step 'I leave a comment like "Line is wrong" on diff' do
283
    init_diff_note
284 285
    leave_comment "Line is wrong"
  end
286

287 288
  step 'user "John Doe" leaves a comment like "Line is wrong" on diff' do
    mr = MergeRequest.find_by(title: "Bug NS-05")
Douwe Maan committed
289
    create(:diff_note_on_merge_request, project: project,
Grzegorz Bizon committed
290
                                        noteable: mr,
291 292 293 294
                                        author: user_exists("John Doe"),
                                        note: 'Line is wrong')
  end

Dmitriy Zaporozhets committed
295
  step 'I leave a comment like "Line is wrong" on diff in commit' do
296
    click_diff_line(sample_commit.line_code)
297
    leave_comment "Line is wrong"
298 299
  end

300 301 302 303 304 305
  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'
306
        click_button 'Save comment'
307 308
      end

309
      expect(page).not_to have_button 'Save comment', disabled: true, visible: true
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    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

325 326
  step 'I delete the comment "Line is wrong" on diff' do
    page.within('.diff-file:nth-of-type(5) .note') do
327 328 329
      find('.more-actions').click
      find('.more-actions .dropdown-menu li', match: :first)

330 331 332 333 334 335
      find('.js-note-delete').click
    end
  end

  step 'I click on the Discussion tab' do
    page.within '.merge-request-tabs' do
Annabel Dunstone Gray committed
336
      find('.notes-tab').trigger('click')
337 338 339 340 341 342 343 344 345 346
    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 committed
347
  step 'I should see a discussion has started on diff' do
Robert Speicher committed
348
    page.within(".notes .discussion") do
Phil Hughes committed
349
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion"
Robert Speicher committed
350 351 352
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
353 354
  end

355
  step 'I should see a discussion by user "John Doe" has started on diff' do
Douwe Maan committed
356 357
    # Trigger a refresh of notes
    execute_script("$(document).trigger('visibilitychange');")
358
    wait_for_requests
359
    page.within(".notes .discussion") do
Phil Hughes committed
360
      page.should have_content "#{user_exists("John Doe").name} #{user_exists("John Doe").to_reference} started a discussion"
361 362 363 364 365 366 367
      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")
368
    wait_for_requests
369 370 371 372
  end

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

Dmitriy Zaporozhets committed
376
  step 'I should see a discussion has started on commit diff' do
Robert Speicher committed
377
    page.within(".notes .discussion") do
Phil Hughes committed
378
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
Robert Speicher committed
379 380
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
381
      wait_for_requests
Robert Speicher committed
382
    end
383 384
  end

Dmitriy Zaporozhets committed
385
  step 'I should see a discussion has started on commit' do
Robert Speicher committed
386
    page.within(".notes .discussion") do
Phil Hughes committed
387
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
Robert Speicher committed
388
      page.should have_content "One comment to rule them all"
389
      wait_for_requests
Robert Speicher committed
390
    end
391
  end
392

393
  step 'merge request is mergeable' do
394
    expect(page).to have_button 'Merge'
395 396 397
  end

  step 'I modify merge commit message' do
398
    click_button "Modify commit message"
399
    fill_in 'Commit message', with: 'wow such merge'
400 401 402 403 404 405 406
  end

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

  step 'I accept this merge request' do
407
    page.within '.mr-state-widget' do
408
      click_button "Merge"
409
    end
410 411 412
  end

  step 'I should see merged request' do
413
    page.within '.status-box' do
414
      expect(page).to have_content "Merged"
415
      wait_for_requests
416 417 418
    end
  end

419
  step 'I click link "Reopen"' do
420
    first(:css, '.reopen-mr-link').trigger('click')
421 422 423
  end

  step 'I should see reopened merge request "Bug NS-04"' do
424
    page.within '.status-box' do
425
      expect(page).to have_content "Open"
426
    end
427
    wait_for_requests
428 429
  end

430
  step 'I click link "Hide inline discussion" of the third file' do
431
    page.within '.files>div:nth-child(3)' do
Dmitriy Zaporozhets committed
432
      find('.js-toggle-diff-comments').trigger('click')
433 434 435
    end
  end

436
  step 'I click link "Show inline discussion" of the third file' do
437
    page.within '.files>div:nth-child(3)' do
Dmitriy Zaporozhets committed
438
      find('.js-toggle-diff-comments').trigger('click')
439 440 441
    end
  end

442
  step 'I should not see a comment like "Line is wrong" in the third file' do
443
    page.within '.files>div:nth-child(3)' do
444
      expect(page).not_to have_visible_content "Line is wrong"
445 446 447
    end
  end

448
  step 'I should see a comment like "Line is wrong" in the third file' do
449
    page.within '.files>div:nth-child(3) .note-body > .note-text' do
450
      expect(page).to have_visible_content "Line is wrong"
451
      wait_for_requests
452 453 454
    end
  end

455
  step 'I should not see a comment like "Line is wrong here" in the third file' do
456
    page.within '.files>div:nth-child(3)' do
457
      expect(page).not_to have_visible_content "Line is wrong here"
458 459 460
    end
  end

461
  step 'I should see a comment like "Line is wrong here" in the third file' do
462
    page.within '.files>div:nth-child(3) .note-body > .note-text' do
463
      expect(page).to have_visible_content "Line is wrong here"
464 465 466
    end
  end

467
  step 'I leave a comment like "Line is correct" on line 12 of the second file' do
468 469
    init_diff_note_first_file

470
    page.within(".js-discussion-note-form") do
471
      fill_in "note_note", with: "Line is correct"
472
      click_button "Comment"
473 474
    end

475
    wait_for_requests
476

477
    page.within ".files>div:nth-child(2) .note-body > .note-text" do
478
      expect(page).to have_content "Line is correct"
479 480 481
    end
  end

482
  step 'I leave a comment like "Line is wrong" on line 39 of the third file' do
483 484
    init_diff_note_second_file

485
    page.within(".js-discussion-note-form") do
486
      fill_in "note_note", with: "Line is wrong on here"
Phil Hughes committed
487
      click_button "Comment"
488
    end
489

490
    wait_for_requests
491 492
  end

493
  step 'I should still see a comment like "Line is correct" in the second file' do
494
    page.within '.files>div:nth-child(2) .note-body > .note-text' do
495
      expect(page).to have_visible_content "Line is correct"
496 497 498
    end
  end

skv committed
499
  step 'I unfold diff' do
500 501
    expect(page).to have_css('.js-unfold')

skv committed
502 503 504 505 506 507 508
    first('.js-unfold').click
  end

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

Marin Jankovski committed
509
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets committed
510
    find('a', text: 'Side-by-side').trigger('click')
511 512 513

    # Waits for load
    expect(page).to have_css('.parallel')
Marin Jankovski committed
514 515 516
  end

  step 'I should see comments on the side-by-side diff page' do
517
    page.within '.files>div:nth-child(2) .parallel .note-body > .note-text' do
518
      expect(page).to have_visible_content "Line is correct"
519
      wait_for_requests
Marin Jankovski committed
520 521 522
    end
  end

523
  step 'I fill in merge request search with "Fe"' do
barthc committed
524
    fill_in 'issuable_search', with: "Fe"
525 526 527
    page.within '.merge-requests-holder' do
      find('.merge-request')
    end
528 529
  end

530
  step 'I click the "Target branch" dropdown' do
Phil Hughes committed
531
    expect(page).to have_content('Target branch')
532 533 534 535 536 537 538 539 540
    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 committed
541
    expect(page).to have_content 'Request to merge fix into feature'
542
    expect(page).to have_content 'changed target branch from merge-test to feature'
543
    wait_for_requests
544 545
  end

546 547 548 549 550 551 552 553 554 555 556 557
  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

558 559 560
  step '"Bug NS-05" has CI status' do
    project = merge_request.source_project
    project.enable_ci
561 562 563 564 565 566 567 568

    pipeline =
      create(:ci_pipeline,
             project: project,
             sha: merge_request.diff_head_sha,
             ref: merge_request.source_branch,
             head_pipeline_of: merge_request)

569
    create :ci_build, pipeline: pipeline
570 571
  end

572 573
  step 'I should see merge request "Bug NS-05" with CI status' do
    page.within ".mr-list" do
Kamil Trzcinski committed
574
      expect(page).to have_link "Pipeline: pending"
575 576
    end
  end
577

578 579 580 581
  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
582

583
    wait_for_requests
584 585 586 587 588 589
  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
590

591
    wait_for_requests
592 593
  end

594
  def merge_request
skv committed
595
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
596
  end
597 598

  def init_diff_note
599
    click_diff_line(sample_commit.line_code)
600 601 602
  end

  def leave_comment(message)
Robert Speicher committed
603
    page.within(".js-discussion-note-form", visible: true) do
604
      fill_in "note_note", with: message
Phil Hughes committed
605
      click_button "Comment"
606
    end
607

608
    wait_for_requests
609

Robert Speicher committed
610 611 612
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
613
  end
614 615

  def init_diff_note_first_file
Dmitriy Zaporozhets committed
616
    click_diff_line(sample_compare.changes[0][:line_code])
617 618 619
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets committed
620
    click_diff_line(sample_compare.changes[1][:line_code])
621 622
  end

623
  def have_visible_content(text)
624 625
    have_css("*", text: text, visible: true)
  end
626 627 628 629 630 631

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