BigW Consortium Gitlab

merge_requests.rb 15.8 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
  step 'I click link "All"' do
20
    click_link "All"
21 22
  end

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

27
  step 'I should see merge request "Wiki Feature"' do
28
    page.within '.merge-request' do
29
      expect(page).to have_content "Wiki Feature"
30
    end
31 32
  end

33
  step 'I should see closed merge request "Bug NS-04"' do
skv committed
34
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
Robert Speicher committed
35
    expect(merge_request).to be_closed
36
    expect(page).to have_content "Closed by"
37 38
  end

39
  step 'I should see merge request "Bug NS-04"' do
40
    expect(page).to have_content "Bug NS-04"
41 42
  end

43
  step 'I should not see "master" branch' do
44
    expect(find('.merge-request-info')).not_to have_content "master"
45 46 47 48 49 50
  end

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

51
  step 'I should see "Bug NS-04" in merge requests' do
52
    expect(page).to have_content "Bug NS-04"
53 54
  end

55
  step 'I should see "Feature NS-03" in merge requests' do
56
    expect(page).to have_content "Feature NS-03"
57 58
  end

59
  step 'I should not see "Feature NS-03" in merge requests' do
60
    expect(page).not_to have_content "Feature NS-03"
61 62
  end

63

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

Valery Sizov committed
68
  step 'I should see that I am subscribed' do
69
    expect(find('.subscribe-button span')).to have_content 'Unsubscribe'
Valery Sizov committed
70 71 72
  end

  step 'I should see that I am unsubscribed' do
73
    expect(find('.subscribe-button span')).to have_content 'Subscribe'
Valery Sizov committed
74 75 76 77 78 79
  end

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

80
  step 'I click link "Close"' do
81
    first(:css, '.close-mr-link').click
82 83
  end

84
  step 'I submit new merge request "Wiki Feature"' do
85 86
    select "fix", from: "merge_request_source_branch"
    select "feature", from: "merge_request_target_branch"
87 88
    click_button "Compare branches"
    fill_in "merge_request_title", with: "Wiki Feature"
89
    click_button "Submit merge request"
90 91
  end

92
  step 'project "Shop" have "Bug NS-04" open merge request' do
Andrew8xx8 committed
93
    create(:merge_request,
94
           title: "Bug NS-04",
95 96
           source_project: project,
           target_project: project,
97
           source_branch: 'fix',
98
           target_branch: 'master',
99 100 101
           author: project.users.first,
           description: "# Description header"
          )
102 103
  end

104 105 106 107 108 109 110 111 112 113 114 115
  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

116
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
117 118
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
119 120
           source_project: project,
           target_project: project,
121
           author: project.users.first)
122 123
  end

124
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8 committed
125
    create(:closed_merge_request,
126
           title: "Feature NS-03",
127 128
           source_project: project,
           target_project: project,
Andrew8xx8 committed
129
           author: project.users.first)
130 131
  end

132 133 134 135 136 137 138 139 140
  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

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
  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'
167
        expect(page).to_not have_content '0 0'
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
      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'
186
        expect(page).to_not have_content '0 0'
187 188 189 190
      end
    end
  end

191
  step 'I click on the Changes tab' do
192
    page.within '.merge-request-tabs' do
193 194 195
      click_link 'Changes'
    end

196 197
    # Waits for load
    expect(page).to have_css('.tab-content #diffs.active')
198 199 200
  end

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

205
  step 'I switch to the merge request\'s comments tab' do
Vinnie Okada committed
206
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
207 208
  end

Dmitriy Zaporozhets committed
209
  step 'I click on the commit in the merge request' do
210
    page.within '.merge-request-tabs' do
Dmitriy Zaporozhets committed
211 212 213
      click_link 'Commits'
    end

214
    page.within '.commits' do
Dmitriy Zaporozhets committed
215
      click_link Commit.truncate_sha(sample_commit.id)
216
    end
217 218
  end

219
  step 'I leave a comment on the diff page' do
220
    init_diff_note
221 222
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets committed
223

224
  step 'I leave a comment on the diff page in commit' do
225
    click_diff_line(sample_commit.line_code)
226
    leave_comment "One comment to rule them all"
227 228
  end

Dmitriy Zaporozhets committed
229
  step 'I leave a comment like "Line is wrong" on diff' do
230
    init_diff_note
231 232
    leave_comment "Line is wrong"
  end
233

234 235 236 237 238 239 240 241 242
  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
243
  step 'I leave a comment like "Line is wrong" on diff in commit' do
244
    click_diff_line(sample_commit.line_code)
245
    leave_comment "Line is wrong"
246 247
  end

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

273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
  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
292
  step 'I should see a discussion has started on diff' do
Robert Speicher committed
293 294 295 296 297
    page.within(".notes .discussion") do
      page.should have_content "#{current_user.name} started a discussion"
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
298 299
  end

300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
  step 'I should see a discussion by user "John Doe" has started on diff' do
    page.within(".notes .discussion") do
      page.should have_content "#{user_exists("John Doe").name} started a discussion"
      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
316
  step 'I should see a discussion has started on commit diff' do
Robert Speicher committed
317 318 319 320 321
    page.within(".notes .discussion") do
      page.should have_content "#{current_user.name} started a discussion on commit"
      page.should have_content sample_commit.line_code_path
      page.should have_content "Line is wrong"
    end
