Welcome to mirror list, hosted at ThFree Co, Russian Federation.

type_change_quick_actions_shared_examples.rb « work_item « quick_actions « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0fc914d71d5d13c6dcacc5eaa5212ca8a27128e9 (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
# frozen_string_literal: true

RSpec.shared_examples 'quick actions that change work item type' do
  include_context 'with work item change type context'

  describe 'type command' do
    let(:command) { "/type #{new_type}" }

    it 'populates :issue_type: and :work_item_type' do
      _, updates, message = service.execute(command, work_item)

      expect(message).to eq(_('Type changed successfully.'))
      expect(updates).to eq({ issue_type: 'task', work_item_type: WorkItems::Type.default_by_type(:task) })
    end

    context 'when new type is invalid' do
      let(:command) { '/type foo' }

      it_behaves_like 'quick command error', 'Provided type is not supported'
    end

    context 'when new type is the same as current type' do
      let(:command) { '/type issue' }

      it_behaves_like 'quick command error', 'Types are the same'
    end

    context 'when user has insufficient permissions to create new type' do
      let(:with_access) { false }

      it_behaves_like 'quick command error', 'You have insufficient permissions'
    end
  end

  describe 'promote_to command' do
    let(:new_type) { 'issue' }
    let(:command) { "/promote_to #{new_type}" }

    shared_examples 'action with validation errors' do
      context 'when user has insufficient permissions to create new type' do
        let(:with_access) { false }

        it_behaves_like 'quick command error', 'You have insufficient permissions', 'promote'
      end

      context 'when new type is not supported' do
        let(:new_type) { unsupported_type }

        it_behaves_like 'quick command error', 'Provided type is not supported', 'promote'
      end
    end

    context 'with issue' do
      let(:new_type) { 'incident' }
      let(:unsupported_type) { 'task' }

      it 'populates :issue_type: and :work_item_type' do
        _, updates, message = service.execute(command, work_item)

        expect(message).to eq(_('Work item promoted successfully.'))
        expect(updates).to eq({ issue_type: 'incident', work_item_type: WorkItems::Type.default_by_type(:incident) })
      end

      it_behaves_like 'action with validation errors'
    end

    context 'with task' do
      let_it_be_with_reload(:task) { create(:work_item, :task, project: project) }
      let(:work_item) { task }
      let(:new_type) { 'issue' }
      let(:unsupported_type) { 'incident' }

      it 'populates :issue_type: and :work_item_type' do
        _, updates, message = service.execute(command, work_item)

        expect(message).to eq(_('Work item promoted successfully.'))
        expect(updates).to eq({ issue_type: 'issue', work_item_type: WorkItems::Type.default_by_type(:issue) })
      end

      it_behaves_like 'action with validation errors'

      context 'when task has a parent' do
        let_it_be(:parent) { create(:work_item, :issue, project: project) }

        before do
          create(:parent_link, work_item: task, work_item_parent: parent)
        end

        it_behaves_like 'quick command error', 'A task cannot be promoted when a parent issue is present', 'promote'
      end
    end
  end
end