merge_requests.rb 8.33 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

59
  step 'I click link "Close"' do
60
    first(:css, '.close-mr-link').click
61 62
  end

63
  step 'I submit new merge request "Wiki Feature"' do
64 65
    select "fix", from: "merge_request_source_branch"
    select "feature", from: "merge_request_target_branch"
66 67
    click_button "Compare branches"
    fill_in "merge_request_title", with: "Wiki Feature"
68
    click_button "Submit merge request"
69 70
  end

71
  step 'project "Shop" have "Bug NS-04" open merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
72
    create(:merge_request,
73
           title: "Bug NS-04",
74 75
           source_project: project,
           target_project: project,
76
           source_branch: 'fix',
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
77
           target_branch: 'master',
78 79 80
           author: project.users.first,
           description: "# Description header"
          )
81 82
  end

83
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
84 85
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
86 87
           source_project: project,
           target_project: project,
88
           author: project.users.first)
89 90
  end

91
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
92
    create(:closed_merge_request,
93
           title: "Feature NS-03",
94 95
           source_project: project,
           target_project: project,
Andrew8xx8's avatar
Andrew8xx8 committed
96
           author: project.users.first)
97 98
  end

99
  step 'project "Shop" has "MR-task-open" open MR with task markdown' do
100
    create_taskable(:merge_request, 'MR-task-open')
101 102
  end

103
  step 'I switch to the diff tab' do
104
    visit diffs_project_merge_request_path(project, merge_request)
105 106
  end

107
  step 'I switch to the merge request\'s comments tab' do
108
    visit project_merge_request_path(project, merge_request)
109 110
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
111
  step 'I click on the commit in the merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
112 113 114 115
    within '.merge-request-tabs' do
      click_link 'Commits'
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
116
    within '.mr-commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
117
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
118
    end
119 120
  end

121
  step 'I leave a comment on the diff page' do
122
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
123 124
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
125

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
126
  step 'I leave a comment on the diff page in commit' do
127
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
128
    leave_comment "One comment to rule them all"
129 130
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
131
  step 'I leave a comment like "Line is wrong" on diff' do
132
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
133 134
    leave_comment "Line is wrong"
  end
135

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
136
  step 'I leave a comment like "Line is wrong" on diff in commit' do
137
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
138
    leave_comment "Line is wrong"
139 140
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
141
  step 'I should see a discussion has started on diff' do
142
    page.should have_content "#{current_user.name} started a discussion"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
143
    page.should have_content sample_commit.line_code_path
144 145 146
    page.should have_content "Line is wrong"
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
147
  step 'I should see a discussion has started on commit diff' do
148
    page.should have_content "#{current_user.name} started a discussion on commit"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
149
    page.should have_content sample_commit.line_code_path
150 151 152
    page.should have_content "Line is wrong"
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
153
  step 'I should see a discussion has started on commit' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
154
    page.should have_content "#{current_user.name} started a discussion on commit"
155
    page.should have_content "One comment to rule them all"
156
  end
157

158 159 160 161 162 163
  step 'merge request is mergeable' do
    page.should have_content 'You can accept this request automatically'
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
164
    fill_in 'commit_message', with: 'wow such merge'
165 166 167 168 169 170 171
  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
172 173 174 175
    Gitlab::Satellite::MergeAction.any_instance.stub(
      merge!: true,
    )

176 177 178 179
    click_button "Accept Merge Request"
  end

  step 'I should see merged request' do
180
    within '.issue-box' do
181 182 183 184
      page.should have_content "Merged"
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
185
  step 'I click link "Reopen"' do
186
    first(:css, '.reopen-mr-link').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
187 188 189
  end

  step 'I should see reopened merge request "Bug NS-04"' do
190
    within '.issue-box' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
191 192 193 194
      page.should have_content "Open"
    end
  end

195 196
  step 'I click link "Hide inline discussion" of the second file' do
    within '.files [id^=diff]:nth-child(2)' do
197
      click_link "Diff comments"
198 199 200 201 202
    end
  end

  step 'I click link "Show inline discussion" of the second file' do
    within '.files [id^=diff]:nth-child(2)' do
203
      click_link "Diff comments"
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
    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
    within '.files [id^=diff]:nth-child(2) .note-text' do
      page.should have_visible_content "Line is wrong"
    end
  end

219 220 221 222 223 224 225 226 227 228 229 230
  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
    within '.files [id^=diff]:nth-child(2) .note-text' do
      page.should have_visible_content "Line is wrong here"
    end
  end

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  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

    within ".files [id^=diff]:nth-child(1) .note-text" do
      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
248
      fill_in "note_note", with: "Line is wrong on here"
249 250 251 252 253 254 255 256 257 258
      click_button "Add Comment"
    end
  end

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

skv's avatar
skv committed
259 260 261 262 263 264 265 266
  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
267
  step 'I click Side-by-side Diff tab' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
268
    click_link 'Side-by-side'
Marin Jankovski's avatar
Marin Jankovski committed
269 270 271 272 273 274 275 276
  end

  step 'I should see comments on the side-by-side diff page' do
    within '.files [id^=diff]:nth-child(1) .note-text' do
      page.should have_visible_content "Line is correct"
    end
  end

277
  def merge_request
skv's avatar
skv committed
278
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
279
  end
280 281

  def init_diff_note
282
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
283 284 285 286 287 288 289 290
  end

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

291
    page.should have_content message
292
  end
293 294

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
295
    click_diff_line(sample_compare.changes[0][:line_code])
296 297 298
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
299
    click_diff_line(sample_compare.changes[1][:line_code])
300 301 302 303 304
  end

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