merge_requests.rb 10.6 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
  step 'I should see "Bug NS-04" in merge requests' do
44
    expect(page).to have_content "Bug NS-04"
45 46
  end

47
  step 'I should see "Feature NS-03" in merge requests' do
48
    expect(page).to have_content "Feature NS-03"
49 50
  end

51
  step 'I should not see "Feature NS-03" in merge requests' do
52
    expect(page).not_to have_content "Feature NS-03"
53 54
  end

55

56
  step 'I should not see "Bug NS-04" in merge requests' do
57
    expect(page).not_to have_content "Bug NS-04"
58 59
  end

Valery Sizov's avatar
tests  
Valery Sizov committed
60
  step 'I should see that I am subscribed' do
61
    expect(find('.subscribe-button span')).to have_content 'Unsubscribe'
Valery Sizov's avatar
tests  
Valery Sizov committed
62 63 64
  end

  step 'I should see that I am unsubscribed' do
65
    expect(find('.subscribe-button span')).to have_content 'Subscribe'
Valery Sizov's avatar
tests  
Valery Sizov committed
66 67 68 69 70 71
  end

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

72
  step 'I click link "Close"' do
73
    first(:css, '.close-mr-link').click
74 75
  end

76
  step 'I submit new merge request "Wiki Feature"' do
77 78
    select "fix", from: "merge_request_source_branch"
    select "feature", from: "merge_request_target_branch"
79 80
    click_button "Compare branches"
    fill_in "merge_request_title", with: "Wiki Feature"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
81
    click_button "Submit new merge request"
82 83
  end

84
  step 'project "Shop" have "Bug NS-04" open merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
85
    create(:merge_request,
86
           title: "Bug NS-04",
87 88
           source_project: project,
           target_project: project,
89
           source_branch: 'fix',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
90
           target_branch: 'master',
91 92 93
           author: project.users.first,
           description: "# Description header"
          )
94 95
  end

96
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
97 98
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
99 100
           source_project: project,
           target_project: project,
101
           author: project.users.first)
102 103
  end

104
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
105
    create(:closed_merge_request,
106
           title: "Feature NS-03",
107 108
           source_project: project,
           target_project: project,
Andrew8xx8's avatar
Andrew8xx8 committed
109
           author: project.users.first)
110 111
  end

112 113 114 115 116 117 118 119 120
  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

121
  step 'I switch to the diff tab' do
Vinnie Okada's avatar
Vinnie Okada committed
122
    visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)
123 124
  end

125
  step 'I click on the Changes tab via Javascript' do
126
    page.within '.merge-request-tabs' do
127 128 129
      click_link 'Changes'
    end

130 131 132 133
    sleep 2
  end

  step 'I should see the proper Inline and Side-by-side links' do
134
    buttons = page.all('#commit-diff-viewtype')
135 136 137
    expect(buttons.count).to eq(2)

    buttons.each do |b|
Robert Speicher's avatar
Robert Speicher committed
138
      expect(b['href']).not_to have_content('json')
139 140 141
    end
  end

142
  step 'I switch to the merge request\'s comments tab' do
Vinnie Okada's avatar
Vinnie Okada committed
143
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
144 145
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
146
  step 'I click on the commit in the merge request' do
147
    page.within '.merge-request-tabs' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
148 149 150
      click_link 'Commits'
    end

151
    page.within '.commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
152
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
153
    end
154 155
  end

156
  step 'I leave a comment on the diff page' do
157
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
158 159
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
160

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
161
  step 'I leave a comment on the diff page in commit' do
162
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
163
    leave_comment "One comment to rule them all"
164 165
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
166
  step 'I leave a comment like "Line is wrong" on diff' do
167
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
168 169
    leave_comment "Line is wrong"
  end
170

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
171
  step 'I leave a comment like "Line is wrong" on diff in commit' do
172
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
173
    leave_comment "Line is wrong"
174 175
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
176
  step 'I should see a discussion has started on diff' do
Robert Speicher's avatar
Robert Speicher committed
177 178 179 180 181
    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
182 183
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
184
  step 'I should see a discussion has started on commit diff' do
Robert Speicher's avatar
Robert Speicher committed
185 186 187 188 189
    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
190 191
  end

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

199
  step 'merge request is mergeable' do
200
    expect(page).to have_button 'Accept Merge Request'
201 202 203 204
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
205
    fill_in 'commit_message', with: 'wow such merge'
206 207 208
  end

  step 'merge request "Bug NS-05" is mergeable' do
209
    merge_request.project.satellite.create
210 211 212 213
    merge_request.mark_as_mergeable
  end

  step 'I accept this merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
