2021-06-08 01:23:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Sidebars::Projects::Menus::IssuesMenu, feature_category: :navigation do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:project) { build(:project) }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:user) { project.first_owner }
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
|
|
|
|
|
|
|
|
subject { described_class.new(context) }
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it_behaves_like 'serializable as super_sidebar_menu_args' do
|
|
|
|
let(:menu) { subject }
|
|
|
|
let(:extra_attrs) do
|
|
|
|
{
|
|
|
|
item_id: :project_issue_list,
|
|
|
|
sprite_icon: 'issues',
|
|
|
|
pill_count: menu.pill_count,
|
|
|
|
has_pill: menu.has_pill?,
|
|
|
|
super_sidebar_parent: ::Sidebars::StaticMenu
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
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
|
|
|
|
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)
|
|
|
|
create(:issue, :closed, project: project)
|
|
|
|
|
|
|
|
expect(subject.pill_count).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|