merge_requests.rb 8.0 KB
Newer Older
1
class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
N
Nihad Abbasov 已提交
2 3 4 5
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths
6
  include SharedMarkdown
N
Nihad Abbasov 已提交
7

8
  step 'I click link "New Merge Request"' do
R
Riyad Preukschas 已提交
9
    click_link "New Merge Request"
10 11
  end

12
  step 'I click link "Bug NS-04"' do
R
Riyad Preukschas 已提交
13 14 15
    click_link "Bug NS-04"
  end

16
  step 'I click link "All"' do
R
Riyad Preukschas 已提交
17
    click_link "All"
18 19
  end

20
  step 'I click link "Closed"' do
21 22 23
    click_link "Closed"
  end

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

30
  step 'I should see closed merge request "Bug NS-04"' do
S
skv 已提交
31
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
32
    merge_request.closed?.should be_true
R
Riyad Preukschas 已提交
33
    page.should have_content "Closed by"
34 35
  end

36
  step 'I should see merge request "Bug NS-04"' do
R
Riyad Preukschas 已提交
37
    page.should have_content "Bug NS-04"
38 39
  end

40
  step 'I should see "Bug NS-04" in merge requests' do
R
Riyad Preukschas 已提交
41
    page.should have_content "Bug NS-04"
42 43
  end

44
  step 'I should see "Feature NS-03" in merge requests' do
R
Riyad Preukschas 已提交
45
    page.should have_content "Feature NS-03"
46 47
  end

48
  step 'I should not see "Feature NS-03" in merge requests' do
R
Riyad Preukschas 已提交
49
    page.should_not have_content "Feature NS-03"
50 51
  end

R
Riyad Preukschas 已提交
52

53
  step 'I should not see "Bug NS-04" in merge requests' do
R
Riyad Preukschas 已提交
54
    page.should_not have_content "Bug NS-04"
55 56
  end

57
  step 'I click link "Close"' do
58 59 60
    within '.page-title' do
      click_link "Close"
    end
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
A
Andrew8xx8 已提交
72
    create(:merge_request,
R
Riyad Preukschas 已提交
73
           title: "Bug NS-04",
I
Izaak Alpert 已提交
74 75
           source_project: project,
           target_project: project,
76
           source_branch: 'fix',
D
Dmitriy Zaporozhets 已提交
77
           target_branch: 'master',
78 79 80
           author: project.users.first,
           description: "# Description header"
          )
R
Riyad Preukschas 已提交
81 82
  end

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

91
  step 'project "Shop" have "Feature NS-03" closed merge request' do
A
Andrew8xx8 已提交
92
    create(:closed_merge_request,
R
Riyad Preukschas 已提交
93
           title: "Feature NS-03",
I
Izaak Alpert 已提交
94 95
           source_project: project,
           target_project: project,
A
Andrew8xx8 已提交
96
           author: project.users.first)
R
Riyad Preukschas 已提交
97 98
  end

99
  step 'I switch to the diff tab' do
100
    visit diffs_project_merge_request_path(project, merge_request)
R
Riyad Preukschas 已提交
101 102
  end

103
  step 'I switch to the merge request\'s comments tab' do
104
    visit project_merge_request_path(project, merge_request)
R
Riyad Preukschas 已提交
105 106
  end

D
Dmitriy Zaporozhets 已提交
107 108 109
  step 'I click on the commit in the merge request' do
    within '.mr-commits' do
      click_link sample_commit.id[0..8]
D
Dmitriy Zaporozhets 已提交
110
    end
R
Riyad Preukschas 已提交
111 112
  end

113
  step 'I leave a comment on the diff page' do
114
    init_diff_note
D
Dmitriy Zaporozhets 已提交
115 116
    leave_comment "One comment to rule them all"
  end
D
Dmitriy Zaporozhets 已提交
117

D
Dmitriy Zaporozhets 已提交
118
  step 'I leave a comment on the diff page in commit' do
119
    click_diff_line(sample_commit.line_code)
D
Dmitriy Zaporozhets 已提交
120
    leave_comment "One comment to rule them all"
