summaryrefslogtreecommitdiff
path: root/spec/features/issues/move_spec.rb
blob: 490e00f8ab8e03db6969961f937fef1b87fd97ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'rails_helper'

feature 'issue move to another project' do
  let(:user) { create(:user) }
  let(:old_project) { create(:project) }
  let(:text) { 'Some issue description' }

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

  background { sign_in(user) }

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

      edit_issue(issue)
    end

    scenario 'moving issue to another project not allowed' do
      expect(page).to have_no_selector('#move_to_project_id')
    end
  end

  context 'user has permission to move issue' do
    let!(:mr) { create(:merge_request, source_project: old_project) }
    let(:new_project) { create(:project) }
    let(:new_project_search) { create(:project) }
    let(:text) { "Text with #{mr.to_reference}" }
    let(:cross_reference) { old_project.to_reference(new_project) }

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

      edit_issue(issue)
    end

    scenario 'moving issue to another project', js: true do
      find('#issuable-move', visible: false).set(new_project.id)
      click_button('Save changes')

      wait_for_requests

      expect(current_url).to include project_path(new_project)

      expect(page).to have_content("Text with #{cross_reference}#{mr.to_reference}")
      expect(page).to have_content("moved from #{cross_reference}#{issue.to_reference}")
      expect(page).to have_content(issue.title)
    end

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

      page.within '.detail-page-description' do
        first('.select2-choice').click
      end

      fill_in('s2id_autogen1_search', with: new_project_search.name)

      page.within '.select2-drop' do
        expect(page).to have_content(new_project_search.name)
        expect(page).not_to have_content(new_project.name)
      end
    end

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

      scenario 'browsing projects in projects select' do
        click_link 'Move to a different project'

        page.within '.select2-results' do
          expect(page).to have_content 'No project'
          expect(page).to have_content new_project.name_with_namespace
        end
      end
    end

    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
        expect(page).to have_no_selector('#move_to_project_id')
      end
    end
  end

  def edit_issue(issue)
    visit issue_path(issue)
    page.within('.issuable-actions') { first(:link, 'Edit').click }
  end

  def issue_path(issue)
    namespace_project_issue_path(issue.project.namespace, issue.project, issue)
  end

  def project_path(project)
    namespace_project_path(new_project.namespace, new_project)
  end
end