Commit 1f55fa41 authored by charlie ablett's avatar charlie ablett

Merge branch...

Merge branch '354803-follow-up-from-add-clusters-actions-menu-to-group-and-admin-views' into 'master'

Clusters helper method refactoring

See merge request gitlab-org/gitlab!82637
parents 34531f83 0393f713
......@@ -15,24 +15,19 @@ module ClustersHelper
gcp: { path: image_path('illustrations/logos/google_gke.svg'), text: s_('ClusterIntegration|Google GKE') }
},
clusters_empty_state_image: image_path('illustrations/empty-state/empty-state-clusters.svg'),
empty_state_image: image_path('illustrations/empty-state/empty-state-agents.svg'),
empty_state_help_text: clusterable.empty_state_help_text,
new_cluster_path: clusterable.new_path,
add_cluster_path: clusterable.connect_path,
can_add_cluster: clusterable.can_add_cluster?.to_s,
can_admin_cluster: clusterable.can_admin_cluster?.to_s,
display_cluster_agents: display_cluster_agents?(clusterable).to_s,
certificate_based_clusters_enabled: Feature.enabled?(:certificate_based_clusters, clusterable, default_enabled: :yaml, type: :ops).to_s
}
end
def js_clusters_data(clusterable)
{
default_branch_name: clusterable.default_branch,
empty_state_image: image_path('illustrations/empty-state/empty-state-agents.svg'),
project_path: clusterable.full_path,
certificate_based_clusters_enabled: Feature.enabled?(:certificate_based_clusters, clusterable, default_enabled: :yaml, type: :ops).to_s,
default_branch_name: default_branch_name(clusterable),
project_path: clusterable_project_path(clusterable),
kas_address: Gitlab::Kas.external_url,
gitlab_version: Gitlab.version_info
}.merge(js_clusters_list_data(clusterable))
}
end
def js_cluster_form_data(cluster, can_edit)
......@@ -113,4 +108,14 @@ module ClustersHelper
def can_admin_cluster?(user, cluster)
can?(user, :admin_cluster, cluster)
end
private
def default_branch_name(clusterable)
clusterable.default_branch if clusterable.is_a?(Project)
end
def clusterable_project_path(clusterable)
clusterable.full_path if clusterable.is_a?(Project)
end
end
......@@ -4,9 +4,5 @@
= render_gcp_signup_offer
.clusters-container
- if display_cluster_agents?(clusterable)
.gl-my-6
.js-clusters-main-view{ data: js_clusters_data(clusterable) }
- else
.gl-my-6
.js-clusters-main-view{ data: js_clusters_list_data(clusterable) }
......@@ -38,6 +38,11 @@ RSpec.describe ClustersHelper do
subject { helper.js_clusters_list_data(clusterable) }
before do
helper.send(:default_branch_name, clusterable)
helper.send(:clusterable_project_path, clusterable)
end
it 'displays endpoint path' do
expect(subject[:endpoint]).to eq("#{project_path(project)}/-/clusters.json")
end
......@@ -58,6 +63,7 @@ RSpec.describe ClustersHelper do
it 'displays empty image path' do
expect(subject[:clusters_empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-clusters|svg))
expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg))
end
it 'displays create cluster using certificate path' do
......@@ -68,6 +74,22 @@ RSpec.describe ClustersHelper do
expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/connect")
end
it 'displays project default branch' do
expect(subject[:default_branch_name]).to eq(project.default_branch)
end
it 'displays project path' do
expect(subject[:project_path]).to eq(project.full_path)
end
it 'displays kas address' do
expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url)
end
it 'displays GitLab version' do
expect(subject[:gitlab_version]).to eq(Gitlab.version_info)
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")
......@@ -107,6 +129,14 @@ RSpec.describe ClustersHelper do
it 'displays display_cluster_agents as false' do
expect(subject[:display_cluster_agents]).to eq("false")
end
it 'does not include a default branch' do
expect(subject[:default_branch_name]).to be_nil
end
it 'does not include a project path' do
expect(subject[:project_path]).to be_nil
end
end
describe 'certificate based clusters enabled' do
......@@ -132,34 +162,6 @@ RSpec.describe ClustersHelper do
end
end
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) }
subject { helper.js_clusters_data(clusterable) }
it 'displays project default branch' do
expect(subject[:default_branch_name]).to eq(project.default_branch)
end
it 'displays image path' do
expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg))
end
it 'displays project path' do
expect(subject[:project_path]).to eq(project.full_path)
end
it 'displays kas address' do
expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url)
end
it 'displays GitLab version' do
expect(subject[:gitlab_version]).to eq(Gitlab.version_info)
end
end
describe '#js_cluster_new' do
subject { helper.js_cluster_new }
......@@ -222,4 +224,33 @@ RSpec.describe ClustersHelper do
end
end
end
describe '#default_branch_name' do
subject { default_branch_name(clusterable) }
context 'when clusterable is a project without a repository' do
let(:clusterable) { build(:project) }
it 'allows default branch name to display default name from settings' do
expect(subject).to eq(Gitlab::CurrentSettings.default_branch_name)
end
end
context 'when clusterable is a project with a repository' do
let(:clusterable) { build(:project, :repository) }
let(:repository) { clusterable.repository }
it 'allows default branch name to display repository root branch' do
expect(subject).to eq(repository.root_ref)
end
end
context 'when clusterable is a group' do
let(:clusterable) { build(:group) }
it 'does not allow default branch name to display' do
expect(subject).to be_nil
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment