merge_requests.rb 11.4 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
  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's avatar
skv committed
34
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
Robert Speicher's avatar
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 44 45 46 47 48 49 50
  step 'I should not see "master" branch' do
    expect(page).not_to have_content "master"
  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's avatar
tests  
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's avatar
tests  
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's avatar
tests  
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's avatar
Andrew8xx8 committed
93
    create(:merge_request,
94
           title: "Bug NS-04",
95 96
           source_project: project,
           target_project: project,
97
           source_branch: 'fix',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
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's avatar
Andrew8xx8 committed
125
    create(:closed_merge_request,
126
           title: "Feature NS-03",
127 128
           source_project: project,
           target_project: project,
Andrew8xx8's avatar
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
  step 'I click on the Changes tab' do
142
    page.within '.merge-request-tabs' do
143 144 145
      click_link 'Changes'
    end

146 147
    # Waits for load
    expect(page).to have_css('.tab-content #diffs.active')
148 149 150
  end

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

155
  step 'I switch to the merge request\'s comments tab' do
Vinnie Okada's avatar
Vinnie Okada committed
156
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
157 158
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
159
  step 'I click on the commit in the merge request' do
160
    page.within '.merge-request-tabs' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
161 162 163
      click_link 'Commits'
    end

164
    page.within '.commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
165
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
166
    end
167 168
  end

169
  step 'I leave a comment on the diff page' do
170
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
171 172
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
173

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
174
  step 'I leave a comment on the diff page in commit' do
175
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
176
    leave_comment "One comment to rule them all"
177 178
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
179
  step 'I leave a comment like "Line is wrong" on diff' do
180
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
181 182
    leave_comment "Line is wrong"
  end
183

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
184
  step 'I leave a comment like "Line is wrong" on diff in commit' do
185
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
186
    leave_comment "Line is wrong"
187 188
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
189
  step 'I should see a discussion has started on diff' do
Robert Speicher's avatar
Robert Speicher committed
190 191 192 193 194
    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
195 196
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
197
  step 'I should see a discussion has started on commit diff' do
Robert Speicher's avatar
Robert Speicher committed
198 199 200 201 202
    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
203 204
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
205
  step 'I should see a discussion has started on commit' do
Robert Speicher's avatar
Robert Speicher committed
206 207 208 209
    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
210
  end
211

212
  step 'merge request is mergeable' do
213
    expect(page).to have_button 'Accept Merge Request'
214 215 216 217
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
218
    fill_in 'commit_message', with: 'wow such merge'
219 220 221 222 223 224 225
  end

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

  step 'I accept this merge request' do
226
    page.within '.mr-state-widget' do
227 228
      click_button "Accept Merge Request"
    end
229 230 231
  end

  step 'I should see merged request' do
232
    page.within '.issue-box' do
233
      expect(page).to have_content "Merged"
234 235 236
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
237
  step 'I click link "Reopen"' do
238
    first(:css, '.reopen-mr-link').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
239 240 241
  end

  step 'I should see reopened merge request "Bug NS-04"' do
242
    page.within '.issue-box' do
243
      expect(page).to have_content "Open"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
244 245 246
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
247 248
  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
249
      find('.js-toggle-diff-comments').trigger('click')
250 251 252
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
253 254
  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
255
      find('.js-toggle-diff-comments').trigger('click')
256 257 258
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
259 260
  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
261
      expect(page).not_to have_visible_content "Line is wrong"
262 263 264
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
265 266
  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
267
      expect(page).to have_visible_content "Line is wrong"
268 269 270
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
271 272
  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
273
      expect(page).not_to have_visible_content "Line is wrong here"
274 275 276
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
277 278
  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
279
      expect(page).to have_visible_content "Line is wrong here"
280 281 282
    end
  end

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

286
    page.within(".js-discussion-note-form") do
287 288 289 290
      fill_in "note_note", with: "Line is correct"
      click_button "Add Comment"
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
291
    page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do
292
      expect(page).to have_content "Line is correct"
293 294 295
    end
  end

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

299
    page.within(".js-discussion-note-form") do
300
      fill_in "note_note", with: "Line is wrong on here"
301 302 303 304
      click_button "Add Comment"
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
305 306
  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
307
      expect(page).to have_visible_content "Line is correct"
308 309 310
    end
  end

skv's avatar
skv committed
311
  step 'I unfold diff' do
312 313
    expect(page).to have_css('.js-unfold')

skv's avatar
skv committed
314 315 316 317 318 319 320
    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
321
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
322
    find('a', text: 'Side-by-side').trigger('click')
Marin Jankovski's avatar
Marin Jankovski committed
323 324 325
  end

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

331 332 333 334
  step 'I fill in merge request search with "Fe"' do
    fill_in 'issue_search', with: "Fe"
  end

335 336 337 338 339 340 341 342 343 344
  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's avatar
Douwe Maan committed
345
    expect(page).to have_content 'Request to merge fix into feature'
346
    expect(page).to have_content 'Target branch changed from master to feature'
347 348
  end

349 350 351 352 353 354 355 356 357 358 359 360
  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

361 362 363 364 365 366 367
  step '"Bug NS-05" has CI status' do
    project = merge_request.source_project
    project.enable_ci
    ci_commit = create :ci_commit, gl_project: project, sha: merge_request.last_commit.id
    create :ci_build, commit: ci_commit
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
368 369
  step 'I should see merge request "Bug NS-05" with CI status' do
    page.within ".mr-list" do
370
      expect(page).to have_link "Build pending"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
371 372
    end
  end
373

374
  def merge_request
skv's avatar
skv committed
375
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
376
  end
377 378

  def init_diff_note
379
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
380 381 382
  end

  def leave_comment(message)
Robert Speicher's avatar
Robert Speicher committed
383
    page.within(".js-discussion-note-form", visible: true) do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
384 385 386
      fill_in "note_note", with: message
      click_button "Add Comment"
    end
Robert Speicher's avatar
Robert Speicher committed
387 388 389
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
390
  end
391 392

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
393
    click_diff_line(sample_compare.changes[0][:line_code])
394 395 396
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
397
    click_diff_line(sample_compare.changes[1][:line_code])
398 399 400 401 402
  end

  def have_visible_content (text)
    have_css("*", text: text, visible: true)
  end
403
end