2021-03-11 19:13:27 +05:30
|
|
|
import { GlAvatarLabeled, GlBadge, GlIcon } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2021-03-08 18:12:59 +05:30
|
|
|
import AdminUserAvatar from '~/admin/users/components/user_avatar.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { LENGTH_OF_USER_NOTE_TOOLTIP } from '~/admin/users/constants';
|
|
|
|
import { truncate } from '~/lib/utils/text_utility';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { users, paths } from '../mock_data';
|
|
|
|
|
|
|
|
describe('AdminUserAvatar component', () => {
|
|
|
|
let wrapper;
|
|
|
|
const user = users[0];
|
|
|
|
const adminUserPath = paths.adminUser;
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
const findNote = () => wrapper.findComponent(GlIcon);
|
|
|
|
const findAvatar = () => wrapper.findComponent(GlAvatarLabeled);
|
2021-03-11 19:13:27 +05:30
|
|
|
const findUserLink = () => wrapper.find('.js-user-link');
|
2022-08-27 11:52:29 +05:30
|
|
|
const findAllBadges = () => wrapper.findAllComponents(GlBadge);
|
2021-03-11 19:13:27 +05:30
|
|
|
const findTooltip = () => getBinding(findNote().element, 'gl-tooltip');
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
const initComponent = (props = {}) => {
|
2021-03-11 19:13:27 +05:30
|
|
|
wrapper = shallowMount(AdminUserAvatar, {
|
2021-03-08 18:12:59 +05:30
|
|
|
propsData: {
|
|
|
|
user,
|
|
|
|
adminUserPath,
|
|
|
|
...props,
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
GlAvatarLabeled,
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when initialized', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
initComponent();
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('adds a user link hover card', () => {
|
|
|
|
expect(findUserLink().attributes()).toMatchObject({
|
2021-03-08 18:12:59 +05:30
|
|
|
'data-user-id': user.id.toString(),
|
|
|
|
'data-username': user.username,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
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));
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
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}`);
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it("renders the user's avatar image", () => {
|
|
|
|
expect(findAvatar().attributes('src')).toBe(user.avatarUrl);
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('renders a user note icon', () => {
|
|
|
|
expect(findNote().exists()).toBe(true);
|
|
|
|
expect(findNote().props('name')).toBe('document');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders the user's note tooltip", () => {
|
|
|
|
const tooltip = findTooltip();
|
|
|
|
|
|
|
|
expect(tooltip).toBeDefined();
|
|
|
|
expect(tooltip.value).toBe(user.note);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it("renders the user's badges", () => {
|
|
|
|
findAllBadges().wrappers.forEach((badge, idx) => {
|
|
|
|
expect(badge.text()).toBe(user.badges[idx].text);
|
|
|
|
expect(badge.props('variant')).toBe(user.badges[idx].variant);
|
|
|
|
});
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
describe('and the user note is very long', () => {
|
|
|
|
const noteText = new Array(LENGTH_OF_USER_NOTE_TOOLTIP + 1).join('a');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
initComponent({
|
|
|
|
user: {
|
|
|
|
...user,
|
|
|
|
note: noteText,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders a truncated user's note tooltip", () => {
|
|
|
|
const tooltip = findTooltip();
|
|
|
|
|
|
|
|
expect(tooltip).toBeDefined();
|
|
|
|
expect(tooltip.value).toBe(truncate(noteText, LENGTH_OF_USER_NOTE_TOOLTIP));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and the user does not have a note', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
initComponent({
|
|
|
|
user: {
|
|
|
|
...user,
|
|
|
|
note: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render a user note', () => {
|
|
|
|
expect(findNote().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
});
|