debian-mirror-gitlab/spec/frontend/members/components/avatars/user_avatar_spec.js

126 lines
3.4 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { GlAvatarLink, GlBadge } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { within } from '@testing-library/dom';
import { mount, createWrapper } from '@vue/test-utils';
2021-02-22 17:27:13 +05:30
import UserAvatar from '~/members/components/avatars/user_avatar.vue';
2021-04-17 20:07:23 +05:30
import { member as memberMock, member2faEnabled, orphanedMember } from '../../mock_data';
2021-01-03 14:25:43 +05:30
describe('UserAvatar', () => {
let wrapper;
const { user } = memberMock;
2021-04-29 21:17:54 +05:30
const createComponent = (propsData = {}, provide = {}) => {
2021-01-03 14:25:43 +05:30
wrapper = mount(UserAvatar, {
propsData: {
member: memberMock,
isCurrentUser: false,
...propsData,
},
2021-04-29 21:17:54 +05:30
provide: {
canManageMembers: true,
...provide,
},
2021-01-03 14:25:43 +05:30
});
};
const getByText = (text, options) =>
createWrapper(within(wrapper.element).findByText(text, options));
2021-03-08 18:12:59 +05:30
const findStatusEmoji = (emoji) => wrapper.find(`gl-emoji[data-name="${emoji}"]`);
2021-01-03 14:25:43 +05:30
afterEach(() => {
wrapper.destroy();
});
it("renders link to user's profile", () => {
createComponent();
const link = wrapper.find(GlAvatarLink);
expect(link.exists()).toBe(true);
expect(link.attributes()).toMatchObject({
href: user.webUrl,
'data-user-id': `${user.id}`,
'data-username': user.username,
});
});
it("renders user's name", () => {
createComponent();
expect(getByText(user.name).exists()).toBe(true);
});
it("renders user's username", () => {
createComponent();
expect(getByText(`@${user.username}`).exists()).toBe(true);
});
it("renders user's avatar", () => {
createComponent();
expect(wrapper.find('img').attributes('src')).toBe(user.avatarUrl);
});
describe('when user property does not exist', () => {
it('displays an orphaned user', () => {
createComponent({ member: orphanedMember });
expect(getByText('Orphaned member').exists()).toBe(true);
});
});
describe('badges', () => {
it.each`
2021-04-17 20:07:23 +05:30
member | badgeText
${{ ...memberMock, user: { ...memberMock.user, blocked: true } }} | ${'Blocked'}
${member2faEnabled} | ${'2FA'}
2021-01-03 14:25:43 +05:30
`('renders the "$badgeText" badge', ({ member, badgeText }) => {
createComponent({ member });
expect(wrapper.find(GlBadge).text()).toBe(badgeText);
});
it('renders the "It\'s you" badge when member is current user', () => {
createComponent({ isCurrentUser: true });
expect(getByText("It's you").exists()).toBe(true);
});
2021-04-17 20:07:23 +05:30
it('does not render 2FA badge when `canManageMembers` is `false`', () => {
createComponent({ member: member2faEnabled }, { canManageMembers: false });
expect(within(wrapper.element).queryByText('2FA')).toBe(null);
});
2021-01-03 14:25:43 +05:30
});
describe('user status', () => {
const emoji = 'island';
describe('when set', () => {
it('displays the status emoji', () => {
createComponent({
member: {
...memberMock,
user: {
...memberMock.user,
status: { emoji, messageHtml: 'On vacation' },
},
},
});
expect(findStatusEmoji(emoji).exists()).toBe(true);
});
});
describe('when not set', () => {
it('does not display status emoji', () => {
createComponent();
expect(findStatusEmoji(emoji).exists()).toBe(false);
});
});
});
});