214 215 216 217
    Gitlab::Satellite::MergeAction.any_instance.stub(
      merge!: true,
    )

218
    page.within '.mr-state-widget' do
219 220
      click_button "Accept Merge Request"
    end
221 222 223
  end

  step 'I should see merged request' do
224
    page.within '.issue-box' do
225
      expect(page).to have_content "Merged"
226 227 228
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
229
  step 'I click link "Reopen"' do
230
    first(:css, '.reopen-mr-link').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
231 232 233
  end

  step 'I should see reopened merge request "Bug NS-04"' do
234
    page.within '.issue-box' do
235
      expect(page).to have_content "Open"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
236 237 238
    end
  end

239
  step 'I click link "Hide inline discussion" of the second file' do
240
    page.within '.files [id^=diff]:nth-child(2)' do
241
      find('.js-toggle-diff-comments').click
242 243 244 245
    end
  end

  step 'I click link "Show inline discussion" of the second file' do
246
    page.within '.files [id^=diff]:nth-child(2)' do
247
      find('.js-toggle-diff-comments').click
248 249 250 251
    end
  end

  step 'I should not see a comment like "Line is wrong" in the second file' do
252
    page.within '.files [id^=diff]:nth-child(2)' do
253
      expect(page).not_to have_visible_content "Line is wrong"
254 255 256 257
    end
  end

  step 'I should see a comment like "Line is wrong" in the second file' do
258
    page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do
259
      expect(page).to have_visible_content "Line is wrong"
260 261 262
    end
  end

263
  step 'I should not see a comment like "Line is wrong here" in the second file' do
264
    page.within '.files [id^=diff]:nth-child(2)' do
265
      expect(page).not_to have_visible_content "Line is wrong here"
266 267 268 269
    end
  end

  step 'I should see a comment like "Line is wrong here" in the second file' do
270
    page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do
271
      expect(page).to have_visible_content "Line is wrong here"
272 273 274
    end
  end

275 276 277
  step 'I leave a comment like "Line is correct" on line 12 of the first file' do
    init_diff_note_first_file

278
    page.within(".js-discussion-note-form") do
279 280 281 282
      fill_in "note_note", with: "Line is correct"
      click_button "Add Comment"
    end

283
    page.within ".files [id^=diff]:nth-child(1) .note-body > .note-text" do
284
      expect(page).to have_content "Line is correct"
285 286 287 288 289 290
    end
  end

  step 'I leave a comment like "Line is wrong" on line 39 of the second file' do
    init_diff_note_second_file

291
    page.within(".js-discussion-note-form") do
292
      fill_in "note_note", with: "Line is wrong on here"
293 294 295 296 297
      click_button "Add Comment"
    end
  end

  step 'I should still see a comment like "Line is correct" in the first file' do
298
    page.within '.files [id^=diff]:nth-child(1) .note-body > .note-text' do
299
      expect(page).to have_visible_content "Line is correct"
300 301 302
    end
  end

skv's avatar
skv committed
303 304 305 306 307 308 309 310
  step 'I unfold diff' do
    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
311
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
312
    find('a', text: 'Side-by-side').trigger('click')
Marin Jankovski's avatar
Marin Jankovski committed
313 314 315
  end

  step 'I should see comments on the side-by-side diff page' do
316
    page.within '.files [id^=diff]:nth-child(1) .parallel .note-body > .note-text' do
317
      expect(page).to have_visible_content "Line is correct"
Marin Jankovski's avatar
Marin Jankovski committed
318 319 320
    end
  end

321 322 323 324
  step 'I fill in merge request search with "Fe"' do
    fill_in 'issue_search', with: "Fe"
  end

325 326 327 328 329 330 331 332 333 334
  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
335 336
    expect(page).to have_content 'From fix into feature'
    expect(page).to have_content 'Target branch changed from master to feature'
337 338
  end

339 340 341 342 343 344 345 346 347 348 349 350
  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

351
  def merge_request
skv's avatar
skv committed
352
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
353
  end
354 355

  def init_diff_note
356
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
357 358 359
  end

  def leave_comment(message)
Robert Speicher's avatar
Robert Speicher committed
360
    page.within(".js-discussion-note-form", visible: true) do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
361 362 363
      fill_in "note_note", with: message
      click_button "Add Comment"
    end
Robert Speicher's avatar
Robert Speicher committed
364 365 366
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
367
  end
368 369

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
370
    click_diff_line(sample_compare.changes[0][:line_code])
371 372 373
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
374
    click_diff_line(sample_compare.changes[1][:line_code])
375 376 377 378 379
  end

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