merge_requests.rb 8.34 KB
Newer Older
1
class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
Nihad Abbasov's avatar
Nihad Abbasov committed
2 3 4 5
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths
6
  include SharedMarkdown
7
  include SharedDiffNote
Nihad Abbasov's avatar
Nihad Abbasov committed
8

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

13 14 15 16
  step 'I click link "Edit"' do
    click_link 'Edit'
  end

17
  step 'I click link "Bug NS-04"' do
18 19 20
    click_link "Bug NS-04"
  end

21
  step 'I click link "All"' do
22
    click_link "All"
23 24
  end

25
  step 'I click link "Closed"' do
26 27 28
    click_link "Closed"
  end

29
  step 'I should see merge request "Wiki Feature"' do
30 31 32
    within '.merge-request' do
      page.should have_content "Wiki Feature"
    end
33 34
  end

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

41
  step 'I should see merge request "Bug NS-04"' do
42
    page.should have_content "Bug NS-04"
43 44
  end

45
  step 'I should see "Bug NS-04" in merge requests' do
46
    page.should have_content "Bug NS-04"
47 48
  end

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

53
  step 'I should not see "Feature NS-03" in merge requests' do
54
    page.should_not have_content "Feature NS-03"
55 56
  end

57

58
  step 'I should not see "Bug NS-04" in merge requests' do
59
    page.should_not have_content "Bug NS-04"
60 61
  end

62
  step 'I click link "Close"' do
63 64 65
    within '.page-title' do
      click_link "Close"
    end
66 67
  end

68
  step 'I submit new merge request "Wiki Feature"' do
69 70
    select "fix", from: "merge_request_source_branch"
    select "feature", from: "merge_request_target_branch"
71 72
    click_button "Compare branches"
    fill_in "merge_request_title", with: "Wiki Feature"
73
    click_button "Submit merge request"
74 75
  end

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

88
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
89 90
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
91 92
           source_project: project,
           target_project: project,
93
           author: project.users.first)
94 95
  end

96
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
97
    create(:closed_merge_request,
98
           title: "Feature NS-03",
99 100
           source_project: project,
           target_project: project,
Andrew8xx8's avatar
Andrew8xx8 committed
101
           author: project.users.first)
102 103
  end

104
  step 'project "Shop" has "MR-task-open" open MR with task markdown' do
105
    create_taskable(:merge_request, 'MR-task-open')
106 107
  end

108
  step 'I switch to the diff tab' do
109
    visit diffs_project_merge_request_path(project, merge_request)
110 111
  end

112
  step 'I switch to the merge request\'s comments tab' do
113
    visit project_merge_request_path(project, merge_request)
114 115
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
116 117
  step 'I click on the commit in the merge request' do
    within '.mr-commits' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
118
      click_link Commit.truncate_sha(sample_commit.id)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
119
    end
120 121
  end

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

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

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

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

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

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

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

159 160 161 162 163 164
  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
165
    fill_in 'commit_message', with: 'wow such merge'
166 167 168 169 170 171 172
  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
173 174 175 176
    Gitlab::Satellite::MergeAction.any_instance.stub(
      merge!: true,
    )

177 178 179 180
    click_button "Accept Merge Request"
  end

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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
186 187 188 189 190 191 192 193 194 195 196 197
  step 'I click link "Reopen"' do
    within '.page-title' do
      click_link "Reopen"
    end
  end

  step 'I should see reopened merge request "Bug NS-04"' do
    within '.state-label' do
      page.should have_content "Open"
    end
  end

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

  step 'I click link "Show inline discussion" of the second file' do
    within '.files [id^=diff]:nth-child(2)' do
206
      click_link "Diff comments"
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
    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

222 223 224 225 226 227 228 229 230 231 232 233
  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

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
  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
251
      fill_in "note_note", with: "Line is wrong on here"
252 253 254 255 256 257 258 259 260 261
      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
262 263 264 265 266 267 268 269
  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
270 271 272 273 274 275 276 277 278 279
  step 'I click Side-by-side Diff tab' do
    click_link 'Side-by-side Diff'
  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

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

  def init_diff_note
285
    click_diff_line(sample_commit.line_code)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
286 287 288 289 290 291 292 293
  end

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

294
    page.should have_content message
295
  end
296 297

  def init_diff_note_first_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
298
    click_diff_line(sample_compare.changes[0][:line_code])
299 300 301
  end

  def init_diff_note_second_file
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
302
    click_diff_line(sample_compare.changes[1][:line_code])
303 304 305 306 307
  end

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