debian-mirror-gitlab/spec/lib/sidebars/projects/menus/analytics_menu_spec.rb

131 lines
3.3 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::AnalyticsMenu do
let_it_be(:project) { create(:project, :repository) }
2021-08-04 16:29:09 +05:30
let_it_be(:guest) do
create(:user).tap { |u| project.add_guest(u) }
end
2021-06-08 01:23:25 +05:30
2021-08-04 16:29:09 +05:30
let(:owner) { project.owner }
let(:current_user) { owner }
let(:context) { Sidebars::Projects::Context.new(current_user: current_user, container: project, current_ref: project.repository.root_ref) }
2021-06-08 01:23:25 +05:30
subject { described_class.new(context) }
describe '#render?' do
context 'whe user cannot read analytics' do
2021-08-04 16:29:09 +05:30
let(:current_user) { nil }
2021-06-08 01:23:25 +05:30
it 'returns false' do
expect(subject.render?).to be false
end
end
context 'whe user can read analytics' do
it 'returns true' do
expect(subject.render?).to be true
end
context 'when menu does not have any menu items' do
it 'returns false' do
allow(subject).to receive(:has_renderable_items?).and_return(false)
expect(subject.render?).to be false
end
end
context 'when menu has menu items' do
it 'returns true' do
expect(subject.render?).to be true
end
end
end
end
describe '#link' do
it 'returns link to the value stream page' do
expect(subject.link).to include('/-/value_stream_analytics')
end
context 'when Value Stream is not visible' do
it 'returns link to the the first visible menu item' do
allow(subject).to receive(:cycle_analytics_menu_item).and_return(double(render?: false))
expect(subject.link).to eq subject.renderable_items.first.link
end
end
end
describe 'Menu items' do
subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }
describe 'CI/CD' do
let(:item_id) { :ci_cd_analytics }
specify { is_expected.not_to be_nil }
describe 'when the project repository is empty' do
before do
allow(project).to receive(:empty_repo?).and_return(true)
end
specify { is_expected.to be_nil }
end
describe 'when builds access level is DISABLED' do
before do
project.project_feature.update!(builds_access_level: Featurable::DISABLED)
end
specify { is_expected.to be_nil }
end
describe 'when the user does not have access' do
2021-08-04 16:29:09 +05:30
let(:current_user) { guest }
2021-06-08 01:23:25 +05:30
specify { is_expected.to be_nil }
end
end
describe 'Repository' do
let(:item_id) { :repository_analytics }
specify { is_expected.not_to be_nil }
describe 'when the project repository is empty' do
before do
allow(project).to receive(:empty_repo?).and_return(true)
end
specify { is_expected.to be_nil }
end
2021-12-07 22:27:20 +05:30
describe 'when a user does not have access to repository graphs' do
let(:current_user) { guest }
specify { is_expected.to be_nil }
end
2021-06-08 01:23:25 +05:30
describe 'when the user does not have access' do
2021-08-04 16:29:09 +05:30
let(:current_user) { nil }
2021-06-08 01:23:25 +05:30
specify { is_expected.to be_nil }
end
end
describe 'Value Stream' do
let(:item_id) { :cycle_analytics }
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
2021-08-04 16:29:09 +05:30
let(:current_user) { nil }
2021-06-08 01:23:25 +05:30
specify { is_expected.to be_nil }
end
end
end
end