BigW Consortium Gitlab

form_spec.rb 10 KB
Newer Older
1 2
require 'rails_helper'

3
describe 'New/edit merge request', :js do
4 5 6 7 8 9 10
  let!(:project)     { create(:project, :public, :repository) }
  let(:fork_project) { create(:project, :repository, forked_from_project: project) }
  let!(:user)        { create(:user) }
  let!(:user2)       { create(:user) }
  let!(:milestone)   { create(:milestone, project: project) }
  let!(:label)       { create(:label, project: project) }
  let!(:label2)      { create(:label, project: project) }
11 12 13

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

  context 'owned projects' do
    before do
19
      sign_in(user)
20
    end
21

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

34
      it 'creates new merge request' do
35 36
        click_button 'Assignee'
        page.within '.dropdown-menu-user' do
37
          click_link user2.name
38
        end
39 40 41 42 43
        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

44
        find('a', text: 'Assign to me').trigger('click')
45 46 47 48
        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
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        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
76

77 78 79
          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
Phil Hughes committed
80

81 82 83 84 85
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
86 87 88 89

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

Annabel Dunstone Gray committed
90
          expect(page).to have_text("Merge request #{merge_request.to_reference}")
91 92 93 94
          # 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
95
      end
96 97 98 99 100 101 102

      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
103
    end
Phil Hughes committed
104

105 106 107 108 109 110 111 112
    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
113

114
        visit edit_project_merge_request_path(project, merge_request)
Phil Hughes committed
115 116
      end

117
      it 'updates merge request' do
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 153 154 155 156
        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
157

158 159 160 161 162
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes committed
163
      end
164 165 166 167 168 169 170

      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
171 172 173 174 175 176
    end
  end

  context 'forked project' do
    before do
      fork_project.team << [user, :master]
177
      sign_in(user)
178
    end
179

180 181
    context 'new merge request' do
      before do
182
        visit project_new_merge_request_path(
183 184 185 186 187 188 189 190
          fork_project,
          merge_request: {
            source_project_id: fork_project.id,
            target_project_id: project.id,
            source_branch: 'fix',
            target_branch: 'master'
          })
      end
191

192
      it 'creates new merge request' do
193 194 195 196 197 198 199 200
        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
201

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

211 212 213 214 215 216 217 218 219 220
        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)
221

222 223 224 225 226 227
        click_button 'Submit merge request'

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

229 230 231
          page.within '.milestone' do
            expect(page).to have_content milestone.title
          end
232

233 234 235 236 237
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes committed
238
      end
239
    end
240

241 242 243 244 245 246 247 248
    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'
                              )
249

250
        visit edit_project_merge_request_path(project, merge_request)
Phil Hughes committed
251
      end
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 283 284 285 286 287 288 289 290 291 292
      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
293

294 295 296 297 298
          page.within '.labels' do
            expect(page).to have_content label.title
            expect(page).to have_content label2.title
          end
        end
Phil Hughes committed
299
      end
300 301 302
    end
  end
end