Commit cd711f52 authored by Marc Shaw's avatar Marc Shaw

Merge branch '352721-add-feature-flag-for-the-cluster-creation-page' into 'master'

Add new page for the cluster creation

See merge request gitlab-org/gitlab!83041
parents 1aaf3138 e9c288ca
<script> <script>
import { import { GlDropdown, GlDropdownItem, GlModalDirective, GlTooltip } from '@gitlab/ui';
GlButton,
GlDropdown,
GlDropdownItem,
GlModalDirective,
GlTooltipDirective,
GlDropdownDivider,
GlDropdownSectionHeader,
} from '@gitlab/ui';
import { INSTALL_AGENT_MODAL_ID, CLUSTERS_ACTIONS } from '../constants'; import { INSTALL_AGENT_MODAL_ID, CLUSTERS_ACTIONS } from '../constants';
...@@ -15,37 +7,40 @@ export default { ...@@ -15,37 +7,40 @@ export default {
i18n: CLUSTERS_ACTIONS, i18n: CLUSTERS_ACTIONS,
INSTALL_AGENT_MODAL_ID, INSTALL_AGENT_MODAL_ID,
components: { components: {
GlButton,
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlDropdownDivider, GlTooltip,
GlDropdownSectionHeader,
}, },
directives: { directives: {
GlModalDirective, GlModalDirective,
GlTooltip: GlTooltipDirective,
}, },
inject: [ inject: [
'newClusterPath', 'newClusterPath',
'addClusterPath', 'addClusterPath',
'newClusterDocsPath',
'canAddCluster', 'canAddCluster',
'displayClusterAgents', 'displayClusterAgents',
'certificateBasedClustersEnabled', 'certificateBasedClustersEnabled',
], ],
computed: { computed: {
tooltip() { shouldTriggerModal() {
const { connectWithAgent, connectExistingCluster, dropdownDisabledHint } = this.$options.i18n; return this.canAddCluster && this.displayClusterAgents;
},
defaultActionText() {
const { connectCluster, connectWithAgent, connectClusterDeprecated } = this.$options.i18n;
if (!this.canAddCluster) { if (!this.displayClusterAgents) {
return dropdownDisabledHint; return connectClusterDeprecated;
} else if (this.displayClusterAgents) { } else if (!this.certificateBasedClustersEnabled) {
return connectWithAgent; return connectCluster;
} }
return connectWithAgent;
return connectExistingCluster;
}, },
shouldTriggerModal() { defaultActionUrl() {
return this.canAddCluster && this.displayClusterAgents; if (this.displayClusterAgents) {
return null;
}
return this.addClusterPath;
}, },
}, },
}; };
...@@ -53,46 +48,50 @@ export default { ...@@ -53,46 +48,50 @@ export default {
<template> <template>
<div class="nav-controls gl-ml-auto"> <div class="nav-controls gl-ml-auto">
<gl-tooltip
v-if="!canAddCluster"
:target="() => $refs.dropdown.$el"
:title="$options.i18n.dropdownDisabledHint"
/>
<gl-dropdown <gl-dropdown
v-if="certificateBasedClustersEnabled"
ref="dropdown" ref="dropdown"
v-gl-modal-directive="shouldTriggerModal && $options.INSTALL_AGENT_MODAL_ID" v-gl-modal-directive="shouldTriggerModal && $options.INSTALL_AGENT_MODAL_ID"
v-gl-tooltip="tooltip"
category="primary" category="primary"
variant="confirm" variant="confirm"
:text="$options.i18n.actionsButton" :text="defaultActionText"
:disabled="!canAddCluster" :disabled="!canAddCluster"
:split="displayClusterAgents" :split-href="defaultActionUrl"
split
right right
> >
<template v-if="displayClusterAgents">
<gl-dropdown-section-header>{{ $options.i18n.agent }}</gl-dropdown-section-header>
<gl-dropdown-item <gl-dropdown-item
v-gl-modal-directive="$options.INSTALL_AGENT_MODAL_ID" v-if="displayClusterAgents"
data-testid="connect-new-agent-link" :href="newClusterDocsPath"
data-testid="create-cluster-link"
@click.stop
> >
{{ $options.i18n.connectWithAgent }} {{ $options.i18n.createCluster }}
</gl-dropdown-item> </gl-dropdown-item>
<gl-dropdown-divider />
<gl-dropdown-section-header>{{ $options.i18n.certificate }}</gl-dropdown-section-header>
</template>
<template v-if="displayClusterAgents && certificateBasedClustersEnabled">
<gl-dropdown-item :href="newClusterPath" data-testid="new-cluster-link" @click.stop> <gl-dropdown-item :href="newClusterPath" data-testid="new-cluster-link" @click.stop>
{{ $options.i18n.createNewCluster }} {{ $options.i18n.createClusterCertificate }}
</gl-dropdown-item> </gl-dropdown-item>
<gl-dropdown-item :href="addClusterPath" data-testid="connect-cluster-link" @click.stop> <gl-dropdown-item :href="addClusterPath" data-testid="connect-cluster-link" @click.stop>
{{ $options.i18n.connectExistingCluster }} {{ $options.i18n.connectClusterCertificate }}
</gl-dropdown-item> </gl-dropdown-item>
</gl-dropdown> </template>
<gl-button
v-else <gl-dropdown-item
v-gl-modal-directive="$options.INSTALL_AGENT_MODAL_ID" v-if="certificateBasedClustersEnabled && !displayClusterAgents"
v-gl-tooltip="tooltip" :href="newClusterPath"
:disabled="!canAddCluster" data-testid="new-cluster-link"
category="primary" @click.stop
variant="confirm"
> >
{{ $options.i18n.connectWithAgent }} {{ $options.i18n.createClusterDeprecated }}
</gl-button> </gl-dropdown-item>
</gl-dropdown>
</div> </div>
</template> </template>
...@@ -252,12 +252,13 @@ export const CERTIFICATE_TAB = { ...@@ -252,12 +252,13 @@ export const CERTIFICATE_TAB = {
export const CLUSTERS_TABS = [ALL_TAB, AGENT_TAB, CERTIFICATE_TAB]; export const CLUSTERS_TABS = [ALL_TAB, AGENT_TAB, CERTIFICATE_TAB];
export const CLUSTERS_ACTIONS = { export const CLUSTERS_ACTIONS = {
actionsButton: s__('ClusterAgents|Actions'), connectCluster: s__('ClusterAgents|Connect a cluster'),
createNewCluster: s__('ClusterAgents|Create a new cluster'), connectWithAgent: s__('ClusterAgents|Connect a cluster (agent)'),
connectWithAgent: s__('ClusterAgents|Connect with an agent'), connectClusterDeprecated: s__('ClusterAgents|Connect a cluster (deprecated)'),
connectExistingCluster: s__('ClusterAgents|Connect with a certificate'), createClusterDeprecated: s__('ClusterAgents|Create a cluster (deprecated)'),
agent: s__('ClusterAgents|Agent'), createCluster: s__('ClusterAgents|Create a cluster'),
certificate: s__('ClusterAgents|Certificate'), createClusterCertificate: s__('ClusterAgents|Create a cluster (certificate - deprecated)'),
connectClusterCertificate: s__('ClusterAgents|Connect a cluster (certificate - deprecated)'),
dropdownDisabledHint: s__( dropdownDisabledHint: s__(
'ClusterAgents|Requires a Maintainer or greater role to perform these actions', 'ClusterAgents|Requires a Maintainer or greater role to perform these actions',
), ),
......
...@@ -25,6 +25,7 @@ export default () => { ...@@ -25,6 +25,7 @@ export default () => {
kasAddress, kasAddress,
newClusterPath, newClusterPath,
addClusterPath, addClusterPath,
newClusterDocsPath,
emptyStateHelpText, emptyStateHelpText,
clustersEmptyStateImage, clustersEmptyStateImage,
canAddCluster, canAddCluster,
...@@ -43,6 +44,7 @@ export default () => { ...@@ -43,6 +44,7 @@ export default () => {
kasAddress, kasAddress,
newClusterPath, newClusterPath,
addClusterPath, addClusterPath,
newClusterDocsPath,
emptyStateHelpText, emptyStateHelpText,
clustersEmptyStateImage, clustersEmptyStateImage,
canAddCluster: parseBoolean(canAddCluster), canAddCluster: parseBoolean(canAddCluster),
......
...@@ -14,7 +14,7 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -14,7 +14,7 @@ class Clusters::ClustersController < Clusters::BaseController
before_action :authorize_create_cluster!, only: [:new, :connect, :authorize_aws_role] before_action :authorize_create_cluster!, only: [:new, :connect, :authorize_aws_role]
before_action :authorize_update_cluster!, only: [:update] before_action :authorize_update_cluster!, only: [:update]
before_action :update_applications_status, only: [:cluster_status] before_action :update_applications_status, only: [:cluster_status]
before_action :ensure_feature_enabled!, except: :index before_action :ensure_feature_enabled!, except: [:index, :new_cluster_docs]
helper_method :token_in_session helper_method :token_in_session
......
...@@ -19,6 +19,7 @@ module ClustersHelper ...@@ -19,6 +19,7 @@ module ClustersHelper
empty_state_help_text: clusterable.empty_state_help_text, empty_state_help_text: clusterable.empty_state_help_text,
new_cluster_path: clusterable.new_path, new_cluster_path: clusterable.new_path,
add_cluster_path: clusterable.connect_path, add_cluster_path: clusterable.connect_path,
new_cluster_docs_path: clusterable.new_cluster_docs_path,
can_add_cluster: clusterable.can_add_cluster?.to_s, can_add_cluster: clusterable.can_add_cluster?.to_s,
can_admin_cluster: clusterable.can_admin_cluster?.to_s, can_admin_cluster: clusterable.can_admin_cluster?.to_s,
display_cluster_agents: display_cluster_agents?(clusterable).to_s, display_cluster_agents: display_cluster_agents?(clusterable).to_s,
......
...@@ -36,6 +36,10 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated ...@@ -36,6 +36,10 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated
polymorphic_path([clusterable, :clusters], action: :connect) polymorphic_path([clusterable, :clusters], action: :connect)
end end
def new_cluster_docs_path
polymorphic_path([clusterable, :clusters], action: :new_cluster_docs)
end
def authorize_aws_role_path def authorize_aws_role_path
polymorphic_path([clusterable, :clusters], action: :authorize_aws_role) polymorphic_path([clusterable, :clusters], action: :authorize_aws_role)
end end
......
...@@ -43,6 +43,11 @@ class InstanceClusterablePresenter < ClusterablePresenter ...@@ -43,6 +43,11 @@ class InstanceClusterablePresenter < ClusterablePresenter
connect_admin_clusters_path connect_admin_clusters_path
end end
override :new_cluster_docs_path
def new_cluster_docs_path
nil
end
override :create_user_clusters_path override :create_user_clusters_path
def create_user_clusters_path def create_user_clusters_path
create_user_admin_clusters_path create_user_admin_clusters_path
......
- is_connect_page = local_assigns.fetch(:is_connect_page, false)
- docs_mode = local_assigns.fetch(:docs_mode, false)
- title = is_connect_page ? s_('ClusterIntegration|Connect a Kubernetes cluster') : s_('ClusterIntegration|Create a Kubernetes cluster')
%h3 %h3
= s_('ClusterIntegration|Connect a Kubernetes cluster') = title
%p %p
= clusterable.sidebar_text = clusterable.sidebar_text
%p
- if !docs_mode
%p
= clusterable.learn_more_link = clusterable.learn_more_link
= render 'clusters/clusters/multiple_clusters_message' = render 'clusters/clusters/multiple_clusters_message'
- provider = local_assigns.fetch(:provider) - provider = local_assigns.fetch(:provider)
- is_current_provider = provider == params[:provider] - is_current_provider = provider == params[:provider]
- logo_path = local_assigns.fetch(:logo_path) - logo_path = local_assigns.fetch(:logo_path)
- help_path = local_assigns.fetch(:help_path)
- label = local_assigns.fetch(:label) - label = local_assigns.fetch(:label)
- last = local_assigns.fetch(:last, false) - last = local_assigns.fetch(:last, false)
- classes = ["btn btn-confirm gl-button btn-confirm-secondary gl-flex-direction-column gl-w-half js-create-#{provider}-cluster-button"] - docs_mode = local_assigns.fetch(:docs_mode, false)
- conditional_classes = [('gl-mr-5' unless last), ('active' if is_current_provider)] - classes = ["btn btn-confirm gl-button btn-confirm-secondary gl-flex-direction-column gl-w-half"]
- conditional_classes = [("gl-mr-5" unless last), ("active" if is_current_provider && !docs_mode), ("js-create-#{provider}-cluster-button" if !docs_mode)]
- link = docs_mode ? help_path : clusterable.new_path(provider: provider)
= link_to clusterable.new_path(provider: provider), class: classes + conditional_classes do = link_to link, class: classes + conditional_classes do
.svg-content.gl-p-3= image_tag logo_path, alt: label, class: 'gl-w-64 gl-h-64' .svg-content.gl-p-3= image_tag logo_path, alt: label, class: "gl-w-64 gl-h-64"
%span %span
= label = label
- gke_label = s_('ClusterIntegration|Google GKE') - gke_label = s_('ClusterIntegration|Google GKE')
- eks_label = s_('ClusterIntegration|Amazon EKS') - eks_label = s_('ClusterIntegration|Amazon EKS')
- create_cluster_label = s_('ClusterIntegration|Where do you want to create a cluster?') - create_cluster_label = s_('ClusterIntegration|Where do you want to create a cluster?')
- eks_help_path = help_page_path('user/infrastructure/clusters/connect/new_eks_cluster')
- gke_help_path = help_page_path('user/infrastructure/clusters/connect/new_gke_cluster')
- docs_mode = local_assigns.fetch(:docs_mode, false)
.gl-p-5 .gl-p-5
%h4.gl-mb-5 %h4.gl-mb-5
= create_cluster_label = create_cluster_label
.gl-display-flex .gl-display-flex
= render partial: 'clusters/clusters/cloud_providers/cloud_provider_button', = render partial: 'clusters/clusters/cloud_providers/cloud_provider_button',
locals: { provider: 'aws', label: eks_label, logo_path: 'illustrations/logos/amazon_eks.svg' } locals: { provider: 'aws', label: eks_label, logo_path: 'illustrations/logos/amazon_eks.svg', help_path: eks_help_path, docs_mode: docs_mode }
= render partial: 'clusters/clusters/cloud_providers/cloud_provider_button', = render partial: 'clusters/clusters/cloud_providers/cloud_provider_button',
locals: { provider: 'gcp', label: gke_label, logo_path: 'illustrations/logos/google_gke.svg', last: true } locals: { provider: 'gcp', label: gke_label, logo_path: 'illustrations/logos/google_gke.svg', help_path: gke_help_path, docs_mode: docs_mode, last: true }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
- breadcrumb_title _('Connect a cluster') - breadcrumb_title _('Connect a cluster')
- page_title _('Connect a Kubernetes Cluster') - page_title _('Connect a Kubernetes Cluster')
.row.gl-mt-3 .gl-md-display-flex.gl-mt-3
.col-md-3 .gl-w-quarter.gl-xs-w-full.gl-flex-shrink-0.gl-md-mr-5
= render 'sidebar' = render 'sidebar', is_connect_page: true
.col-md-9 .gl-w-full
#js-cluster-new{ data: js_cluster_new } #js-cluster-new{ data: js_cluster_new }
= render 'clusters/clusters/user/form' = render 'clusters/clusters/user/form'
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
= render_gcp_signup_offer = render_gcp_signup_offer
.row.gl-mt-3 .gl-md-display-flex.gl-mt-3
.col-md-3 .gl-w-quarter.gl-xs-w-full.gl-flex-shrink-0.gl-md-mr-5
= render 'sidebar' = render 'sidebar', is_connect_page: false
.col-md-9 .gl-w-full
= render 'clusters/clusters/cloud_providers/cloud_provider_selector' = render 'clusters/clusters/cloud_providers/cloud_provider_selector'
- if ['aws', 'gcp'].include?(provider) - if ['aws', 'gcp'].include?(provider)
......
- @content_class = 'limit-container-width' unless fluid_layout
- add_to_breadcrumbs _('Kubernetes Clusters'), clusterable.index_path
- breadcrumb_title _('Create a cluster')
- page_title _('Create a Kubernetes cluster')
- docs_mode = true
= render_gcp_signup_offer
.gl-md-display-flex.gl-mt-3
.gl-w-quarter.gl-xs-w-full.gl-flex-shrink-0.gl-md-mr-5
= render 'sidebar', docs_mode: docs_mode, is_connect_page: false
.gl-w-full
= render 'clusters/clusters/cloud_providers/cloud_provider_selector', docs_mode: docs_mode
...@@ -237,6 +237,7 @@ Rails.application.routes.draw do ...@@ -237,6 +237,7 @@ Rails.application.routes.draw do
resources :clusters, only: [:index, :new, :show, :update, :destroy] do resources :clusters, only: [:index, :new, :show, :update, :destroy] do
collection do collection do
get :connect get :connect
get :new_cluster_docs
post :create_user post :create_user
post :create_gcp post :create_gcp
post :create_aws post :create_aws
......
...@@ -7822,9 +7822,6 @@ msgstr "" ...@@ -7822,9 +7822,6 @@ msgstr ""
msgid "ClusterAgents|Access tokens" msgid "ClusterAgents|Access tokens"
msgstr "" msgstr ""
msgid "ClusterAgents|Actions"
msgstr ""
msgid "ClusterAgents|Add an agent configuration file to %{linkStart}this repository%{linkEnd} and select it, or create a new one to register with GitLab:" msgid "ClusterAgents|Add an agent configuration file to %{linkStart}this repository%{linkEnd} and select it, or create a new one to register with GitLab:"
msgstr "" msgstr ""
...@@ -7879,16 +7876,22 @@ msgstr "" ...@@ -7879,16 +7876,22 @@ msgstr ""
msgid "ClusterAgents|Configuration" msgid "ClusterAgents|Configuration"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect a cluster through an agent" msgid "ClusterAgents|Connect a cluster"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect existing cluster" msgid "ClusterAgents|Connect a cluster (agent)"
msgstr ""
msgid "ClusterAgents|Connect a cluster (certificate - deprecated)"
msgstr ""
msgid "ClusterAgents|Connect a cluster (deprecated)"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect with a certificate" msgid "ClusterAgents|Connect a cluster through an agent"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect with an agent" msgid "ClusterAgents|Connect existing cluster"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect with the GitLab Agent" msgid "ClusterAgents|Connect with the GitLab Agent"
...@@ -7906,7 +7909,13 @@ msgstr "" ...@@ -7906,7 +7909,13 @@ msgstr ""
msgid "ClusterAgents|Copy token" msgid "ClusterAgents|Copy token"
msgstr "" msgstr ""
msgid "ClusterAgents|Create a new cluster" msgid "ClusterAgents|Create a cluster"
msgstr ""
msgid "ClusterAgents|Create a cluster (certificate - deprecated)"
msgstr ""
msgid "ClusterAgents|Create a cluster (deprecated)"
msgstr "" msgstr ""
msgid "ClusterAgents|Create agent access token" msgid "ClusterAgents|Create agent access token"
...@@ -8289,6 +8298,9 @@ msgstr "" ...@@ -8289,6 +8298,9 @@ msgstr ""
msgid "ClusterIntegration|Create Kubernetes cluster" msgid "ClusterIntegration|Create Kubernetes cluster"
msgstr "" msgstr ""
msgid "ClusterIntegration|Create a Kubernetes cluster"
msgstr ""
msgid "ClusterIntegration|Creating Kubernetes cluster" msgid "ClusterIntegration|Creating Kubernetes cluster"
msgstr "" msgstr ""
......
...@@ -15,8 +15,8 @@ RSpec.describe 'Instance-level AWS EKS Cluster', :js do ...@@ -15,8 +15,8 @@ RSpec.describe 'Instance-level AWS EKS Cluster', :js do
before do before do
visit admin_clusters_path visit admin_clusters_path
click_button 'Actions' click_button(class: 'dropdown-toggle-split')
click_link 'Create a new cluster' click_link 'Create a cluster (deprecated)'
end end
context 'when user creates a cluster on AWS EKS' do context 'when user creates a cluster on AWS EKS' do
......
...@@ -25,7 +25,7 @@ RSpec.describe 'Cluster agent registration', :js do ...@@ -25,7 +25,7 @@ RSpec.describe 'Cluster agent registration', :js do
end end
it 'allows the user to select an agent to install, and displays the resulting agent token' do it 'allows the user to select an agent to install, and displays the resulting agent token' do
click_button('Actions') click_button('Connect a cluster')
expect(page).to have_content('Register') expect(page).to have_content('Register')
click_button('Select an agent') click_button('Select an agent')
......
...@@ -20,8 +20,8 @@ RSpec.describe 'Group AWS EKS Cluster', :js do ...@@ -20,8 +20,8 @@ RSpec.describe 'Group AWS EKS Cluster', :js do
before do before do
visit group_clusters_path(group) visit group_clusters_path(group)
click_button 'Actions' click_button(class: 'dropdown-toggle-split')
click_link 'Create a new cluster' click_link 'Create a cluster (deprecated)'
end end
context 'when user creates a cluster on AWS EKS' do context 'when user creates a cluster on AWS EKS' do
......
...@@ -20,7 +20,7 @@ RSpec.describe 'AWS EKS Cluster', :js do ...@@ -20,7 +20,7 @@ RSpec.describe 'AWS EKS Cluster', :js do
visit project_clusters_path(project) visit project_clusters_path(project)
click_button(class: 'dropdown-toggle-split') click_button(class: 'dropdown-toggle-split')
click_link 'Create a new cluster' click_link 'Create a cluster (certificate - deprecated)'
end end
context 'when user creates a cluster on AWS EKS' do context 'when user creates a cluster on AWS EKS' do
......
...@@ -135,7 +135,7 @@ RSpec.describe 'Gcp Cluster', :js do ...@@ -135,7 +135,7 @@ RSpec.describe 'Gcp Cluster', :js do
visit project_clusters_path(project) visit project_clusters_path(project)
click_button(class: 'dropdown-toggle-split') click_button(class: 'dropdown-toggle-split')
click_link 'Connect with a certificate' click_link 'Connect a cluster (certificate - deprecated)'
end end
it 'user sees the "Environment scope" field' do it 'user sees the "Environment scope" field' do
...@@ -220,6 +220,6 @@ RSpec.describe 'Gcp Cluster', :js do ...@@ -220,6 +220,6 @@ RSpec.describe 'Gcp Cluster', :js do
def visit_create_cluster_page def visit_create_cluster_page
click_button(class: 'dropdown-toggle-split') click_button(class: 'dropdown-toggle-split')
click_link 'Create a new cluster' click_link 'Create a cluster (certificate - deprecated)'
end end
end end
...@@ -222,11 +222,11 @@ RSpec.describe 'Clusters', :js do ...@@ -222,11 +222,11 @@ RSpec.describe 'Clusters', :js do
visit project_clusters_path(project) visit project_clusters_path(project)
click_button(class: 'dropdown-toggle-split') click_button(class: 'dropdown-toggle-split')
click_link 'Create a new cluster' click_link 'Create a cluster (certificate - deprecated)'
end end
def visit_connect_cluster_page def visit_connect_cluster_page
click_button(class: 'dropdown-toggle-split') click_button(class: 'dropdown-toggle-split')
click_link 'Connect with a certificate' click_link 'Connect a cluster (certificate - deprecated)'
end end
end end
import { GlDropdown, GlDropdownItem, GlButton } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlTooltip } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ClustersActions from '~/clusters_list/components/clusters_actions.vue'; import ClustersActions from '~/clusters_list/components/clusters_actions.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
...@@ -7,12 +7,14 @@ import { INSTALL_AGENT_MODAL_ID, CLUSTERS_ACTIONS } from '~/clusters_list/consta ...@@ -7,12 +7,14 @@ import { INSTALL_AGENT_MODAL_ID, CLUSTERS_ACTIONS } from '~/clusters_list/consta
describe('ClustersActionsComponent', () => { describe('ClustersActionsComponent', () => {
let wrapper; let wrapper;
const newClusterPath = 'path/to/create/cluster'; const newClusterPath = 'path/to/add/cluster';
const addClusterPath = 'path/to/connect/existing/cluster'; const addClusterPath = 'path/to/connect/existing/cluster';
const newClusterDocsPath = 'path/to/create/new/cluster';
const defaultProvide = { const defaultProvide = {
newClusterPath, newClusterPath,
addClusterPath, addClusterPath,
newClusterDocsPath,
canAddCluster: true, canAddCluster: true,
displayClusterAgents: true, displayClusterAgents: true,
certificateBasedClustersEnabled: true, certificateBasedClustersEnabled: true,
...@@ -20,12 +22,13 @@ describe('ClustersActionsComponent', () => { ...@@ -20,12 +22,13 @@ describe('ClustersActionsComponent', () => {
const findDropdown = () => wrapper.findComponent(GlDropdown); const findDropdown = () => wrapper.findComponent(GlDropdown);
const findDropdownItems = () => wrapper.findAllComponents(GlDropdownItem); const findDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
const findTooltip = () => wrapper.findComponent(GlTooltip);
const findDropdownItemIds = () => const findDropdownItemIds = () =>
findDropdownItems().wrappers.map((x) => x.attributes('data-testid')); findDropdownItems().wrappers.map((x) => x.attributes('data-testid'));
const findDropdownItemTexts = () => findDropdownItems().wrappers.map((x) => x.text());
const findNewClusterLink = () => wrapper.findByTestId('new-cluster-link'); const findNewClusterLink = () => wrapper.findByTestId('new-cluster-link');
const findNewClusterDocsLink = () => wrapper.findByTestId('create-cluster-link');
const findConnectClusterLink = () => wrapper.findByTestId('connect-cluster-link'); const findConnectClusterLink = () => wrapper.findByTestId('connect-cluster-link');
const findConnectNewAgentLink = () => wrapper.findByTestId('connect-new-agent-link');
const findConnectWithAgentButton = () => wrapper.findComponent(GlButton);
const createWrapper = (provideData = {}) => { const createWrapper = (provideData = {}) => {
wrapper = shallowMountExtended(ClustersActions, { wrapper = shallowMountExtended(ClustersActions, {
...@@ -35,7 +38,6 @@ describe('ClustersActionsComponent', () => { ...@@ -35,7 +38,6 @@ describe('ClustersActionsComponent', () => {
}, },
directives: { directives: {
GlModalDirective: createMockDirective(), GlModalDirective: createMockDirective(),
GlTooltip: createMockDirective(),
}, },
}); });
}; };
...@@ -49,12 +51,15 @@ describe('ClustersActionsComponent', () => { ...@@ -49,12 +51,15 @@ describe('ClustersActionsComponent', () => {
}); });
describe('when the certificate based clusters are enabled', () => { describe('when the certificate based clusters are enabled', () => {
it('renders actions menu', () => { it('renders actions menu', () => {
expect(findDropdown().props('text')).toBe(CLUSTERS_ACTIONS.actionsButton); expect(findDropdown().exists()).toBe(true);
}); });
it('renders correct href attributes for the links', () => { it('shows split button in dropdown', () => {
expect(findNewClusterLink().attributes('href')).toBe(newClusterPath); expect(findDropdown().props('split')).toBe(true);
expect(findConnectClusterLink().attributes('href')).toBe(addClusterPath); });
it("doesn't show the tooltip", () => {
expect(findTooltip().exists()).toBe(false);
}); });
describe('when user cannot add clusters', () => { describe('when user cannot add clusters', () => {
...@@ -67,8 +72,7 @@ describe('ClustersActionsComponent', () => { ...@@ -67,8 +72,7 @@ describe('ClustersActionsComponent', () => {
}); });
it('shows tooltip explaining why dropdown is disabled', () => { it('shows tooltip explaining why dropdown is disabled', () => {
const tooltip = getBinding(findDropdown().element, 'gl-tooltip'); expect(findTooltip().attributes('title')).toBe(CLUSTERS_ACTIONS.dropdownDisabledHint);
expect(tooltip.value).toBe(CLUSTERS_ACTIONS.dropdownDisabledHint);
}); });
it('does not bind split dropdown button', () => { it('does not bind split dropdown button', () => {
...@@ -79,33 +83,36 @@ describe('ClustersActionsComponent', () => { ...@@ -79,33 +83,36 @@ describe('ClustersActionsComponent', () => {
}); });
describe('when on project level', () => { describe('when on project level', () => {
it('renders a dropdown with 3 actions items', () => { it(`displays default action as ${CLUSTERS_ACTIONS.connectWithAgent}`, () => {
expect(findDropdownItemIds()).toEqual([ expect(findDropdown().props('text')).toBe(CLUSTERS_ACTIONS.connectWithAgent);
'connect-new-agent-link',
'new-cluster-link',
'connect-cluster-link',
]);
}); });
it('renders correct modal id for the agent link', () => { it('renders correct modal id for the default action', () => {
const binding = getBinding(findConnectNewAgentLink().element, 'gl-modal-directive'); const binding = getBinding(findDropdown().element, 'gl-modal-directive');
expect(binding.value).toBe(INSTALL_AGENT_MODAL_ID); expect(binding.value).toBe(INSTALL_AGENT_MODAL_ID);
}); });
it('shows tooltip', () => { it('renders a dropdown with 3 actions items', () => {
const tooltip = getBinding(findDropdown().element, 'gl-tooltip'); expect(findDropdownItemIds()).toEqual([
expect(tooltip.value).toBe(CLUSTERS_ACTIONS.connectWithAgent); 'create-cluster-link',
'new-cluster-link',
'connect-cluster-link',
]);
}); });
it('shows split button in dropdown', () => { it('renders correct texts for the dropdown items', () => {
expect(findDropdown().props('split')).toBe(true); expect(findDropdownItemTexts()).toEqual([
CLUSTERS_ACTIONS.createCluster,
CLUSTERS_ACTIONS.createClusterCertificate,
CLUSTERS_ACTIONS.connectClusterCertificate,
]);
}); });
it('binds split button with modal id', () => { it('renders correct href attributes for the links', () => {
const binding = getBinding(findDropdown().element, 'gl-modal-directive'); expect(findNewClusterDocsLink().attributes('href')).toBe(newClusterDocsPath);
expect(findNewClusterLink().attributes('href')).toBe(newClusterPath);
expect(binding.value).toBe(INSTALL_AGENT_MODAL_ID); expect(findConnectClusterLink().attributes('href')).toBe(addClusterPath);
}); });
}); });
...@@ -114,17 +121,20 @@ describe('ClustersActionsComponent', () => { ...@@ -114,17 +121,20 @@ describe('ClustersActionsComponent', () => {
createWrapper({ displayClusterAgents: false }); createWrapper({ displayClusterAgents: false });
}); });
it('renders a dropdown with 2 actions items', () => { it(`displays default action as ${CLUSTERS_ACTIONS.connectClusterDeprecated}`, () => {
expect(findDropdownItemIds()).toEqual(['new-cluster-link', 'connect-cluster-link']); expect(findDropdown().props('text')).toBe(CLUSTERS_ACTIONS.connectClusterDeprecated);
}); });
it('shows tooltip', () => { it('renders a dropdown with 1 action item', () => {
const tooltip = getBinding(findDropdown().element, 'gl-tooltip'); expect(findDropdownItemIds()).toEqual(['new-cluster-link']);
expect(tooltip.value).toBe(CLUSTERS_ACTIONS.connectExistingCluster);
}); });
it('does not show split button in dropdown', () => { it('renders correct text for the dropdown item', () => {
expect(findDropdown().props('split')).toBe(false); expect(findDropdownItemTexts()).toEqual([CLUSTERS_ACTIONS.createClusterDeprecated]);
});
it('renders correct href attributes for the links', () => {
expect(findNewClusterLink().attributes('href')).toBe(newClusterPath);
}); });
it('does not bind dropdown button to modal', () => { it('does not bind dropdown button to modal', () => {
...@@ -140,17 +150,26 @@ describe('ClustersActionsComponent', () => { ...@@ -140,17 +150,26 @@ describe('ClustersActionsComponent', () => {
createWrapper({ certificateBasedClustersEnabled: false }); createWrapper({ certificateBasedClustersEnabled: false });
}); });
it('it does not show the the dropdown', () => { it(`displays default action as ${CLUSTERS_ACTIONS.connectCluster}`, () => {
expect(findDropdown().exists()).toBe(false); expect(findDropdown().props('text')).toBe(CLUSTERS_ACTIONS.connectCluster);
});
it('renders correct modal id for the default action', () => {
const binding = getBinding(findDropdown().element, 'gl-modal-directive');
expect(binding.value).toBe(INSTALL_AGENT_MODAL_ID);
});
it('renders a dropdown with 1 action item', () => {
expect(findDropdownItemIds()).toEqual(['create-cluster-link']);
}); });
it('shows the connect with agent button', () => { it('renders correct text for the dropdown item', () => {
expect(findConnectWithAgentButton().props()).toMatchObject({ expect(findDropdownItemTexts()).toEqual([CLUSTERS_ACTIONS.createCluster]);
disabled: !defaultProvide.canAddCluster,
category: 'primary',
variant: 'confirm',
}); });
expect(findConnectWithAgentButton().text()).toBe(CLUSTERS_ACTIONS.connectWithAgent);
it('renders correct href attributes for the links', () => {
expect(findNewClusterDocsLink().attributes('href')).toBe(newClusterDocsPath);
}); });
}); });
}); });
...@@ -74,6 +74,10 @@ RSpec.describe ClustersHelper do ...@@ -74,6 +74,10 @@ RSpec.describe ClustersHelper do
expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/connect") expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/connect")
end end
it 'displays create cluster path' do
expect(subject[:new_cluster_docs_path]).to eq("#{project_path(project)}/-/clusters/new_cluster_docs")
end
it 'displays project default branch' do it 'displays project default branch' do
expect(subject[:default_branch_name]).to eq(project.default_branch) expect(subject[:default_branch_name]).to eq(project.default_branch)
end end
......
...@@ -49,6 +49,12 @@ RSpec.describe ProjectClusterablePresenter do ...@@ -49,6 +49,12 @@ RSpec.describe ProjectClusterablePresenter do
it { is_expected.to eq(connect_project_clusters_path(project)) } it { is_expected.to eq(connect_project_clusters_path(project)) }
end end
describe '#new_cluster_docs_path' do
subject { presenter.new_cluster_docs_path }
it { is_expected.to eq(new_cluster_docs_project_clusters_path(project)) }
end
describe '#authorize_aws_role_path' do describe '#authorize_aws_role_path' do
subject { presenter.authorize_aws_role_path } subject { presenter.authorize_aws_role_path }
......
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