create_branch_merge_request_spec.rb 3.29 KB
Newer Older
1 2
require 'rails_helper'

3
feature 'Create Branch/Merge Request Dropdown on issue page', :feature, :js do
4
  let(:user) { create(:user) }
5
  let!(:project) { create(:project, :repository) }
6 7 8 9 10
  let(:issue) { create(:issue, project: project, title: 'Cherry-Coloured Funk') }

  context 'for team members' do
    before do
      project.team << [user, :developer]
11
      sign_in(user)
12 13 14
    end

    it 'allows creating a merge request from the issue page' do
15
      visit project_issue_path(project, issue)
16

17 18 19 20 21 22 23 24
      perform_enqueued_jobs do
        select_dropdown_option('create-mr')

        expect(page).to have_content('WIP: Resolve "Cherry-Coloured Funk"')
        expect(current_path).to eq(project_merge_request_path(project, MergeRequest.first))

        wait_for_requests
      end
25

26
      visit project_issue_path(project, issue)
27 28 29 30 31 32

      expect(page).to have_content("created branch 1-cherry-coloured-funk")
      expect(page).to have_content("mentioned in merge request !1")
    end

    it 'allows creating a branch from the issue page' do
33
      visit project_issue_path(project, issue)
34 35 36

      select_dropdown_option('create-branch')

37
      wait_for_requests
38 39

      expect(page).to have_selector('.dropdown-toggle-text ', text: '1-cherry-coloured-funk')
40
      expect(current_path).to eq project_tree_path(project, '1-cherry-coloured-funk')
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    end

    context "when there is a referenced merge request" do
      let!(:note) do
        create(:note, :on_issue, :system, project: project, noteable: issue,
                                          note: "mentioned in #{referenced_mr.to_reference}")
      end

      let(:referenced_mr) do
        create(:merge_request, :simple, source_project: project, target_project: project,
                                        description: "Fixes #{issue.to_reference}", author: user)
      end

      before do
        referenced_mr.cache_merge_request_closes_issues!(user)

57
        visit project_issue_path(project, issue)
58 59 60 61 62 63 64 65 66
      end

      it 'disables the create branch button' do
        expect(page).to have_css('.create-mr-dropdown-wrap .unavailable:not(.hide)')
        expect(page).to have_css('.create-mr-dropdown-wrap .available.hide', visible: false)
        expect(page).to have_content /1 Related Merge Request/
      end
    end

67 68 69 70 71 72 73 74 75 76 77 78 79
    context 'when merge requests are disabled' do
      before do
        project.project_feature.update(merge_requests_access_level: 0)

        visit project_issue_path(project, issue)
      end

      it 'shows only create branch button' do
        expect(page).not_to have_button('Create a merge request')
        expect(page).to have_button('Create a branch')
      end
    end

80 81 82 83
    context 'when issue is confidential' do
      it 'disables the create branch button' do
        issue = create(:issue, :confidential, project: project)

84
        visit project_issue_path(project, issue)
85 86 87 88 89 90 91 92

        expect(page).not_to have_css('.create-mr-dropdown-wrap')
      end
    end
  end

  context 'for visitors' do
    before do
93
      visit project_issue_path(project, issue)
94 95 96 97 98 99 100 101 102 103 104 105 106
    end

    it 'shows no buttons' do
      expect(page).not_to have_selector('.create-mr-dropdown-wrap')
    end
  end

  def select_dropdown_option(option)
    find('.create-mr-dropdown-wrap .dropdown-toggle').click
    find("li[data-value='#{option}']").click
    find('.js-create-merge-request').click
  end
end