BigW Consortium Gitlab

form_spec.rb 9.77 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 21 22
  end

  context 'owned projects' do
    before do
      login_as(user)
    end
23

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

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 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 committed
79

80 81 82
          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
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 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 committed
98
      end
99
    end
Phil Hughes committed
100

101 102 103 104 105 106 107 108
    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 committed
109

110
        visit edit_namespace_project_merge_request_path(project.namespace, project, merge_request)
Phil Hughes committed
111 112
      end

113
      it 'updates merge request' do
114 115 116 117 118 119 120 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
        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 committed
153

154 155 156 157 158
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes committed
159
      end
160 161 162 163 164 165
    end
  end

  context 'forked project' do
    before do
      fork_project.team << [user, :master]
166 167
      login_as(user)
    end
168

169 170 171 172 173 174 175 176 177 178 179 180
    context 'new merge request' do
      before do
        visit new_namespace_project_merge_request_path(
          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
181

182
      it 'creates new merge request' do
183 184 185 186 187 188 189 190
        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
191

192 193 194 195 196 197 198 199
        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
200

201 202 203 204 205 206 207 208 209 210
        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)
211

212 213 214 215 216 217
        click_button 'Submit merge request'

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

219 220 221
          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
222

223 224 225 226 227
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes committed
228
      end
229
    end
230

231 232 233 234 235 236 237 238
    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'
                              )
239

240
        visit edit_namespace_project_merge_request_path(project.namespace, project, merge_request)
Phil Hughes committed
241
      end
242

243 244 245 246 247 248 249 250 251 252 253 254 255 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
      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
283

284 285 286 287 288
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes committed
289
      end
290 291 292
    end
  end
end