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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

163 lines
4.5 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { GlAvatarLink, GlBadge } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
2021-02-22 17:27:13 +05:30
import UserAvatar from '~/members/components/avatars/user_avatar.vue';
2022-10-11 01:57:18 +05:30
import { AVAILABILITY_STATUS } from '~/set_status_modal/constants';
2022-04-04 11:22:00 +05:30
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 = {}) => {
2022-04-04 11:22:00 +05:30
wrapper = mountExtended(UserAvatar, {
2021-01-03 14:25:43 +05:30
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
});
};
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
it("renders link to user's profile", () => {
createComponent();
2022-08-27 11:52:29 +05:30
const link = wrapper.findComponent(GlAvatarLink);
2021-01-03 14:25:43 +05:30
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();
2022-04-04 11:22:00 +05:30
expect(wrapper.findByText(user.name).exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
it("renders user's username", () => {
createComponent();
2022-04-04 11:22:00 +05:30
expect(wrapper.findByText(`@${user.username}`).exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
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 });
2022-04-04 11:22:00 +05:30
expect(wrapper.findByText('Orphaned member').exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
});
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 });
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(GlBadge).text()).toBe(badgeText);
2021-01-03 14:25:43 +05:30
});
it('renders the "It\'s you" badge when member is current user', () => {
createComponent({ isCurrentUser: true });
2022-04-04 11:22:00 +05:30
expect(wrapper.findByText("It's you").exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
2021-04-17 20:07:23 +05:30
it('does not render 2FA badge when `canManageMembers` is `false`', () => {
createComponent({ member: member2faEnabled }, { canManageMembers: false });
2022-04-04 11:22:00 +05:30
expect(wrapper.findByText('2FA').exists()).toBe(false);
2021-04-17 20:07:23 +05:30
});
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);
});
2022-04-04 11:22:00 +05:30
describe('when `user.showStatus` is `false', () => {
it('does not display status emoji', () => {
createComponent({
member: {
...memberMock,
user: {
...memberMock.user,
showStatus: false,
status: { emoji, messageHtml: 'On vacation' },
},
},
});
expect(findStatusEmoji(emoji).exists()).toBe(false);
});
});
2021-01-03 14:25:43 +05:30
});
describe('when not set', () => {
it('does not display status emoji', () => {
createComponent();
expect(findStatusEmoji(emoji).exists()).toBe(false);
});
});
});
2022-04-04 11:22:00 +05:30
describe('user availability', () => {
describe('when `user.availability` is `null`', () => {
it("does not show `(Busy)` next to user's name", () => {
createComponent();
expect(wrapper.findByText('(Busy)').exists()).toBe(false);
});
});
describe(`when user.availability is ${AVAILABILITY_STATUS.BUSY}`, () => {
it("shows `(Busy)` next to user's name", () => {
createComponent({
member: {
...memberMock,
user: {
...memberMock.user,
availability: AVAILABILITY_STATUS.BUSY,
},
},
});
expect(wrapper.findByText('(Busy)').exists()).toBe(true);
});
});
});
2021-01-03 14:25:43 +05:30
});