merge_requests.rb 10.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
  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 click on the Changes tab' do
122
    page.within '.merge-request-tabs' do
123 124 125
      click_link 'Changes'
    end

126 127
    # Waits for load
    expect(page).to have_css('.tab-content #diffs.active')
128 129 130
  end

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

135
  step 'I switch to the merge request\'s comments tab' do
Vinnie Okada's avatar
Vinnie Okada committed
136
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
137 138
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
139
  step 'I click on the commit in the merge request' do
140
    page.within '.merge-request-tabs' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
141 142 143
      click_link 'Commits'
    end

144
    page.within '.commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
145
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
146
    end
147 148
  end

149
  step 'I leave a comment on the diff page' do
150
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
151 152
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
153

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
154
  step 'I leave a comment on the diff page in commit' do
155
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
156
    leave_comment "One comment to rule them all"
157 158
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
159
  step 'I leave a comment like "Line is wrong" on diff' do
160
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
161 162
    leave_comment "Line is wrong"
  end
163

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
164
  step 'I leave a comment like "Line is wrong" on diff in commit' do
165
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
166
    leave_comment "Line is wrong"
167 168
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
169
  step 'I should see a discussion has started on diff' do
Robert Speicher's avatar
Robert Speicher committed
170 171 172 173 174
    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
175 176
  end

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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
185
  step 'I should see a discussion has started on commit' do
Robert Speicher's avatar
Robert Speicher committed
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 "One comment to rule them all"
    end
190
  end
191

192
  step 'merge request is mergeable' do
193
    expect(page).to have_button 'Accept Merge Request'
194 195 196 197
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
198
    fill_in 'commit_message', with: 'wow such merge'
199 200 201 202 203 204 205
  end

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

  step 'I accept this merge request' do
206
    page.within '.mr-state-widget' do
207 208
      click_button "Accept Merge Request"
    end
209 210 211
  end

  step 'I should see merged request' do
212
    page.within '.issue-box' do
213
      expect(page).to have_content "Merged"
214 215 216
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
217
  step 'I click link "Reopen"' do
218
    first(:css, '.reopen-mr-link').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
219 220 221
  end

  step 'I should see reopened merge request "Bug NS-04"' do
222
    page.within '.issue-box' do
223
      expect(page).to have_content "Open"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
224 225 226
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
227 228
  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
229
      find('.js-toggle-diff-comments').trigger('click')
230 231 232
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
233 234
  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
235
      find('.js-toggle-diff-comments').trigger('click')
236 237 238
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
239 240
  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
241
      expect(page).not_to have_visible_content "Line is wrong"
242 243 244
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
245 246
  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
247
      expect(page).to have_visible_content "Line is wrong"
248 249 250
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
251 252
  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
253
      expect(page).not_to have_visible_content "Line is wrong here"
254 255 256
    end
  end

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

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

266
    page.within(".js-discussion-note-form") do
267 268 269 270
      fill_in "note_note", with: "Line is correct"
      click_button "Add Comment"
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
271
    page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do
272
      expect(page).to have_content "Line is correct"
273 274 275
    end
  end

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

279
    page.within(".js-discussion-note-form") do
280
      fill_in "note_note", with: "Line is wrong on here"
281 282 283 284
      click_button "Add Comment"
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
285 286
  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
287
      expect(page).to have_visible_content "Line is correct"
288 289 290
    end
  end

skv's avatar
skv committed
291
  step 'I unfold diff' do
292 293
    expect(page).to have_css('.js-unfold')

skv's avatar
skv committed
294 295 296 297 298 299 300
    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
301
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
302
    find('a', text: 'Side-by-side').trigger('click')
Marin Jankovski's avatar
Marin Jankovski committed
303 304 305
  end

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

311 312 313 314
  step 'I fill in merge request search with "Fe"' do
    fill_in 'issue_search', with: "Fe"
  end

315 316 317 318 319 320 321 322 323 324
  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
325
    expect(page).to have_content 'Request to merge fix into feature'
326
    expect(page).to have_content 'Target branch changed from master to feature'
327 328
  end

329 330 331 332 333 334 335 336 337 338 339 340
  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

341
  def merge_request
skv's avatar
skv committed
342
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
343
  end
344 345

  def init_diff_note
346
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
347 348 349
  end

  def leave_comment(message)
Robert Speicher's avatar
Robert Speicher committed
350
    page.within(".js-discussion-note-form", visible: true) do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
351 352 353
      fill_in "note_note", with: message
      click_button "Add Comment"
    end
Robert Speicher's avatar
Robert Speicher committed
354 355 356
    page.within(".notes_holder", visible: true) do
      expect(page).to have_content message
    end
357
  end
358 359

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
360
    click_diff_line(sample_compare.changes[0][:line_code])
361 362 363
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
364
    click_diff_line(sample_compare.changes[1][:line_code])
365 366 367 368 369
  end

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