Commit f2766906 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch '346459-geo-icon-actions' into 'master'

Geo Sites - Icon Actions

See merge request gitlab-org/gitlab!78410
parents 87f15e2a 2bf77ebf
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { __ } from '~/locale'; import { s__ } from '~/locale';
export default { export default {
name: 'GeoNodeActionsDesktop', name: 'GeoNodeActionsDesktop',
i18n: { i18n: {
editButtonLabel: __('Edit'), editButtonTooltip: s__('Geo|Edit %{nodeType} site'),
removeButtonLabel: __('Remove'), removeButtonTooltip: s__('Geo|Remove %{nodeType} site'),
}, },
components: { components: {
GlButton, GlButton,
}, },
directives: {
GlTooltip: GlTooltipDirective,
},
props: { props: {
node: { node: {
type: Object, type: Object,
...@@ -20,22 +23,32 @@ export default { ...@@ -20,22 +23,32 @@ export default {
}, },
computed: { computed: {
...mapGetters(['canRemoveNode']), ...mapGetters(['canRemoveNode']),
nodeType() {
return this.node.primary ? s__('Geo|primary') : s__('Geo|secondary');
},
}, },
}; };
</script> </script>
<template> <template>
<div> <div>
<gl-button class="gl-mr-3" :href="node.webEditUrl">{{
$options.i18n.editButtonLabel
}}</gl-button>
<gl-button <gl-button
variant="danger" v-gl-tooltip
category="secondary" :title="sprintf($options.i18n.editButtonTooltip, { nodeType })"
:aria-label="sprintf($options.i18n.editButtonTooltip, { nodeType })"
icon="pencil"
class="gl-mr-3"
data-testid="geo-desktop-edit-action"
:href="node.webEditUrl"
/>
<gl-button
v-gl-tooltip
:title="sprintf($options.i18n.removeButtonTooltip, { nodeType })"
:aria-label="sprintf($options.i18n.removeButtonTooltip, { nodeType })"
icon="remove"
:disabled="!canRemoveNode(node.id)" :disabled="!canRemoveNode(node.id)"
data-testid="geo-desktop-remove-action" data-testid="geo-desktop-remove-action"
@click="$emit('remove')" @click="$emit('remove')"
>{{ $options.i18n.removeButtonLabel }}</gl-button />
>
</div> </div>
</template> </template>
...@@ -39,6 +39,7 @@ describe('GeoNodeActionsDesktop', () => { ...@@ -39,6 +39,7 @@ describe('GeoNodeActionsDesktop', () => {
}); });
const findGeoDesktopActionsButtons = () => wrapper.findAllComponents(GlButton); const findGeoDesktopActionsButtons = () => wrapper.findAllComponents(GlButton);
const findGeoDesktopActionsEditButton = () => wrapper.findByTestId('geo-desktop-edit-action');
const findGeoDesktopActionsRemoveButton = () => wrapper.findByTestId('geo-desktop-remove-action'); const findGeoDesktopActionsRemoveButton = () => wrapper.findByTestId('geo-desktop-remove-action');
describe('template', () => { describe('template', () => {
...@@ -47,11 +48,10 @@ describe('GeoNodeActionsDesktop', () => { ...@@ -47,11 +48,10 @@ describe('GeoNodeActionsDesktop', () => {
createComponent(); createComponent();
}); });
it('renders an Edit and Remove button', () => { it('renders an Edit and Remove button icon', () => {
expect(findGeoDesktopActionsButtons().wrappers.map((w) => w.text())).toStrictEqual([ expect(
'Edit', findGeoDesktopActionsButtons().wrappers.map((w) => w.attributes('icon')),
'Remove', ).toStrictEqual(['pencil', 'remove']);
]);
}); });
it('renders edit link correctly', () => { it('renders edit link correctly', () => {
...@@ -82,5 +82,27 @@ describe('GeoNodeActionsDesktop', () => { ...@@ -82,5 +82,27 @@ describe('GeoNodeActionsDesktop', () => {
}); });
}); });
}); });
describe.each`
primary | editTooltip | removeTooltip
${false} | ${'Edit secondary site'} | ${'Remove secondary site'}
${true} | ${'Edit primary site'} | ${'Remove primary site'}
`('action tooltips', ({ primary, editTooltip, removeTooltip }) => {
describe(`when node is ${primary ? '' : ' not'} a primary node`, () => {
beforeEach(() => {
createComponent({ node: { ...MOCK_NODES[0], primary } });
});
it(`sets edit tooltip to ${editTooltip}`, () => {
expect(findGeoDesktopActionsEditButton().attributes('title')).toBe(editTooltip);
expect(findGeoDesktopActionsEditButton().attributes('aria-label')).toBe(editTooltip);
});
it(`sets remove tooltip to ${removeTooltip}`, () => {
expect(findGeoDesktopActionsRemoveButton().attributes('title')).toBe(removeTooltip);
expect(findGeoDesktopActionsRemoveButton().attributes('aria-label')).toBe(removeTooltip);
});
});
});
}); });
}); });
...@@ -15761,6 +15761,9 @@ msgstr "" ...@@ -15761,6 +15761,9 @@ msgstr ""
msgid "Geo|Does not match the primary storage configuration" msgid "Geo|Does not match the primary storage configuration"
msgstr "" msgstr ""
msgid "Geo|Edit %{nodeType} site"
msgstr ""
msgid "Geo|Failed" msgid "Geo|Failed"
msgstr "" msgstr ""
...@@ -15890,6 +15893,9 @@ msgstr "" ...@@ -15890,6 +15893,9 @@ msgstr ""
msgid "Geo|Remove" msgid "Geo|Remove"
msgstr "" msgstr ""
msgid "Geo|Remove %{nodeType} site"
msgstr ""
msgid "Geo|Remove entry" msgid "Geo|Remove entry"
msgstr "" msgstr ""
......
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