Commit f4908170 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'update-vue-admin-users-avatar-links' into 'master'

Update vue admin users avatar links

See merge request gitlab-org/gitlab!53492
parents d1be3575 62f6a6c9
<script>
import { GlAvatarLink, GlAvatarLabeled, GlBadge, GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { GlAvatarLabeled, GlBadge, GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { truncate } from '~/lib/utils/text_utility';
import { USER_AVATAR_SIZE, LENGTH_OF_USER_NOTE_TOOLTIP } from '../constants';
......@@ -8,7 +8,6 @@ export default {
GlTooltip: GlTooltipDirective,
},
components: {
GlAvatarLink,
GlAvatarLabeled,
GlBadge,
GlIcon,
......@@ -27,6 +26,11 @@ export default {
adminUserHref() {
return this.adminUserPath.replace('id', this.user.username);
},
adminUserMailto() {
// NOTE: 'mailto:' is a false positive: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26#possible-false-positives
// eslint-disable-next-line @gitlab/require-i18n-strings
return `mailto:${this.user.email}`;
},
userNoteShort() {
return truncate(this.user.note, LENGTH_OF_USER_NOTE_TOOLTIP);
},
......@@ -36,10 +40,9 @@ export default {
</script>
<template>
<gl-avatar-link
<div
v-if="user"
class="js-user-link"
:href="adminUserHref"
class="js-user-link gl-display-inline-block"
:data-user-id="user.id"
:data-username="user.username"
>
......@@ -48,6 +51,8 @@ export default {
:src="user.avatarUrl"
:label="user.name"
:sub-label="user.email"
:label-link="adminUserHref"
:sub-label-link="adminUserMailto"
>
<template #meta>
<div v-if="user.note" class="gl-text-gray-500 gl-p-1">
......@@ -60,5 +65,5 @@ export default {
</div>
</template>
</gl-avatar-labeled>
</gl-avatar-link>
</div>
</template>
import { GlAvatarLink, GlAvatarLabeled, GlBadge, GlIcon } from '@gitlab/ui';
import { GlAvatarLabeled, GlBadge, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
......@@ -14,7 +14,7 @@ describe('AdminUserAvatar component', () => {
const findNote = () => wrapper.find(GlIcon);
const findAvatar = () => wrapper.find(GlAvatarLabeled);
const findAvatarLink = () => wrapper.find(GlAvatarLink);
const findUserLink = () => wrapper.find('.js-user-link');
const findAllBadges = () => wrapper.findAll(GlBadge);
const findTooltip = () => getBinding(findNote().element, 'gl-tooltip');
......@@ -44,20 +44,25 @@ describe('AdminUserAvatar component', () => {
initComponent();
});
it("links to the user's admin path", () => {
expect(findAvatarLink().attributes()).toMatchObject({
href: adminUserPath.replace('id', user.username),
it('adds a user link hover card', () => {
expect(findUserLink().attributes()).toMatchObject({
'data-user-id': user.id.toString(),
'data-username': user.username,
});
});
it("renders the user's name", () => {
expect(findAvatar().props('label')).toBe(user.name);
it("renders the user's name with an admin path link", () => {
const avatar = findAvatar();
expect(avatar.props('label')).toBe(user.name);
expect(avatar.props('labelLink')).toBe(adminUserPath.replace('id', user.username));
});
it("renders the user's email", () => {
expect(findAvatar().props('subLabel')).toBe(user.email);
it("renders the user's email with a mailto link", () => {
const avatar = findAvatar();
expect(avatar.props('subLabel')).toBe(user.email);
expect(avatar.props('subLabelLink')).toBe(`mailto:${user.email}`);
});
it("renders the user's avatar image", () => {
......
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