2021-06-08 01:23:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Sidebars::Projects::Menus::SettingsMenu do
|
2021-09-04 01:27:46 +05:30
|
|
|
let_it_be(:project) { create(: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) }
|
|
|
|
|
|
|
|
describe '#render?' do
|
|
|
|
it 'returns false when menu does not have any menu items' do
|
|
|
|
allow(subject).to receive(:has_renderable_items?).and_return(false)
|
|
|
|
|
|
|
|
expect(subject.render?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Menu items' do
|
|
|
|
subject { described_class.new(context).renderable_items.find { |e| e.item_id == item_id } }
|
|
|
|
|
|
|
|
shared_examples 'access rights checks' do
|
|
|
|
specify { is_expected.not_to be_nil }
|
|
|
|
|
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'General' do
|
|
|
|
let(:item_id) { :general }
|
|
|
|
|
|
|
|
it_behaves_like 'access rights checks'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Integrations' do
|
|
|
|
let(:item_id) { :integrations }
|
|
|
|
|
|
|
|
it_behaves_like 'access rights checks'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Webhooks' do
|
|
|
|
let(:item_id) { :webhooks }
|
|
|
|
|
|
|
|
it_behaves_like 'access rights checks'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Access Tokens' do
|
|
|
|
let(:item_id) { :access_tokens }
|
|
|
|
|
|
|
|
it_behaves_like 'access rights checks'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Repository' do
|
|
|
|
let(:item_id) { :repository }
|
|
|
|
|
|
|
|
it_behaves_like 'access rights checks'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'CI/CD' do
|
|
|
|
let(:item_id) { :ci_cd }
|
|
|
|
|
|
|
|
describe 'when project is archived' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:archived?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when project is not archived' do
|
|
|
|
specify { is_expected.not_to be_nil }
|
|
|
|
|
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Monitor' do
|
|
|
|
let(:item_id) { :monitor }
|
|
|
|
|
|
|
|
describe 'when project is archived' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:archived?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when project is not archived' do
|
|
|
|
specify { is_expected.not_to be_nil }
|
|
|
|
|
|
|
|
specify { expect(subject.title).to eq 'Monitor' }
|
|
|
|
|
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Pages' do
|
|
|
|
let(:item_id) { :pages }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:pages_available?).and_return(pages_enabled)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when pages are enabled' do
|
|
|
|
let(:pages_enabled) { true }
|
|
|
|
|
|
|
|
specify { is_expected.not_to be_nil }
|
|
|
|
|
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when pages are not enabled' do
|
|
|
|
let(:pages_enabled) { false }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'Merge requests' do
|
|
|
|
let(:item_id) { :merge_requests }
|
|
|
|
|
|
|
|
it_behaves_like 'access rights checks'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Packages and registries' do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:item_id) { :packages_and_registries }
|
2022-08-13 15:12:31 +05:30
|
|
|
let(:packages_enabled) { false }
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: container_enabled)
|
2022-08-13 15:12:31 +05:30
|
|
|
stub_config(packages: { enabled: packages_enabled })
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
describe 'when container registry setting is disabled' do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:container_enabled) { false }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
describe 'when container registry setting is enabled' do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:container_enabled) { true }
|
|
|
|
|
|
|
|
specify { is_expected.not_to be_nil }
|
|
|
|
|
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
describe 'when package registry setting is enabled' do
|
|
|
|
let(:container_enabled) { false }
|
|
|
|
let(:packages_enabled) { true }
|
|
|
|
|
|
|
|
specify { is_expected.not_to be_nil }
|
|
|
|
|
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
describe 'Usage Quotas' do
|
|
|
|
let(:item_id) { :usage_quotas }
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
specify { is_expected.not_to be_nil }
|
2021-11-11 11:23:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe 'when the user does not have access' do
|
|
|
|
let(:user) { nil }
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
specify { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|