Commit 9dc67bf1 authored by Thong Kuah's avatar Thong Kuah

Move group path display logic to helper

Add specs
parent 887bbd8e
......@@ -6,6 +6,28 @@ module ClustersHelper
false
end
# We do not want to show the group path for clusters belonging to the
# clusterable, only for the ancestor clusters.
def cluster_group_path_display(cluster, clusterable)
if cluster.group_type? && cluster.group.id != clusterable.id
group_path_shortened(cluster.group)
end
end
def group_path_shortened(group)
components = group.full_path_components
breadcrumb = if components.size > 2
[components.first, '…'.html_safe, components.last]
else
components
end
breadcrumb.each_with_object(''.html_safe) do |component, string|
string.concat(component + ' / ')
end
end
def render_gcp_signup_offer
return if Gitlab::CurrentSettings.current_application_settings.hide_third_party_offers?
return unless show_gcp_signup_offer?
......
......@@ -3,12 +3,7 @@
.table-section.section-60
.table-mobile-header{ role: "rowheader" }= s_("ClusterIntegration|Kubernetes cluster")
.table-mobile-content
- if cluster.group_type? && cluster.group.id != clusterable.id
- if cluster.group.ancestors.any?
= "#{cluster.group.ancestors.first.name} /"
- if cluster.group.ancestors.length > 1
= "… /".html_safe
= "#{cluster.group.name} /"
= cluster_group_path_display(cluster, clusterable)
= link_to cluster.name, cluster.show_path
- unless cluster.enabled?
%span.badge.badge-danger Connection disabled
......
# frozen_string_literal: true
require 'spec_helper'
describe ClustersHelper do
describe '#cluster_group_path_display' do
let(:group) { create(:group, name: 'group') }
let(:cluster) { create(:cluster, cluster_type: :group_type, groups: [group]) }
let(:clusterable) { group }
subject { helper.cluster_group_path_display(cluster, clusterable) }
it 'returns nothing' do
is_expected.to be_nil
end
context 'for another clusterable' do
let(:clusterable) { create(:group) }
it 'returns the group path' do
is_expected.to eq('group / ')
end
end
context 'for a project cluster' do
let(:cluster) { create(:cluster, :project) }
let(:clusterable) { cluster.project }
it 'returns nothing' do
is_expected.to be_nil
end
end
end
describe '#group_path_shortened' do
let(:group) { create(:group, name: 'group') }
subject { helper.group_path_shortened(group) }
it 'returns the group name with trailing slash' do
is_expected.to eq('group / ')
end
it 'escapes group name' do
expect(CGI).to receive(:escapeHTML).with('group / ').and_call_original
subject
end
context 'subgroup', :nested_groups do
let(:root_group) { create(:group, name: 'root') }
let(:group) { create(:group, name: 'group', parent: root_group) }
it 'returns the full path with trailing slash' do
is_expected.to eq('root / group / ')
end
it 'escapes group names' do
expect(CGI).to receive(:escapeHTML).with('root / ').and_call_original
expect(CGI).to receive(:escapeHTML).with('group / ').and_call_original
subject
end
context 'deeper nested' do
let(:next_group) { create(:group, name: 'next', parent: root_group) }
let(:group) { create(:group, name: 'group', parent: next_group) }
it 'returns a shorted path with trailing slash' do
is_expected.to eq('root / … / group / ')
end
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