user_sees_cherry_pick_modal_spec.rb 1.92 KB
Newer Older
1
require 'rails_helper'
Douwe Maan's avatar
Douwe Maan committed
2

3
describe 'Merge request > User cherry-picks', :js do
4
  let(:group) { create(:group) }
5
  let(:project) { create(:project, :repository, namespace: group) }
6
  let(:user) { project.creator }
Douwe Maan's avatar
Douwe Maan committed
7 8 9
  let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user) }

  before do
10
    project.add_maintainer(user)
11
    sign_in(user)
Douwe Maan's avatar
Douwe Maan committed
12 13
  end

14
  context 'Viewing a merged merge request' do
Douwe Maan's avatar
Douwe Maan committed
15 16 17 18 19 20 21 22 23
    before do
      service = MergeRequests::MergeService.new(project, user)

      perform_enqueued_jobs do
        service.execute(merge_request)
      end
    end

    # Fast-forward merge, or merged before GitLab 8.5.
24
    context 'without a merge commit' do
Douwe Maan's avatar
Douwe Maan committed
25 26 27 28 29
      before do
        merge_request.merge_commit_sha = nil
        merge_request.save
      end

30
      it 'does not show a Cherry-pick button' do
31
        visit project_merge_request_path(project, merge_request)
Douwe Maan's avatar
Douwe Maan committed
32

33
        expect(page).not_to have_link 'Cherry-pick'
Douwe Maan's avatar
Douwe Maan committed
34 35 36
      end
    end

37
    context 'with a merge commit' do
38
      it 'shows a Cherry-pick button' do
39
        visit project_merge_request_path(project, merge_request)
Douwe Maan's avatar
Douwe Maan committed
40

41
        expect(page).to have_link 'Cherry-pick'
Douwe Maan's avatar
Douwe Maan committed
42
      end
43 44 45 46 47 48 49 50

      it 'hides the cherry pick button for an archived project' do
        project.update!(archived: true)

        visit project_merge_request_path(project, merge_request)

        expect(page).not_to have_link 'Cherry-pick'
      end
Douwe Maan's avatar
Douwe Maan committed
51
    end
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

    context 'and seeing the cherry-pick modal' do
      before do
        visit project_merge_request_path(project, merge_request)

        click_link('Cherry-pick')
      end

      it 'shows the cherry-pick modal' do
        expect(page).to have_content('Cherry-pick this merge request')
      end

      it 'closes the cherry-pick modal with escape keypress' do
        find('#modal-cherry-pick-commit').send_keys(:escape)

        expect(page).not_to have_content('Start a new merge request with these changes')
      end
    end
Douwe Maan's avatar
Douwe Maan committed
70 71
  end
end