form_spec.rb 10.2 KB
Newer Older
1 2 3
require 'rails_helper'

describe 'New/edit merge request', feature: true, js: true do
4 5
  include GitlabRoutingHelper

6 7 8
  let!(:project)   { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
  let(:fork_project) { create(:project, forked_from_project: project) }
  let!(:user)      { create(:user)}
9
  let!(:user2)      { create(:user)}
10 11 12 13 14 15
  let!(:milestone) { create(:milestone, project: project) }
  let!(:label)     { create(:label, project: project) }
  let!(:label2)    { create(:label, project: project) }

  before do
    project.team << [user, :master]
16
    project.team << [user2, :master]
17 18 19 20
  end

  context 'owned projects' do
    before do
21
      gitlab_sign_in(user)
22
    end
Phil Hughes's avatar
Phil Hughes committed
23

24 25
    context 'new merge request' do
      before do
26
        visit namespace_project_new_merge_request_path(
27 28 29 30 31 32 33 34 35
          project.namespace,
          project,
          merge_request: {
            source_project_id: project.id,
            target_project_id: project.id,
            source_branch: 'fix',
            target_branch: 'master'
          })
      end
36

Phil Hughes's avatar
Phil Hughes committed
37
      it 'creates new merge request' do
38 39
        click_button 'Assignee'
        page.within '.dropdown-menu-user' do
40
          click_link user2.name
41
        end
42 43 44 45 46 47
        expect(find('input[name="merge_request[assignee_id]"]', visible: false).value).to match(user2.id.to_s)
        page.within '.js-assignee-search' do
          expect(page).to have_content user2.name
        end

        click_link 'Assign to me'
48 49 50 51
        expect(find('input[name="merge_request[assignee_id]"]', visible: false).value).to match(user.id.to_s)
        page.within '.js-assignee-search' do
          expect(page).to have_content user.name
        end
Phil Hughes's avatar
Phil Hughes committed
52

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        click_button 'Milestone'
        page.within '.issue-milestone' do
          click_link milestone.title
        end
        expect(find('input[name="merge_request[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
        page.within '.js-milestone-select' do
          expect(page).to have_content milestone.title
        end

        click_button 'Labels'
        page.within '.dropdown-menu-labels' do
          click_link label.title
          click_link label2.title
        end
        page.within '.js-label-select' do
          expect(page).to have_content label.title
        end
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s)
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s)

        click_button 'Submit merge request'

        page.within '.issuable-sidebar' do
          page.within '.assignee' do
            expect(page).to have_content user.name
          end
Phil Hughes's avatar
Phil Hughes committed
79

80 81 82
          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
Phil Hughes's avatar
Phil Hughes committed
83

84 85 86 87 88
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
89 90 91 92

        page.within '.issuable-meta' do
          merge_request = MergeRequest.find_by(source_branch: 'fix')

Annabel Dunstone Gray's avatar
Annabel Dunstone Gray committed
93
          expect(page).to have_text("Merge request #{merge_request.to_reference}")
94 95 96 97
          # compare paths because the host differ in test
          expect(find_link(merge_request.to_reference)[:href])
            .to end_with(merge_request_path(merge_request))
        end
Phil Hughes's avatar
Phil Hughes committed
98
      end
99 100 101 102 103 104 105

      it 'description has autocomplete' do
        find('#merge_request_description').native.send_keys('')
        fill_in 'merge_request_description', with: '@'

        expect(page).to have_selector('.atwho-view')
      end
106
    end
Phil Hughes's avatar
Phil Hughes committed
107

108 109 110 111 112 113 114 115
    context 'edit merge request' do
      before do
        merge_request = create(:merge_request,
                                 source_project: project,
                                 target_project: project,
                                 source_branch: 'fix',
                                 target_branch: 'master'
                              )
Phil Hughes's avatar
Phil Hughes committed
116

117
        visit edit_namespace_project_merge_request_path(project.namespace, project, merge_request)
Phil Hughes's avatar
Phil Hughes committed
118 119
      end

Phil Hughes's avatar
Phil Hughes committed
120
      it 'updates merge request' do
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        click_button 'Assignee'
        page.within '.dropdown-menu-user' do
          click_link user.name
        end
        expect(find('input[name="merge_request[assignee_id]"]', visible: false).value).to match(user.id.to_s)
        page.within '.js-assignee-search' do
          expect(page).to have_content user.name
        end

        click_button 'Milestone'
        page.within '.issue-milestone' do
          click_link milestone.title
        end
        expect(find('input[name="merge_request[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
        page.within '.js-milestone-select' do
          expect(page).to have_content milestone.title
        end

        click_button 'Labels'
        page.within '.dropdown-menu-labels' do
          click_link label.title
          click_link label2.title
        end
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s)
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s)
        page.within '.js-label-select' do
          expect(page).to have_content label.title
        end

        click_button 'Save changes'

        page.within '.issuable-sidebar' do
          page.within '.assignee' do
            expect(page).to have_content user.name
          end

          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
Phil Hughes's avatar
Phil Hughes committed
160

161 162 163 164 165
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes's avatar
Phil Hughes committed
166
      end
167 168 169 170 171 172 173

      it 'description has autocomplete' do
        find('#merge_request_description').native.send_keys('')
        fill_in 'merge_request_description', with: '@'

        expect(page).to have_selector('.atwho-view')
      end
174 175 176 177 178 179
    end
  end

  context 'forked project' do
    before do
      fork_project.team << [user, :master]
180
      gitlab_sign_in(user)
181
    end
182

183 184
    context 'new merge request' do
      before do
185
        visit namespace_project_new_merge_request_path(
186 187 188 189 190 191 192 193 194
          fork_project.namespace,
          fork_project,
          merge_request: {
            source_project_id: fork_project.id,
            target_project_id: project.id,
            source_branch: 'fix',
            target_branch: 'master'
          })
      end
195

Phil Hughes's avatar
Phil Hughes committed
196
      it 'creates new merge request' do
197 198 199 200 201 202 203 204
        click_button 'Assignee'
        page.within '.dropdown-menu-user' do
          click_link user.name
        end
        expect(find('input[name="merge_request[assignee_id]"]', visible: false).value).to match(user.id.to_s)
        page.within '.js-assignee-search' do
          expect(page).to have_content user.name
        end
205

206 207 208 209 210 211 212 213
        click_button 'Milestone'
        page.within '.issue-milestone' do
          click_link milestone.title
        end
        expect(find('input[name="merge_request[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
        page.within '.js-milestone-select' do
          expect(page).to have_content milestone.title
        end
214

215 216 217 218 219 220 221 222 223 224
        click_button 'Labels'
        page.within '.dropdown-menu-labels' do
          click_link label.title
          click_link label2.title
        end
        page.within '.js-label-select' do
          expect(page).to have_content label.title
        end
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s)
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s)
225

226 227 228 229 230 231
        click_button 'Submit merge request'

        page.within '.issuable-sidebar' do
          page.within '.assignee' do
            expect(page).to have_content user.name
          end
232

233 234 235
          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
236

237 238 239 240 241
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes's avatar
Phil Hughes committed
242
      end
243
    end
244

245 246 247 248 249 250 251 252
    context 'edit merge request' do
      before do
        merge_request = create(:merge_request,
                                 source_project: fork_project,
                                 target_project: project,
                                 source_branch: 'fix',
                                 target_branch: 'master'
                              )
253

254
        visit edit_namespace_project_merge_request_path(project.namespace, project, merge_request)
Phil Hughes's avatar
Phil Hughes committed
255
      end
256

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
      it 'should update merge request' do
        click_button 'Assignee'
        page.within '.dropdown-menu-user' do
          click_link user.name
        end
        expect(find('input[name="merge_request[assignee_id]"]', visible: false).value).to match(user.id.to_s)
        page.within '.js-assignee-search' do
          expect(page).to have_content user.name
        end

        click_button 'Milestone'
        page.within '.issue-milestone' do
          click_link milestone.title
        end
        expect(find('input[name="merge_request[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
        page.within '.js-milestone-select' do
          expect(page).to have_content milestone.title
        end

        click_button 'Labels'
        page.within '.dropdown-menu-labels' do
          click_link label.title
          click_link label2.title
        end
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s)
        expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s)
        page.within '.js-label-select' do
          expect(page).to have_content label.title
        end

        click_button 'Save changes'

        page.within '.issuable-sidebar' do
          page.within '.assignee' do
            expect(page).to have_content user.name
          end

          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
297

298 299 300 301 302
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes's avatar
Phil Hughes committed
303
      end
304 305 306
    end
  end
end