Commit 5a46295c authored by anna_vovchenko's avatar anna_vovchenko Committed by Anna Vovchenko

Updated actions menu

Updated actions menu and corresponding tests
parent a2b2a69c
<script> <script>
import { import { GlDropdown, GlDropdownItem, GlModalDirective, GlTooltip } from '@gitlab/ui';
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';
...@@ -16,12 +9,10 @@ export default { ...@@ -16,12 +9,10 @@ export default {
components: { components: {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlDropdownDivider, GlTooltip,
GlDropdownSectionHeader,
}, },
directives: { directives: {
GlModalDirective, GlModalDirective,
GlTooltip: GlTooltipDirective,
}, },
inject: [ inject: [
'newClusterPath', 'newClusterPath',
...@@ -32,22 +23,24 @@ export default { ...@@ -32,22 +23,24 @@ export default {
'certificateBasedClustersEnabled', 'certificateBasedClustersEnabled',
], ],
computed: { computed: {
tooltip() {
const { connectWithAgent, connectExistingCluster, dropdownDisabledHint } = this.$options.i18n;
if (!this.canAddCluster) {
return dropdownDisabledHint;
} else if (this.displayClusterAgents) {
return connectWithAgent;
}
return connectExistingCluster;
},
shouldTriggerModal() { shouldTriggerModal() {
return this.canAddCluster && this.displayClusterAgents; return this.canAddCluster && this.displayClusterAgents;
}, },
hasSectionHeaders() { defaultActionText() {
return this.displayClusterAgents && this.certificateBasedClustersEnabled; const { connectCluster, connectWithAgent, connectClusterDeprecated } = this.$options.i18n;
if (!this.displayClusterAgents) {
return connectClusterDeprecated;
} else if (!this.certificateBasedClustersEnabled) {
return connectCluster;
}
return connectWithAgent;
},
defaultActionUrl() {
if (this.displayClusterAgents) {
return null;
}
return this.addClusterPath;
}, },
}, },
}; };
...@@ -55,47 +48,50 @@ export default { ...@@ -55,47 +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
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
> >
<gl-dropdown-section-header v-if="hasSectionHeaders">{{
$options.i18n.agent
}}</gl-dropdown-section-header>
<template v-if="displayClusterAgents">
<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-item :href="newClusterDocsPath" data-testid="create-cluster-link" @click.stop>
{{ $options.i18n.createAndConnectCluster }}
</gl-dropdown-item>
</template>
<template v-if="hasSectionHeaders"> <template v-if="displayClusterAgents && certificateBasedClustersEnabled">
<gl-dropdown-divider />
<gl-dropdown-section-header>{{ $options.i18n.certificate }}</gl-dropdown-section-header>
</template>
<template v-if="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>
</template> </template>
<gl-dropdown-item
v-if="certificateBasedClustersEnabled && !displayClusterAgents"
:href="newClusterPath"
data-testid="new-cluster-link"
@click.stop
>
{{ $options.i18n.createClusterDeprecated }}
</gl-dropdown-item>
</gl-dropdown> </gl-dropdown>
</div> </div>
</template> </template>
...@@ -252,13 +252,13 @@ export const CERTIFICATE_TAB = { ...@@ -252,13 +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)'),
createAndConnectCluster: s__('ClusterAgents|Create and connect new cluster'), connectClusterDeprecated: s__('ClusterAgents|Connect a cluster (deprecated)'),
connectWithAgent: s__('ClusterAgents|Connect with an agent'), createClusterDeprecated: s__('ClusterAgents|Create a cluster (deprecated)'),
connectExistingCluster: s__('ClusterAgents|Connect with a certificate'), createCluster: s__('ClusterAgents|Create a cluster'),
agent: s__('ClusterAgents|Agent'), createClusterCertificate: s__('ClusterAgents|Create a cluster (certificate) (deprecated)'),
certificate: s__('ClusterAgents|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',
), ),
......
...@@ -7819,9 +7819,6 @@ msgstr "" ...@@ -7819,9 +7819,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 ""
...@@ -7873,22 +7870,25 @@ msgstr "" ...@@ -7873,22 +7870,25 @@ msgstr ""
msgid "ClusterAgents|Certificate" msgid "ClusterAgents|Certificate"
msgstr "" msgstr ""
msgid "ClusterAgents|Certificate (deprecated)" msgid "ClusterAgents|Configuration"
msgstr "" msgstr ""
msgid "ClusterAgents|Configuration" msgid "ClusterAgents|Connect a cluster"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect a cluster through an agent" msgid "ClusterAgents|Connect a cluster (agent)"
msgstr "" msgstr ""
msgid "ClusterAgents|Connect existing cluster" 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,16 +7906,19 @@ msgstr "" ...@@ -7906,16 +7906,19 @@ msgstr ""
msgid "ClusterAgents|Copy token" msgid "ClusterAgents|Copy token"
msgstr "" msgstr ""
msgid "ClusterAgents|Create a new cluster" msgid "ClusterAgents|Create a cluster"
msgstr "" msgstr ""
msgid "ClusterAgents|Create agent access token" msgid "ClusterAgents|Create a cluster (certificate) (deprecated)"
msgstr "" msgstr ""
msgid "ClusterAgents|Create agent: %{searchTerm}" msgid "ClusterAgents|Create a cluster (deprecated)"
msgstr "" msgstr ""
msgid "ClusterAgents|Create and connect new cluster" msgid "ClusterAgents|Create agent access token"
msgstr ""
msgid "ClusterAgents|Create agent: %{searchTerm}"
msgstr "" msgstr ""
msgid "ClusterAgents|Create token" msgid "ClusterAgents|Create token"
......
...@@ -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, GlDropdownSectionHeader } 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';
...@@ -22,13 +22,13 @@ describe('ClustersActionsComponent', () => { ...@@ -22,13 +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 findAllSectionHeaders = () => wrapper.findAllComponents(GlDropdownSectionHeader); const findDropdownItemTexts = () => findDropdownItems().wrappers.map((x) => x.text());
const findSectionHeadersTexts = () => findAllSectionHeaders().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 createWrapper = (provideData = {}) => { const createWrapper = (provideData = {}) => {
wrapper = shallowMountExtended(ClustersActions, { wrapper = shallowMountExtended(ClustersActions, {
...@@ -38,7 +38,6 @@ describe('ClustersActionsComponent', () => { ...@@ -38,7 +38,6 @@ describe('ClustersActionsComponent', () => {
}, },
directives: { directives: {
GlModalDirective: createMockDirective(), GlModalDirective: createMockDirective(),
GlTooltip: createMockDirective(),
}, },
}); });
}; };
...@@ -52,12 +51,15 @@ describe('ClustersActionsComponent', () => { ...@@ -52,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', () => {
...@@ -70,8 +72,7 @@ describe('ClustersActionsComponent', () => { ...@@ -70,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', () => {
...@@ -82,41 +83,36 @@ describe('ClustersActionsComponent', () => { ...@@ -82,41 +83,36 @@ describe('ClustersActionsComponent', () => {
}); });
describe('when on project level', () => { describe('when on project level', () => {
it(`displays default action as ${CLUSTERS_ACTIONS.connectWithAgent}`, () => {
expect(findDropdown().props('text')).toBe(CLUSTERS_ACTIONS.connectWithAgent);
});
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 3 actions items', () => { it('renders a dropdown with 3 actions items', () => {
expect(findDropdownItemIds()).toEqual([ expect(findDropdownItemIds()).toEqual([
'connect-new-agent-link',
'create-cluster-link', 'create-cluster-link',
'new-cluster-link', 'new-cluster-link',
'connect-cluster-link', 'connect-cluster-link',
]); ]);
}); });
it('renders proper section headers', () => { it('renders correct texts for the dropdown items', () => {
expect(findSectionHeadersTexts()).toEqual([ expect(findDropdownItemTexts()).toEqual([
CLUSTERS_ACTIONS.agent, CLUSTERS_ACTIONS.createCluster,
CLUSTERS_ACTIONS.certificate, CLUSTERS_ACTIONS.createClusterCertificate,
CLUSTERS_ACTIONS.connectClusterCertificate,
]); ]);
}); });
it('renders correct modal id for the agent link', () => { it('renders correct href attributes for the links', () => {
const binding = getBinding(findConnectNewAgentLink().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);
});
it('shows tooltip', () => {
const tooltip = getBinding(findDropdown().element, 'gl-tooltip');
expect(tooltip.value).toBe(CLUSTERS_ACTIONS.connectWithAgent);
});
it('shows split button in dropdown', () => {
expect(findDropdown().props('split')).toBe(true);
});
it('binds split button with modal id', () => {
const binding = getBinding(findDropdown().element, 'gl-modal-directive');
expect(binding.value).toBe(INSTALL_AGENT_MODAL_ID);
}); });
}); });
...@@ -125,21 +121,20 @@ describe('ClustersActionsComponent', () => { ...@@ -125,21 +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("doesn't render section headers", () => { it('renders a dropdown with 1 action item', () => {
expect(findAllSectionHeaders()).toHaveLength(0); expect(findDropdownItemIds()).toEqual(['new-cluster-link']);
}); });
it('shows tooltip', () => { it('renders correct text for the dropdown item', () => {
const tooltip = getBinding(findDropdown().element, 'gl-tooltip'); expect(findDropdownItemTexts()).toEqual([CLUSTERS_ACTIONS.createClusterDeprecated]);
expect(tooltip.value).toBe(CLUSTERS_ACTIONS.connectExistingCluster);
}); });
it('does not show split button in dropdown', () => { it('renders correct href attributes for the links', () => {
expect(findDropdown().props('split')).toBe(false); expect(findNewClusterLink().attributes('href')).toBe(newClusterPath);
}); });
it('does not bind dropdown button to modal', () => { it('does not bind dropdown button to modal', () => {
...@@ -155,12 +150,26 @@ describe('ClustersActionsComponent', () => { ...@@ -155,12 +150,26 @@ describe('ClustersActionsComponent', () => {
createWrapper({ certificateBasedClustersEnabled: false }); createWrapper({ certificateBasedClustersEnabled: false });
}); });
it('renders a dropdown with 2 actions items', () => { it(`displays default action as ${CLUSTERS_ACTIONS.connectCluster}`, () => {
expect(findDropdownItemIds()).toEqual(['connect-new-agent-link', 'create-cluster-link']); expect(findDropdown().props('text')).toBe(CLUSTERS_ACTIONS.connectCluster);
}); });
it("doesn't render section headers", () => { it('renders correct modal id for the default action', () => {
expect(findAllSectionHeaders()).toHaveLength(0); 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('renders correct text for the dropdown item', () => {
expect(findDropdownItemTexts()).toEqual([CLUSTERS_ACTIONS.createCluster]);
});
it('renders correct href attributes for the links', () => {
expect(findNewClusterDocsLink().attributes('href')).toBe(newClusterDocsPath);
}); });
}); });
}); });
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