R
Riyad Preukschas 已提交
121 122
  end

D
Dmitriy Zaporozhets 已提交
123
  step 'I leave a comment like "Line is wrong" on diff' do
124
    init_diff_note
D
Dmitriy Zaporozhets 已提交
125 126
    leave_comment "Line is wrong"
  end
R
Riyad Preukschas 已提交
127

D
Dmitriy Zaporozhets 已提交
128
  step 'I leave a comment like "Line is wrong" on diff in commit' do
129
    click_diff_line(sample_commit.line_code)
D
Dmitriy Zaporozhets 已提交
130
    leave_comment "Line is wrong"
R
Riyad Preukschas 已提交
131 132
  end

D
Dmitriy Zaporozhets 已提交
133
  step 'I should see a discussion has started on diff' do
134
    page.should have_content "#{current_user.name} started a discussion"
D
Dmitriy Zaporozhets 已提交
135
    page.should have_content sample_commit.line_code_path
R
Riyad Preukschas 已提交
136 137 138
    page.should have_content "Line is wrong"
  end

D
Dmitriy Zaporozhets 已提交
139
  step 'I should see a discussion has started on commit diff' do
R
Riyad Preukschas 已提交
140
    page.should have_content "#{current_user.name} started a discussion on commit"
D
Dmitriy Zaporozhets 已提交
141
    page.should have_content sample_commit.line_code_path
R
Riyad Preukschas 已提交
142 143 144
    page.should have_content "Line is wrong"
  end

D
Dmitriy Zaporozhets 已提交
145
  step 'I should see a discussion has started on commit' do
D
Dmitriy Zaporozhets 已提交
146
    page.should have_content "#{current_user.name} started a discussion on commit"
R
Riyad Preukschas 已提交
147
    page.should have_content "One comment to rule them all"
148
  end
149

150 151 152 153 154 155 156 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
    fill_in 'merge_commit_message', with: "wow such merge"
  end

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

  step 'I accept this merge request' do
D
Dmitriy Zaporozhets 已提交
164 165 166 167
    Gitlab::Satellite::MergeAction.any_instance.stub(
      merge!: true,
    )

168 169 170 171
    click_button "Accept Merge Request"
  end

  step 'I should see merged request' do
172
    within '.issue-box' do
173 174 175 176
      page.should have_content "Merged"
    end
  end

D
Dmitriy Zaporozhets 已提交
177 178 179 180 181 182 183 184 185 186 187 188
  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

189 190
  step 'I click link "Hide inline discussion" of the second file' do
    within '.files [id^=diff]:nth-child(2)' do
191
      click_link "Diff comments"
192 193 194 195 196
    end
  end

  step 'I click link "Show 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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
    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

  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
      fill_in "note_note", with: "Line is wrong"
      click_button "Add Comment"
    end

    within ".files [id^=diff]:nth-child(2) .note-text" do
      page.should have_content "Line is wrong"
    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

S
skv 已提交
245 246 247 248 249 250 251 252
  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

M
Marin Jankovski 已提交
253 254 255 256 257 258 259 260 261 262
  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

263
  def project
S
skv 已提交
264
    @project ||= Project.find_by!(name: "Shop")
265 266 267
  end

  def merge_request
S
skv 已提交
268
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
269
  end
270 271

  def init_diff_note
272
    click_diff_line(sample_commit.line_code)
D
Dmitriy Zaporozhets 已提交
273 274 275 276 277 278 279 280
  end

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

281
    page.should have_content message
282
  end
283 284

  def init_diff_note_first_file
D
Dmitriy Zaporozhets 已提交
285
    click_diff_line(sample_compare.changes[0][:line_code])
286 287 288
  end

  def init_diff_note_second_file
D
Dmitriy Zaporozhets 已提交
289
    click_diff_line(sample_compare.changes[1][:line_code])
290 291 292 293 294
  end

  def have_visible_content (text)
    have_css("*", text: text, visible: true)
  end
295 296 297 298

  def click_diff_line(code)
    find("a[data-line-code='#{code}']").click
  end
299
end