merge_requests.rb 8.93 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
Nihad Abbasov's avatar
Nihad Abbasov committed
9

10
  step 'I click link "New Merge Request"' do
11
    click_link "New Merge Request"
12 13
  end

14
  step 'I click link "Bug NS-04"' do
15 16 17
    click_link "Bug NS-04"
  end

18
  step 'I click link "All"' do
19
    click_link "All"
20 21
  end

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

26
  step 'I should see merge request "Wiki Feature"' do
27 28 29
    within '.merge-request' do
      page.should have_content "Wiki Feature"
    end
30 31
  end

32
  step 'I should see closed merge request "Bug NS-04"' do
skv's avatar
skv committed
33
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
34
    merge_request.closed?.should be_true
35
    page.should have_content "Closed by"
36 37
  end

38
  step 'I should see merge request "Bug NS-04"' do
39
    page.should have_content "Bug NS-04"
40 41
  end

42
  step 'I should see "Bug NS-04" in merge requests' do
43
    page.should have_content "Bug NS-04"
44 45
  end

46
  step 'I should see "Feature NS-03" in merge requests' do
47
    page.should have_content "Feature NS-03"
48 49
  end

50
  step 'I should not see "Feature NS-03" in merge requests' do
51
    page.should_not have_content "Feature NS-03"
52 53
  end

54

55
  step 'I should not see "Bug NS-04" in merge requests' do
56
    page.should_not have_content "Bug NS-04"
57 58
  end

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

  step 'I should see that I am unsubscribed' do
    sleep 0.2
Valery Sizov's avatar
Valery Sizov committed
65
    find(".subscribe-button span").text.should == "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"
81
    click_button "Submit 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
  step 'project "Shop" has "MR-task-open" open MR with task markdown' do
113
    create_taskable(:merge_request, 'MR-task-open')
114 115
  end

116
  step 'I switch to the diff tab' do
Vinnie Okada's avatar
Vinnie Okada committed
117
    visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)
118 119
  end

120
  step 'I switch to the merge request\'s comments tab' do
Vinnie Okada's avatar
Vinnie Okada committed
121
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
122 123
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
124
  step 'I click on the commit in the merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
125 126 127 128
    within '.merge-request-tabs' do
      click_link 'Commits'
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
129
    within '.commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
130
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
131
    end
132 133
  end

134
  step 'I leave a comment on the diff page' do
135
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
136 137
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
138

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
139
  step 'I leave a comment on the diff page in commit' do
140
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
141
    leave_comment "One comment to rule them all"
142 143
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
144
  step 'I leave a comment like "Line is wrong" on diff' do
145
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
146 147
    leave_comment "Line is wrong"
  end
148

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
149
  step 'I leave a comment like "Line is wrong" on diff in commit' do
150
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
151
    leave_comment "Line is wrong"
152 153
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
154
  step 'I should see a discussion has started on diff' do
155
    page.should have_content "#{current_user.name} started a discussion"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
156
    page.should have_content sample_commit.line_code_path
157 158 159
    page.should have_content "Line is wrong"
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
160
  step 'I should see a discussion has started on commit diff' do
161
    page.should have_content "#{current_user.name} started a discussion on commit"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
162
    page.should have_content sample_commit.line_code_path
163 164 165
    page.should have_content "Line is wrong"
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
166
  step 'I should see a discussion has started on commit' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
167
    page.should have_content "#{current_user.name} started a discussion on commit"
168
    page.should have_content "One comment to rule them all"
169
  end
170

171
  step 'merge request is mergeable' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
172
    page.should have_button 'Accept Merge Request'
173 174 175 176
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
177
    fill_in 'commit_message', with: 'wow such merge'
178 179 180 181 182 183 184
  end

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

  step 'I accept this merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
185 186 187 188
    Gitlab::Satellite::MergeAction.any_instance.stub(
      merge!: true,
    )

189 190 191
    within '.can_be_merged' do
      click_button "Accept Merge Request"
    end
192 193 194
  end

  step 'I should see merged request' do
195
    within '.issue-box' do
196 197 198 199
      page.should have_content "Merged"
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
200
  step 'I click link "Reopen"' do
201
    first(:css, '.reopen-mr-link').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
202 203 204
  end

  step 'I should see reopened merge request "Bug NS-04"' do
205
    within '.issue-box' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
206 207 208 209
      page.should have_content "Open"
    end
  end

210 211
  step 'I click link "Hide inline discussion" of the second file' do
    within '.files [id^=diff]:nth-child(2)' do
212
      find('.js-toggle-diff-comments').click
213 214 215 216 217
    end
  end

  step 'I click link "Show inline discussion" of the second file' do
    within '.files [id^=diff]:nth-child(2)' do
218
      find('.js-toggle-diff-comments').click
219 220 221 222 223 224 225 226 227 228
    end
  end

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

  step 'I should see a comment like "Line is wrong" in the second file' do
229
    within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do
230 231 232 233
      page.should have_visible_content "Line is wrong"
    end
  end

234 235 236 237 238 239 240
  step 'I should not see a comment like "Line is wrong here" in the second file' do
    within '.files [id^=diff]:nth-child(2)' do
      page.should_not have_visible_content "Line is wrong here"
    end
  end

  step 'I should see a comment like "Line is wrong here" in the second file' do
241
    within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do
242 243 244 245
      page.should have_visible_content "Line is wrong here"
    end
  end

246 247 248 249 250 251 252 253
  step 'I leave a comment like "Line is correct" on line 12 of the first file' do
    init_diff_note_first_file

    within(".js-discussion-note-form") do
      fill_in "note_note", with: "Line is correct"
      click_button "Add Comment"
    end

254
    within ".files [id^=diff]:nth-child(1) .note-body > .note-text" do
255 256 257 258 259 260 261 262
      page.should have_content "Line is correct"
    end
  end

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

    within(".js-discussion-note-form") do
263
      fill_in "note_note", with: "Line is wrong on here"
264 265 266 267 268
      click_button "Add Comment"
    end
  end

  step 'I should still see a comment like "Line is correct" in the first file' do
269
    within '.files [id^=diff]:nth-child(1) .note-body > .note-text' do
270 271 272 273
      page.should have_visible_content "Line is correct"
    end
  end

skv's avatar
skv committed
274 275 276 277 278 279 280 281
  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
282
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
283
    find('a', text: 'Side-by-side').trigger('click')
Marin Jankovski's avatar
Marin Jankovski committed
284 285 286
  end

  step 'I should see comments on the side-by-side diff page' do
287
    within '.files [id^=diff]:nth-child(1) .parallel .note-body > .note-text' do
Marin Jankovski's avatar
Marin Jankovski committed
288 289 290 291
      page.should have_visible_content "Line is correct"
    end
  end

292 293 294 295
  step 'I fill in merge request search with "Fe"' do
    fill_in 'issue_search', with: "Fe"
  end

296
  def merge_request
skv's avatar
skv committed
297
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
298
  end
299 300

  def init_diff_note
301
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
302 303 304 305 306 307 308 309
  end

  def leave_comment(message)
    within(".js-discussion-note-form") do
      fill_in "note_note", with: message
      click_button "Add Comment"
    end

310
    page.should have_content message
311
  end
312 313

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
314
    click_diff_line(sample_compare.changes[0][:line_code])
315 316 317
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
318
    click_diff_line(sample_compare.changes[1][:line_code])
319 320 321 322 323
  end

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