BigW Consortium Gitlab

move_spec.rb 2.99 KB
Newer Older
1 2 3 4
require 'rails_helper'

feature 'issue move to another project' do
  let(:user) { create(:user) }
5
  let(:old_project) { create(:project, :repository) }
6 7 8 9 10 11
  let(:text) { 'Some issue description' }

  let(:issue) do
    create(:issue, description: text, project: old_project, author: user)
  end

12
  background { sign_in(user) }
13 14 15 16 17

  context 'user does not have permission to move issue' do
    background do
      old_project.team << [user, :guest]

18
      visit issue_path(issue)
19 20 21
    end

    scenario 'moving issue to another project not allowed' do
22
      expect(page).to have_no_selector('.js-sidebar-move-issue-block')
23 24 25 26 27
    end
  end

  context 'user has permission to move issue' do
    let!(:mr) { create(:merge_request, source_project: old_project) }
28 29
    let(:new_project) { create(:project) }
    let(:new_project_search) { create(:project) }
30
    let(:text) { "Text with #{mr.to_reference}" }
31
    let(:cross_reference) { old_project.to_reference(new_project) }
32 33 34 35 36

    background do
      old_project.team << [user, :reporter]
      new_project.team << [user, :reporter]

37
      visit issue_path(issue)
38 39
    end

40
    scenario 'moving issue to another project', :js do
41
      find('.js-move-issue').click
42 43 44
      wait_for_requests
      all('.js-move-issue-dropdown-item')[0].click
      find('.js-move-issue-confirmation-button').click
45

46 47
      expect(page).to have_content("Text with #{cross_reference}#{mr.to_reference}")
      expect(page).to have_content("moved from #{cross_reference}#{issue.to_reference}")
Phil Hughes committed
48
      expect(page).to have_content(issue.title)
49
      expect(page.current_path).to include project_path(new_project)
50 51
    end

52
    scenario 'searching project dropdown', :js do
53 54
      new_project_search.team << [user, :reporter]

55
      find('.js-move-issue').click
56
      wait_for_requests
57

58 59
      page.within '.js-sidebar-move-issue-block' do
        fill_in('sidebar-move-issue-dropdown-search', with: new_project_search.name)
60 61 62 63 64 65

        expect(page).to have_content(new_project_search.name)
        expect(page).not_to have_content(new_project.name)
      end
    end

66
    context 'user does not have permission to move the issue to a project', :js do
67 68
      let!(:private_project) { create(:project, :private) }
      let(:another_project) { create(:project) }
69 70 71
      background { another_project.team << [user, :guest] }

      scenario 'browsing projects in projects select' do
72
        find('.js-move-issue').click
73
        wait_for_requests
Phil Hughes committed
74

75
        page.within '.js-sidebar-move-issue-block' do
Phil Hughes committed
76 77
          expect(page).to have_content new_project.name_with_namespace
        end
78 79
      end
    end
80 81 82 83 84 85 86 87

    context 'issue has been already moved' do
      let(:new_issue) { create(:issue, project: new_project) }
      let(:issue) do
        create(:issue, project: old_project, author: user, moved_to: new_issue)
      end

      scenario 'user wants to move issue that has already been moved' do
Phil Hughes committed
88
        expect(page).to have_no_selector('#move_to_project_id')
89 90
      end
    end
91 92 93
  end

  def issue_path(issue)
94
    project_issue_path(issue.project, issue)
95 96
  end
end