diff options
Diffstat (limited to 'spec/helpers/clusters_helper_spec.rb')
-rw-r--r-- | spec/helpers/clusters_helper_spec.rb | 120 |
1 files changed, 91 insertions, 29 deletions
diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb index f1e19f17c72..51f111917d1 100644 --- a/spec/helpers/clusters_helper_spec.rb +++ b/spec/helpers/clusters_helper_spec.rb @@ -59,54 +59,96 @@ RSpec.describe ClustersHelper do end end - describe '#js_cluster_agents_list_data' do - let_it_be(:project) { build(:project, :repository) } + describe '#js_clusters_list_data' do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { build(:project) } + let_it_be(:clusterable) { ClusterablePresenter.fabricate(project, current_user: current_user) } - subject { helper.js_cluster_agents_list_data(project) } + subject { helper.js_clusters_list_data(clusterable) } - it 'displays project default branch' do - expect(subject[:default_branch_name]).to eq(project.default_branch) + it 'displays endpoint path' do + expect(subject[:endpoint]).to eq("#{project_path(project)}/-/clusters.json") end - it 'displays image path' do - expect(subject[:empty_state_image]).to match(%r(/illustrations/logos/clusters_empty|svg)) + it 'generates svg image data', :aggregate_failures do + expect(subject.dig(:img_tags, :aws, :path)).to match(%r(/illustrations/logos/amazon_eks|svg)) + expect(subject.dig(:img_tags, :default, :path)).to match(%r(/illustrations/logos/kubernetes|svg)) + expect(subject.dig(:img_tags, :gcp, :path)).to match(%r(/illustrations/logos/google_gke|svg)) + + expect(subject.dig(:img_tags, :aws, :text)).to eq('Amazon EKS') + expect(subject.dig(:img_tags, :default, :text)).to eq('Kubernetes Cluster') + expect(subject.dig(:img_tags, :gcp, :text)).to eq('Google GKE') end - it 'displays project path' do - expect(subject[:project_path]).to eq(project.full_path) + it 'displays and ancestor_help_path' do + expect(subject[:ancestor_help_path]).to eq(help_page_path('user/group/clusters/index', anchor: 'cluster-precedence')) end - it 'generates docs urls' do - expect(subject[:agent_docs_url]).to eq(help_page_path('user/clusters/agent/index')) - expect(subject[:install_docs_url]).to eq(help_page_path('administration/clusters/kas')) - expect(subject[:get_started_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'define-a-configuration-repository')) - expect(subject[:integration_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'get-started-with-gitops-and-the-gitlab-agent')) + it 'displays empty image path' do + expect(subject[:clusters_empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-clusters|svg)) end - it 'displays kas address' do - expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url) + it 'displays create cluster using certificate path' do + expect(subject[:new_cluster_path]).to eq("#{project_path(project)}/-/clusters/new?tab=create") + end + + context 'user has no permissions to create a cluster' do + it 'displays that user can\t add cluster' do + expect(subject[:can_add_cluster]).to eq("false") + end + end + + context 'user is a maintainer' do + before do + project.add_maintainer(current_user) + end + + it 'displays that the user can add cluster' do + expect(subject[:can_add_cluster]).to eq("true") + end + end + + context 'project cluster' do + it 'doesn\'t display empty state help text' do + expect(subject[:empty_state_help_text]).to be_nil + end + end + + context 'group cluster' do + let_it_be(:group) { create(:group) } + let_it_be(:clusterable) { ClusterablePresenter.fabricate(group, current_user: current_user) } + + it 'displays empty state help text' do + expect(subject[:empty_state_help_text]).to eq(s_('ClusterIntegration|Adding an integration to your group will share the cluster across all your projects.')) + end end end - describe '#js_clusters_list_data' do - subject { helper.js_clusters_list_data('/path') } + describe '#js_clusters_data' do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { build(:project) } + let_it_be(:clusterable) { ClusterablePresenter.fabricate(project, current_user: current_user) } - it 'displays endpoint path' do - expect(subject[:endpoint]).to eq('/path') + subject { helper.js_clusters_data(clusterable) } + + it 'displays project default branch' do + expect(subject[:default_branch_name]).to eq(project.default_branch) end - it 'generates svg image data', :aggregate_failures do - expect(subject.dig(:img_tags, :aws, :path)).to match(%r(/illustrations/logos/amazon_eks|svg)) - expect(subject.dig(:img_tags, :default, :path)).to match(%r(/illustrations/logos/kubernetes|svg)) - expect(subject.dig(:img_tags, :gcp, :path)).to match(%r(/illustrations/logos/google_gke|svg)) + it 'displays image path' do + expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg)) + end - expect(subject.dig(:img_tags, :aws, :text)).to eq('Amazon EKS') - expect(subject.dig(:img_tags, :default, :text)).to eq('Kubernetes Cluster') - expect(subject.dig(:img_tags, :gcp, :text)).to eq('Google GKE') + it 'displays project path' do + expect(subject[:project_path]).to eq(project.full_path) end - it 'displays and ancestor_help_path' do - expect(subject[:ancestor_help_path]).to eq(help_page_path('user/group/clusters/index', anchor: 'cluster-precedence')) + it 'displays add cluster using certificate path' do + expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/new?tab=add") + end + + it 'displays kas address' do + expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url) end end @@ -152,4 +194,24 @@ RSpec.describe ClustersHelper do end end end + + describe '#display_cluster_agents?' do + subject { helper.display_cluster_agents?(clusterable) } + + context 'when clusterable is a project' do + let(:clusterable) { build(:project) } + + it 'allows agents to display' do + expect(subject).to be_truthy + end + end + + context 'when clusterable is a group' do + let(:clusterable) { build(:group) } + + it 'does not allow agents to display' do + expect(subject).to be_falsey + end + end + end end |