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