merge_requests.rb 8.3 KB
Newer Older
1
class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
N
Nihad Abbasov 已提交
2
  include SharedAuthentication
V
Vinnie Okada 已提交
3
  include SharedIssuable
N
Nihad Abbasov 已提交
4 5 6
  include SharedProject
  include SharedNote
  include SharedPaths
7
  include SharedMarkdown
8
  include SharedDiffNote
N
Nihad Abbasov 已提交
9

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

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

18
  step 'I click link "All"' do
R
Riyad Preukschas 已提交
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
S
skv 已提交
33
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
34
    merge_request.closed?.should be_true
R
Riyad Preukschas 已提交
35
    page.should have_content "Closed by"
36 37
  end

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

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

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

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

R
Riyad Preukschas 已提交
54

55
  step 'I should not see "Bug NS-04" in merge requests' do
R
Riyad Preukschas 已提交
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
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

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

103
  step 'I switch to the diff tab' do
104
    visit diffs_project_merge_request_path(project, merge_request)
R
Riyad Preukschas 已提交
105 106
  end

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

D
Dmitriy Zaporozhets 已提交
111
  step 'I click on the commit in the merge request' do
D
Dmitriy Zaporozhets 已提交
112 113 114 115
    within '.merge-request-tabs' do
      click_link 'Commits'
    end

D
Dmitriy Zaporozhets 已提交
116
    within '.commits' do
D
Dmitriy Zaporozhets 已提交
117
      click_link Commit.truncate_sha(sample_commit.id)
D
Dmitriy Zaporozhets 已提交
118
    end
R
Riyad Preukschas 已提交
119 120
  end

121
  step 'I leave a comment on the diff page' do
122
    init_diff_note
D
Dmitriy Zaporozhets 已提交
123 124
    leave_comment "One comment to rule them all"
  end
D
Dmitriy Zaporozhets 已提交
125

D
Dmitriy Zaporozhets 已提交
126
  step 'I leave a comment on the diff page in commit' do
127
    click_diff_line(sample_commit.line_code)
D
Dmitriy Zaporozhets 已提交
128
    leave_comment "One comment to rule them all"
R
Riyad Preukschas 已提交
129 130
  end

D
Dmitriy Zaporozhets 已提交
131
  step 'I leave a comment like "Line is wrong" on diff' do
132
    init_diff_note
D
Dmitriy Zaporozhets 已提交
133 134
    leave_comment "Line is wrong"
  end
R
Riyad Preukschas 已提交
135

D
Dmitriy Zaporozhets 已提交
136
  step 'I leave a comment like "Line is wrong" on diff in commit' do
137
    click_diff_line(sample_commit.line_code)
D
Dmitriy Zaporozhets 已提交
138
    leave_comment "Line is wrong"
R
Riyad Preukschas 已提交
139 140
  end

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

D
Dmitriy Zaporozhets 已提交
147
  step 'I should see a discussion has started on commit diff' do
R
Riyad Preukschas 已提交
148
    page.should have_content "#{current_user.name} started a discussion on commit"
D
Dmitriy Zaporozhets 已提交
149
    page.should have_content sample_commit.line_code_path
R
Riyad Preukschas 已提交
150 151 152
    page.should have_content "Line is wrong"
  end

D
Dmitriy Zaporozhets 已提交
153
  step 'I should see a discussion has started on commit' do
D
Dmitriy Zaporozhets 已提交
154
    page.should have_content "#{current_user.name} started a discussion on commit"
R
Riyad Preukschas 已提交
155
    page.should have_content "One comment to rule them all"
156
  end
157

158
  step 'merge request is mergeable' do
D
Dmitriy Zaporozhets 已提交
159
    page.should have_button 'Accept Merge Request'
160 161 162 163
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
C
Ciro Santilli 已提交
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
D
Dmitriy Zaporozhets 已提交
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

D
Dmitriy Zaporozhets 已提交
185
  step 'I click link "Reopen"' do
186
    first(:css, '.reopen-mr-link').click
D
Dmitriy Zaporozhets 已提交
187 188 189
  end

  step 'I should see reopened merge request "Bug NS-04"' do
190
    within '.issue-box' do
D
Dmitriy Zaporozhets 已提交
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

S
skv 已提交
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

M
Marin Jankovski 已提交
267
  step 'I click Side-by-side Diff tab' do
D
Dmitriy Zaporozhets 已提交
268
    find('a', text: 'Side-by-side').trigger('click')
M
Marin Jankovski 已提交
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
S
skv 已提交
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)
D
Dmitriy Zaporozhets 已提交
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
D
Dmitriy Zaporozhets 已提交
295
    click_diff_line(sample_compare.changes[0][:line_code])
296 297 298
  end

  def init_diff_note_second_file
D
Dmitriy Zaporozhets 已提交
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