Skip to content
代码片段 群组 项目
提交 cbce9f4e 编辑于 作者: Payton Burdette's avatar Payton Burdette
浏览文件

Merge branch '418064-convert-sites-actions-to-disclosure-dropdown' into 'master'

No related branches found
No related tags found
无相关合并请求
<script> <script>
import { GlDropdown, GlDropdownItem, GlIcon } from '@gitlab/ui'; import { GlDisclosureDropdown } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { __ } from '~/locale'; import { __ } from '~/locale';
...@@ -7,13 +7,12 @@ import { __ } from '~/locale'; ...@@ -7,13 +7,12 @@ import { __ } from '~/locale';
export default { export default {
name: 'GeoSiteActionsMobile', name: 'GeoSiteActionsMobile',
i18n: { i18n: {
toggleText: __('Actions'),
editButtonLabel: __('Edit'), editButtonLabel: __('Edit'),
removeButtonLabel: __('Remove'), removeButtonLabel: __('Remove'),
}, },
components: { components: {
GlDropdown, GlDisclosureDropdown,
GlDropdownItem,
GlIcon,
}, },
props: { props: {
site: { site: {
...@@ -23,25 +22,39 @@ export default { ...@@ -23,25 +22,39 @@ export default {
}, },
computed: { computed: {
...mapGetters(['canRemoveSite']), ...mapGetters(['canRemoveSite']),
dropdownItems() {
return [
{
text: this.$options.i18n.editButtonLabel,
href: this.site.webEditUrl,
},
{
text: this.$options.i18n.removeButtonLabel,
action: () => {
this.$emit('remove');
},
extraAttrs: {
'data-testid': 'geo-mobile-remove-action',
class: this.dropdownRemoveClass,
disabled: !this.canRemoveSite(this.site.id),
},
},
];
},
dropdownRemoveClass() { dropdownRemoveClass() {
return this.canRemoveSite(this.site.id) ? 'gl-text-red-500' : 'gl-text-gray-400'; return this.canRemoveSite(this.site.id) ? 'gl-text-red-500!' : 'gl-text-gray-400!';
}, },
}, },
}; };
</script> </script>
<template> <template>
<gl-dropdown toggle-class="gl-shadow-none! gl-bg-transparent! gl-p-3!" right> <gl-disclosure-dropdown
<template #button-content> icon="ellipsis_v"
<gl-icon name="ellipsis_h" /> :toggle-text="$options.i18n.toggleText"
</template> text-sr-only
<gl-dropdown-item :href="site.webEditUrl">{{ $options.i18n.editButtonLabel }}</gl-dropdown-item> category="tertiary"
<gl-dropdown-item no-caret
:disabled="!canRemoveSite(site.id)" :items="dropdownItems"
data-testid="geo-mobile-remove-action" />
@click="$emit('remove')"
>
<span :class="dropdownRemoveClass">{{ $options.i18n.removeButtonLabel }}</span>
</gl-dropdown-item>
</gl-dropdown>
</template> </template>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDisclosureDropdown } from '@gitlab/ui';
import Vue from 'vue'; import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import Vuex from 'vuex'; import Vuex from 'vuex';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
import GeoSiteActionsMobile from 'ee/geo_sites/components/header/geo_site_actions_mobile.vue'; import GeoSiteActionsMobile from 'ee/geo_sites/components/header/geo_site_actions_mobile.vue';
import { MOCK_PRIMARY_SITE } from 'ee_jest/geo_sites/mock_data'; import { MOCK_PRIMARY_SITE } from 'ee_jest/geo_sites/mock_data';
...@@ -15,7 +15,7 @@ describe('GeoSiteActionsMobile', () => { ...@@ -15,7 +15,7 @@ describe('GeoSiteActionsMobile', () => {
site: MOCK_PRIMARY_SITE, site: MOCK_PRIMARY_SITE,
}; };
const createComponent = (props, getters) => { const createComponent = (props, getters, mountFn = shallowMountExtended) => {
const store = new Vuex.Store({ const store = new Vuex.Store({
getters: { getters: {
canRemoveSite: () => () => true, canRemoveSite: () => () => true,
...@@ -23,7 +23,7 @@ describe('GeoSiteActionsMobile', () => { ...@@ -23,7 +23,7 @@ describe('GeoSiteActionsMobile', () => {
}, },
}); });
wrapper = shallowMountExtended(GeoSiteActionsMobile, { wrapper = mountFn(GeoSiteActionsMobile, {
store, store,
propsData: { propsData: {
...defaultProps, ...defaultProps,
...@@ -32,11 +32,11 @@ describe('GeoSiteActionsMobile', () => { ...@@ -32,11 +32,11 @@ describe('GeoSiteActionsMobile', () => {
}); });
}; };
const findGeoMobileActionsDropdown = () => wrapper.findComponent(GlDropdown); const findGeoMobileActionsDisclosureDropdown = () => wrapper.findComponent(GlDisclosureDropdown);
const findGeoMobileActionsDropdownItems = () => wrapper.findAllComponents(GlDropdownItem); const findGeoMobileActionsDisclosureDropdownItems = () =>
findGeoMobileActionsDisclosureDropdown().props('items');
const findGeoMobileActionsRemoveDropdownItem = () => const findGeoMobileActionsRemoveDropdownItem = () =>
wrapper.findByTestId('geo-mobile-remove-action'); wrapper.findByTestId('geo-mobile-remove-action');
const findGeoMobileActionsRemoveDropdownItemText = () => wrapper.findByText('Remove');
describe('template', () => { describe('template', () => {
describe('always', () => { describe('always', () => {
...@@ -45,36 +45,41 @@ describe('GeoSiteActionsMobile', () => { ...@@ -45,36 +45,41 @@ describe('GeoSiteActionsMobile', () => {
}); });
it('renders Dropdown', () => { it('renders Dropdown', () => {
expect(findGeoMobileActionsDropdown().exists()).toBe(true); expect(findGeoMobileActionsDisclosureDropdown().exists()).toBe(true);
}); });
it('renders an Edit and Remove dropdown item', () => { it('renders an Edit and Remove dropdown item', () => {
expect(findGeoMobileActionsDropdownItems().wrappers.map((w) => w.text())).toStrictEqual([ expect(
'Edit', findGeoMobileActionsDisclosureDropdownItems().map((item) => item.text),
'Remove', ).toStrictEqual(['Edit', 'Remove']);
]);
}); });
it('renders edit link correctly', () => { it('renders edit link correctly', () => {
expect(findGeoMobileActionsDropdownItems().at(0).attributes('href')).toBe( expect(findGeoMobileActionsDisclosureDropdownItems()[0].href).toBe(
MOCK_PRIMARY_SITE.webEditUrl, MOCK_PRIMARY_SITE.webEditUrl,
); );
}); });
});
describe('actions', () => {
beforeEach(() => {
createComponent(null, null, mountExtended);
});
it('emits remove when remove button is clicked', () => { it('emits remove when remove button is clicked', () => {
findGeoMobileActionsRemoveDropdownItem().vm.$emit('click'); findGeoMobileActionsRemoveDropdownItem().trigger('click');
expect(wrapper.emitted('remove')).toHaveLength(1); expect(wrapper.emitted('remove')).toHaveLength(1);
}); });
}); });
describe.each` describe.each`
canRemoveSite | disabled | dropdownClass canRemoveSite | disabled | dropdownClass
${false} | ${'true'} | ${'gl-text-gray-400'} ${false} | ${'disabled'} | ${'gl-text-gray-400!'}
${true} | ${undefined} | ${'gl-text-red-500'} ${true} | ${undefined} | ${'gl-text-red-500!'}
`(`conditionally`, ({ canRemoveSite, disabled, dropdownClass }) => { `(`conditionally`, ({ canRemoveSite, disabled, dropdownClass }) => {
beforeEach(() => { beforeEach(() => {
createComponent({}, { canRemoveSite: () => () => canRemoveSite }); createComponent({}, { canRemoveSite: () => () => canRemoveSite }, mountExtended);
}); });
describe(`when canRemoveSite is ${canRemoveSite}`, () => { describe(`when canRemoveSite is ${canRemoveSite}`, () => {
...@@ -82,7 +87,7 @@ describe('GeoSiteActionsMobile', () => { ...@@ -82,7 +87,7 @@ describe('GeoSiteActionsMobile', () => {
canRemoveSite ? 'not ' : '' canRemoveSite ? 'not ' : ''
}disable the Mobile Remove dropdown item and adds proper class`, () => { }disable the Mobile Remove dropdown item and adds proper class`, () => {
expect(findGeoMobileActionsRemoveDropdownItem().attributes('disabled')).toBe(disabled); expect(findGeoMobileActionsRemoveDropdownItem().attributes('disabled')).toBe(disabled);
expect(findGeoMobileActionsRemoveDropdownItemText().classes(dropdownClass)).toBe(true); expect(findGeoMobileActionsRemoveDropdownItem().classes(dropdownClass)).toBe(true);
}); });
}); });
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册