322 323
  end

Dmitriy Zaporozhets committed
324
  step 'I should see a discussion has started on commit' do
Robert Speicher committed
325 326 327 328
    page.within(".notes .discussion") do
      page.should have_content "#{current_user.name} started a discussion on commit"
      page.should have_content "One comment to rule them all"
    end
329
  end
330

331
  step 'merge request is mergeable' do
332
    expect(page).to have_button 'Accept Merge Request'
333 334 335 336
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
337
    fill_in 'commit_message', with: 'wow such merge'
338 339 340 341 342 343 344
  end

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

  step 'I accept this merge request' do
345
    page.within '.mr-state-widget' do
346 347
      click_button "Accept Merge Request"
    end
348 349 350
  end

  step 'I should see merged request' do
351
    page.within '.status-box' do
352
      expect(page).to have_content "Merged"
353 354 355
    end
  end

356
  step 'I click link "Reopen"' do
357
    first(:css, '.reopen-mr-link').click
358 359 360
  end

  step 'I should see reopened merge request "Bug NS-04"' do
361
    page.within '.status-box' do
362
      expect(page).to have_content "Open"
363 364 365
    end
  end

366 367
  step 'I click link "Hide inline discussion" of the third file' do
    page.within '.files [id^=diff]:nth-child(3)' do
Dmitriy Zaporozhets committed
368
      find('.js-toggle-diff-comments').trigger('click')
369 370 371
    end
  end

372 373
  step 'I click link "Show inline discussion" of the third file' do
    page.within '.files [id^=diff]:nth-child(3)' do
Dmitriy Zaporozhets committed
374
      find('.js-toggle-diff-comments').trigger('click')
375 376 377
    end
  end

378 379
  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
380
      expect(page).not_to have_visible_content "Line is wrong"
381 382 383
    end
  end

384 385
  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
386
      expect(page).to have_visible_content "Line is wrong"
387 388 389
    end
  end

390 391
  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
392
      expect(page).not_to have_visible_content "Line is wrong here"
393 394 395
    end
  end

396 397
  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
398
      expect(page).to have_visible_content "Line is wrong here"
399 400 401
    end
  end

402
  step 'I leave a comment like "Line is correct" on line 12 of the second file' do
403 404
    init_diff_note_first_file

405
    page.within(".js-discussion-note-form") do
406 407 408 409
      fill_in "note_note", with: "Line is correct"
      click_button "Add Comment"
    end

410
    page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do
411
      expect(page).to have_content "Line is correct"
412 413 414
    end
  end

415
  step 'I leave a comment like "Line is wrong" on line 39 of the third file' do
416 417
    init_diff_note_second_file

418
    page.within(".js-discussion-note-form") do
419
      fill_in "note_note", with: "Line is wrong on here"
420 421 422 423
      click_button "Add Comment"
    end
  end

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

skv committed
430
  step 'I unfold diff' do
431 432
    expect(page).to have_css('.js-unfold')

skv committed
433 434 435 436 437 438 439
    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
440
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets committed
441
    find('a', text: 'Side-by-side').trigger('click')
Marin Jankovski committed
442 443 444
  end

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

450 451 452 453
  step 'I fill in merge request search with "Fe"' do
    fill_in 'issue_search', with: "Fe"
  end

454 455 456 457 458 459 460 461 462 463
  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
464
    expect(page).to have_content 'Request to merge fix into feature'
465
    expect(page).to have_content 'Target branch changed from master to feature'
466 467
  end

468 469 470 471 472 473 474 475 476 477 478 479
  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

480 481 482
  step '"Bug NS-05" has CI status' do
    project = merge_request.source_project
    project.enable_ci
483
    ci_commit = create :ci_commit, project: project, sha: merge_request.last_commit.id
484 485 486
    create :ci_build, commit: ci_commit
  end

487 488
  step 'I should see merge request "Bug NS-05" with CI status' do
    page.within ".mr-list" do
489
      expect(page).to have_link "Build pending"
490 491
    end
  end
492

493 494 495 496 497 498 499 500
  step 'I should see "Bug NS-05" at the top' do
    expect(page.find('ul.content-list.mr-list li.merge-request:first-child')).to have_content("Bug NS-05")
  end

  step 'I should see "Bug NS-04" at the top' do
    expect(page.find('ul.content-list.mr-list li.merge-request:first-child')).to have_content("Bug NS-04")
  end

501
  def merge_request
skv committed
502
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
503
  end
504 505

  def init_diff_note
506
    click_diff_line(sample_commit.line_code)
507 508 509
  end

  def leave_comment(message)
Robert Speicher committed
510
    page.within(".js-discussion-note-form", visible: true) do
511 512 513
      fill_in "note_note", with: message
      click_button "Add Comment"
    end
Robert Speicher committed
514 515 516
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
517
  end
518 519

  def init_diff_note_first_file
Dmitriy Zaporozhets committed
520
    click_diff_line(sample_compare.changes[0][:line_code])
521 522 523
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets committed
524
    click_diff_line(sample_compare.changes[1][:line_code])
525 526 527 528 529
  end

  def have_visible_content (text)
    have_css("*", text: text, visible: true)
  end
530 531 532 533 534 535

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