Commit 20082d12 authored by Tom Quirk's avatar Tom Quirk

Use GlAvatar in approval rule selector

Replaces deprecated avatar with GlAvatarLabeled.

Changelog: changed
EE: true
parent 3ee1ed2b
<script>
import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import Avatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
import { GlButton, GlTooltipDirective, GlAvatarLabeled } from '@gitlab/ui';
import { __ } from '~/locale';
import { TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS } from '../constants';
import HiddenGroupsItem from './hidden_groups_item.vue';
......@@ -9,7 +9,7 @@ const types = [TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS];
export default {
components: {
GlButton,
Avatar,
GlAvatarLabeled,
HiddenGroupsItem,
},
directives: {
......@@ -19,7 +19,7 @@ export default {
approver: {
type: Object,
required: true,
validator: ({ type }) => type && types.indexOf(type) >= 0,
validator: ({ type }) => type && types.includes(type),
},
},
computed: {
......@@ -32,23 +32,36 @@ export default {
displayName() {
return this.isGroup ? this.approver.full_path : this.approver.name;
},
avatarShape() {
return this.isGroup ? 'rect' : 'circle';
},
},
i18n: {
removeApproverText: __('Remove'),
},
};
</script>
<template>
<transition name="fade">
<li class="d-flex align-items-center px-3">
<li class="gl-display-flex! gl-align-items-center gl-px-5!">
<hidden-groups-item v-if="isHiddenGroups" />
<template v-else>
<avatar :project="approver" :size="24" /><span>{{ displayName }}</span>
</template>
<gl-avatar-labeled
v-else
:shape="avatarShape"
:entity-name="approver.name"
:label="displayName"
:src="approver.avatar_url"
:alt="approver.name"
:size="24"
/>
<gl-button
v-gl-tooltip
class="ml-auto"
class="gl-ml-auto"
icon="remove"
:aria-label="__('Remove')"
:title="__('Remove')"
:aria-label="$options.i18n.removeApproverText"
:title="$options.i18n.removeApproverText"
@click="$emit('remove', approver)"
/>
</li>
......
import { GlButton } from '@gitlab/ui';
import { GlButton, GlAvatarLabeled } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import ApproversListItem from 'ee/approvals/components/approvers_list_item.vue';
import HiddenGroupsItem from 'ee/approvals/components/hidden_groups_item.vue';
import { TYPE_USER, TYPE_GROUP, TYPE_HIDDEN_GROUPS } from 'ee/approvals/constants';
import Avatar from '~/vue_shared/components/deprecated_project_avatar/default.vue';
const TEST_USER = {
id: 1,
type: TYPE_USER,
name: 'Lorem Ipsum',
avatar_url: '/asd/1',
};
const TEST_GROUP = {
id: 1,
type: TYPE_GROUP,
name: 'Lorem Group',
full_path: 'dolar/sit/amit',
avatar_url: '/asd/2',
};
describe('Approvals ApproversListItem', () => {
......@@ -26,6 +27,9 @@ describe('Approvals ApproversListItem', () => {
});
};
const findAvatar = () => wrapper.findComponent(GlAvatarLabeled);
const findHiddenGroupsItem = () => wrapper.findComponent(HiddenGroupsItem);
describe('when user', () => {
beforeEach(() => {
factory({
......@@ -35,24 +39,23 @@ describe('Approvals ApproversListItem', () => {
});
});
it('renders avatar', () => {
const avatar = wrapper.find(Avatar);
it('renders GlAvatar for user', () => {
const avatar = findAvatar();
expect(avatar.exists()).toBe(true);
expect(avatar.props('project')).toEqual(TEST_USER);
});
it('renders name', () => {
expect(wrapper.text()).toContain(TEST_USER.name);
expect(avatar.attributes()).toMatchObject({
'entity-name': TEST_USER.name,
src: TEST_USER.avatar_url,
shape: 'circle',
alt: TEST_USER.name,
});
expect(avatar.props('label')).toBe(TEST_USER.name);
});
it('when remove clicked, emits remove', () => {
const button = wrapper.find(GlButton);
button.vm.$emit('click');
it('when remove clicked, emits remove', async () => {
const button = wrapper.findComponent(GlButton);
await button.vm.$emit('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().remove).toEqual([[TEST_USER]]);
});
expect(wrapper.emitted().remove).toEqual([[TEST_USER]]);
});
});
......@@ -65,13 +68,20 @@ describe('Approvals ApproversListItem', () => {
});
});
it('renders full_path', () => {
expect(wrapper.text()).toContain(TEST_GROUP.full_path);
expect(wrapper.text()).not.toContain(TEST_GROUP.name);
it('renders ProjectAvatar for group', () => {
const avatar = findAvatar();
expect(avatar.exists()).toBe(true);
expect(avatar.attributes()).toMatchObject({
'entity-name': TEST_GROUP.name,
src: TEST_GROUP.avatar_url,
shape: 'rect',
alt: TEST_GROUP.name,
});
expect(avatar.props('label')).toBe(TEST_GROUP.full_path);
});
it('does not render hidden-groups-item', () => {
expect(wrapper.find(HiddenGroupsItem).exists()).toBe(false);
expect(findHiddenGroupsItem().exists()).toBe(false);
});
});
......@@ -85,11 +95,11 @@ describe('Approvals ApproversListItem', () => {
});
it('renders hidden-groups-item', () => {
expect(wrapper.find(HiddenGroupsItem).exists()).toBe(true);
expect(findHiddenGroupsItem().exists()).toBe(true);
});
it('does not render avatar', () => {
expect(wrapper.find(Avatar).exists()).toBe(false);
it('does not render any avatar', () => {
expect(findAvatar().exists()).toBe(false);
});
});
});
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