2022-05-07 20:08:51 +05:30
|
|
|
import { GlAvatarLabeled, GlIcon } from '@gitlab/ui';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-05-07 20:08:51 +05:30
|
|
|
import { IssuableType } from '~/issues/constants';
|
2021-04-29 21:17:54 +05:30
|
|
|
import SidebarParticipant from '~/sidebar/components/assignees/sidebar_participant.vue';
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
name: 'John Doe',
|
|
|
|
username: 'johndoe',
|
|
|
|
webUrl: '/link',
|
|
|
|
avatarUrl: '/avatar',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Sidebar participant component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findAvatar = () => wrapper.findComponent(GlAvatarLabeled);
|
2022-05-07 20:08:51 +05:30
|
|
|
const findIcon = () => wrapper.findComponent(GlIcon);
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
const createComponent = ({
|
|
|
|
status = null,
|
|
|
|
issuableType = IssuableType.Issue,
|
|
|
|
canMerge = false,
|
|
|
|
} = {}) => {
|
2021-04-29 21:17:54 +05:30
|
|
|
wrapper = shallowMount(SidebarParticipant, {
|
|
|
|
propsData: {
|
|
|
|
user: {
|
|
|
|
...user,
|
2022-05-07 20:08:51 +05:30
|
|
|
canMerge,
|
2021-04-29 21:17:54 +05:30
|
|
|
status,
|
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
issuableType,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
GlAvatarLabeled,
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
it('does not show `Busy` status when user is not busy', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findAvatar().props('label')).toBe(user.name);
|
|
|
|
});
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
it('shows `Busy` status when user is busy', () => {
|
|
|
|
createComponent({ status: { availability: 'BUSY' } });
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
expect(findAvatar().props('label')).toBe(`${user.name} (Busy)`);
|
|
|
|
});
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
it('does not render a warning icon', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when on merge request sidebar', () => {
|
|
|
|
it('when project member cannot merge', () => {
|
|
|
|
createComponent({ issuableType: IssuableType.MergeRequest });
|
|
|
|
|
|
|
|
expect(findIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when project member can merge', () => {
|
|
|
|
createComponent({ issuableType: IssuableType.MergeRequest, canMerge: true });
|
|
|
|
|
|
|
|
expect(findIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|