BigW Consortium Gitlab

merge_requests.rb 17.1 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
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 committed
42
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
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 committed
79
  step 'I should see that I am subscribed' do
80
    expect(find('.issuable-subscribe-button span')).to have_content 'Unsubscribe'
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 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 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 committed
108
    create(:merge_request,
109
           title: "Bug NS-04",
110 111
           source_project: project,
           target_project: project,
112
           source_branch: 'fix',
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 committed
164
    create(:closed_merge_request,
165
           title: "Feature NS-03",
166 167
           source_project: project,
           target_project: project,
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
  step 'merge request "Bug NS-04" have 2 upvotes and 1 downvote' do
    merge_request = MergeRequest.find_by(title: 'Bug NS-04')
    create_list(:upvote_note, 2, project: project, noteable: merge_request)
    create(:downvote_note, project: project, noteable: merge_request)
  end

  step 'merge request "Bug NS-06" have 1 upvote and 2 downvotes' do
    merge_request = MergeRequest.find_by(title: 'Bug NS-06')
    create(:upvote_note, project: project, noteable: merge_request)
    create_list(:downvote_note, 2, project: project, noteable: merge_request)
  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).to_not 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).to_not 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 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 committed
245
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
246 247
  end

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

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

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

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

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

273 274 275 276 277 278 279 280 281
  step 'user "John Doe" leaves a comment like "Line is wrong" on diff' do
    mr = MergeRequest.find_by(title: "Bug NS-05")
    create(:note_on_merge_request_diff, project: project,
                                        noteable_id: mr.id,
                                        author: user_exists("John Doe"),
                                        line_code: sample_commit.line_code,
                                        note: 'Line is wrong')
  end

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

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
  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

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
  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 committed
331
  step 'I should see a discussion has started on diff' do
Robert Speicher committed
332
    page.within(".notes .discussion") do
Phil Hughes committed
333
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion"
Robert Speicher committed
334 335 336
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
337 338
  end

339 340
  step 'I should see a discussion by user "John Doe" has started on diff' do
    page.within(".notes .discussion") do
Phil Hughes committed
341
      page.should have_content "#{user_exists("John Doe").name} #{user_exists("John Doe").to_reference} started a discussion"
342 343 344 345 346 347 348 349 350 351 352 353 354
      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 committed
355
  step 'I should see a discussion has started on commit diff' do
Robert Speicher committed
356
    page.within(".notes .discussion") do
Phil Hughes committed
357
      page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
Robert Speicher committed
358 359 360
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
361 362
  end

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

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

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

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

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

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

395
  step 'I click link "Reopen"' do
396
    first(:css, '.reopen-mr-link').click
397 398 399
  end

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

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

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

417 418
  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
419
      expect(page).not_to have_visible_content "Line is wrong"
420 421 422
    end
  end

423 424
  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
425
      expect(page).to have_visible_content "Line is wrong"
426 427 428
    end
  end

429 430
  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
431
      expect(page).not_to have_visible_content "Line is wrong here"
432 433 434
    end
  end

435 436
  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
437
      expect(page).to have_visible_content "Line is wrong here"
438 439 440
    end
  end

441
  step 'I leave a comment like "Line is correct" on line 12 of the second file' do
442 443
    init_diff_note_first_file

444
    page.within(".js-discussion-note-form") do
445
      fill_in "note_note", with: "Line is correct"
446
      click_button "Comment"
447 448
    end

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

454
  step 'I leave a comment like "Line is wrong" on line 39 of the third file' do
455 456
    init_diff_note_second_file

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

463 464
  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
465
      expect(page).to have_visible_content "Line is correct"
466 467 468
    end
  end

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

skv committed
472 473 474 475 476 477 478
    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
479
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets committed
480
    find('a', text: 'Side-by-side').trigger('click')
Marin Jankovski committed
481 482 483
  end

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

489 490 491 492
  step 'I fill in merge request search with "Fe"' do
    fill_in 'issue_search', with: "Fe"
  end

493 494 495 496 497 498 499 500 501 502
  step 'I click the "Target branch" dropdown' do
    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
503
    expect(page).to have_content 'Request to merge fix into feature'
504
    expect(page).to have_content 'Target branch changed from master to feature'
505 506
  end

507 508 509 510 511 512 513 514 515 516 517 518
  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

519 520 521
  step '"Bug NS-05" has CI status' do
    project = merge_request.source_project
    project.enable_ci
Kamil Trzcinski committed
522
    ci_commit = create :ci_commit, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch
523 524 525
    create :ci_build, commit: ci_commit
  end

526 527
  step 'I should see merge request "Bug NS-05" with CI status' do
    page.within ".mr-list" do
528
      expect(page).to have_link "Build pending"
529 530
    end
  end
531

532 533 534 535 536 537 538 539 540 541 542 543
  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

544
  def merge_request
skv committed
545
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
546
  end
547 548

  def init_diff_note
549
    click_diff_line(sample_commit.line_code)
550 551 552
  end

  def leave_comment(message)
Robert Speicher committed
553
    page.within(".js-discussion-note-form", visible: true) do
554
      fill_in "note_note", with: message
Phil Hughes committed
555
      click_button "Comment"
556
    end
Robert Speicher committed
557 558 559
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
560
  end
561 562

  def init_diff_note_first_file
Dmitriy Zaporozhets committed
563
    click_diff_line(sample_compare.changes[0][:line_code])
564 565 566
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets committed
567
    click_diff_line(sample_compare.changes[1][:line_code])
568 569 570 571 572
  end

  def have_visible_content (text)
    have_css("*", text: text, visible: true)
  end
573 574 575 576 577 578

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