File: issues_menu_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (158 lines) | stat: -rw-r--r-- 4,146 bytes parent folder | download
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Sidebars::Projects::Menus::IssuesMenu, feature_category: :navigation do
  let(:project) { build(:project) }
  let(:user) { project.first_owner }
  let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }

  subject { described_class.new(context) }

  it_behaves_like 'serializable as super_sidebar_menu_args' do
    let(:menu) { subject }
    let(:extra_attrs) do
      {
        item_id: :project_issue_list,
        active_routes: { path: %w[projects/issues#index projects/issues#show projects/issues#new] },
        pill_count: menu.pill_count,
        pill_count_field: menu.pill_count_field,
        has_pill: menu.has_pill?,
        super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::PlanMenu
      }
    end
  end

  describe '#render?' do
    context 'when user can read issues' do
      it 'returns true' do
        expect(subject.render?).to eq true
      end
    end

    context 'when user cannot read issues' do
      let(:user) { nil }

      it 'returns false' do
        expect(subject.render?).to eq false
      end
    end
  end

  describe '#has_pill?' do
    context 'when issues feature is enabled' do
      it 'returns true' do
        expect(subject.has_pill?).to eq true
      end
    end

    context 'when issue feature is disabled' do
      it 'returns false' do
        allow(project).to receive(:issues_enabled?).and_return(false)

        expect(subject.has_pill?).to eq false
      end
    end
  end

  describe '#pill_count' do
    before do
      stub_feature_flags(async_sidebar_counts: false)
    end

    it 'returns zero when there are no open issues' do
      expect(subject.pill_count).to eq '0'
    end

    it 'memoizes the query' do
      subject.pill_count

      control = ActiveRecord::QueryRecorder.new do
        subject.pill_count
      end

      expect(control.count).to eq 0
    end

    context 'when there are open issues' do
      it 'returns the number of open issues' do
        create_list(:issue, 2, :opened, project: project)
        build_stubbed(:issue, :closed, project: project)

        expect(subject.pill_count).to eq '2'
      end
    end

    describe 'formatting' do
      it 'returns truncated digits for count value over 1000' do
        allow(project).to receive(:open_issues_count).and_return 1001
        expect(subject.pill_count).to eq('1k')
      end
    end

    context 'when async_sidebar_counts feature flag is enabled' do
      before do
        stub_feature_flags(async_sidebar_counts: true)
      end

      it 'returns nil' do
        expect(subject.pill_count).to be_nil
      end
    end
  end

  describe '#pill_count_field' do
    it 'returns the correct GraphQL field name' do
      expect(subject.pill_count_field).to eq('openIssuesCount')
    end

    context 'when async_sidebar_counts feature flag is disabled' do
      before do
        stub_feature_flags(async_sidebar_counts: false)
      end

      it 'returns nil' do
        expect(subject.pill_count_field).to be_nil
      end
    end
  end

  describe 'Menu Items' do
    subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }

    describe 'Service Desk' do
      let(:item_id) { :service_desk }

      describe 'when service desk is supported' do
        before do
          allow(Gitlab::ServiceDesk).to receive(:supported?).and_return(true)
        end

        describe 'when service desk is enabled' do
          before do
            project.update!(service_desk_enabled: true)
          end

          it { is_expected.not_to be_nil }
        end

        describe 'when service desk is disabled' do
          before do
            project.update!(service_desk_enabled: false)
          end

          it { is_expected.to be_nil }
        end
      end

      describe 'when service desk is unsupported' do
        before do
          allow(Gitlab::ServiceDesk).to receive(:supported?).and_return(false)
          project.update!(service_desk_enabled: true)
        end

        it { is_expected.to be_nil }
      end
    end
  end
end