2020-08-21 05:10:08 -04:00
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-01-25 07:14:14 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { trimText } from 'helpers/text_helper';
|
2021-01-14 19:10:45 -05:00
|
|
|
import UsersMockHelper from 'helpers/user_mock_data_helper';
|
2019-12-03 13:06:49 -05:00
|
|
|
import Assignee from '~/sidebar/components/assignees/assignees.vue';
|
2021-10-04 23:11:53 -04:00
|
|
|
import AssigneeAvatarLink from '~/sidebar/components/assignees/assignee_avatar_link.vue';
|
2019-12-03 13:06:49 -05:00
|
|
|
import UsersMock from './mock_data';
|
|
|
|
|
|
|
|
describe('Assignee component', () => {
|
|
|
|
const getDefaultProps = () => ({
|
|
|
|
rootPath: 'http://localhost:3000',
|
|
|
|
users: [],
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createWrapper = (propsData = getDefaultProps()) => {
|
|
|
|
wrapper = mount(Assignee, {
|
|
|
|
propsData,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-10-04 23:11:53 -04:00
|
|
|
const findAllAvatarLinks = () => wrapper.findAllComponents(AssigneeAvatarLink);
|
2021-06-11 02:10:03 -04:00
|
|
|
const findComponentTextNoUsers = () => wrapper.find('[data-testid="no-value"]');
|
2019-12-03 13:06:49 -05:00
|
|
|
const findCollapsedChildren = () => wrapper.findAll('.sidebar-collapsed-icon > *');
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('No assignees/users', () => {
|
|
|
|
it('displays no assignee icon when collapsed', () => {
|
|
|
|
createWrapper();
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
2022-09-21 11:14:09 -04:00
|
|
|
const userIcon = collapsedChildren.at(0).findComponent(GlIcon);
|
2019-12-03 13:06:49 -05:00
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(1);
|
|
|
|
expect(collapsedChildren.at(0).attributes('aria-label')).toBe('None');
|
2020-08-21 05:10:08 -04:00
|
|
|
expect(userIcon.exists()).toBe(true);
|
|
|
|
expect(userIcon.props('name')).toBe('user');
|
2019-12-03 13:06:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays only "None" when no users are assigned and the issue is read-only', () => {
|
|
|
|
createWrapper();
|
|
|
|
const componentTextNoUsers = trimText(findComponentTextNoUsers().text());
|
|
|
|
|
|
|
|
expect(componentTextNoUsers).toBe('None');
|
|
|
|
expect(componentTextNoUsers).not.toContain('assign yourself');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays only "None" when no users are assigned and the issue can be edited', () => {
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
const componentTextNoUsers = trimText(findComponentTextNoUsers().text());
|
|
|
|
|
|
|
|
expect(componentTextNoUsers).toContain('None');
|
|
|
|
expect(componentTextNoUsers).toContain('assign yourself');
|
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('emits the assign-self event when "assign yourself" is clicked', async () => {
|
2019-12-03 13:06:49 -05:00
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.spyOn(wrapper.vm, '$emit');
|
2021-06-11 02:10:03 -04:00
|
|
|
wrapper.find('[data-testid="assign-yourself"]').trigger('click');
|
2019-12-03 13:06:49 -05:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
2022-08-11 14:11:57 -04:00
|
|
|
expect(wrapper.emitted('assign-self')).toHaveLength(1);
|
2019-12-03 13:06:49 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('One assignee/user', () => {
|
|
|
|
it('displays one assignee icon when collapsed', () => {
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users: [UsersMock.user],
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
|
|
|
const assignee = collapsedChildren.at(0);
|
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(1);
|
|
|
|
expect(assignee.find('.avatar').attributes('src')).toBe(UsersMock.user.avatar);
|
|
|
|
expect(assignee.find('.avatar').attributes('alt')).toBe(`${UsersMock.user.name}'s avatar`);
|
|
|
|
|
|
|
|
expect(trimText(assignee.find('.author').text())).toBe(UsersMock.user.name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Two or more assignees/users', () => {
|
|
|
|
it('displays two assignee icons when collapsed', () => {
|
|
|
|
const users = UsersMockHelper.createNumberRandomUsers(2);
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(2);
|
|
|
|
|
|
|
|
const first = collapsedChildren.at(0);
|
|
|
|
|
2020-04-01 05:07:45 -04:00
|
|
|
expect(first.find('.avatar').attributes('src')).toBe(users[0].avatar_url);
|
2019-12-03 13:06:49 -05:00
|
|
|
expect(first.find('.avatar').attributes('alt')).toBe(`${users[0].name}'s avatar`);
|
|
|
|
|
|
|
|
expect(trimText(first.find('.author').text())).toBe(users[0].name);
|
|
|
|
|
|
|
|
const second = collapsedChildren.at(1);
|
|
|
|
|
2020-04-01 05:07:45 -04:00
|
|
|
expect(second.find('.avatar').attributes('src')).toBe(users[1].avatar_url);
|
2019-12-03 13:06:49 -05:00
|
|
|
expect(second.find('.avatar').attributes('alt')).toBe(`${users[1].name}'s avatar`);
|
|
|
|
|
|
|
|
expect(trimText(second.find('.author').text())).toBe(users[1].name);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays one assignee icon and counter when collapsed', () => {
|
|
|
|
const users = UsersMockHelper.createNumberRandomUsers(3);
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(2);
|
|
|
|
|
|
|
|
const first = collapsedChildren.at(0);
|
|
|
|
|
2020-04-01 05:07:45 -04:00
|
|
|
expect(first.find('.avatar').attributes('src')).toBe(users[0].avatar_url);
|
2019-12-03 13:06:49 -05:00
|
|
|
expect(first.find('.avatar').attributes('alt')).toBe(`${users[0].name}'s avatar`);
|
|
|
|
|
|
|
|
expect(trimText(first.find('.author').text())).toBe(users[0].name);
|
|
|
|
|
|
|
|
const second = collapsedChildren.at(1);
|
|
|
|
|
|
|
|
expect(trimText(second.find('.avatar-counter').text())).toBe('+2');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Shows two assignees', () => {
|
|
|
|
const users = UsersMockHelper.createNumberRandomUsers(2);
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
2021-10-04 23:11:53 -04:00
|
|
|
expect(findAllAvatarLinks()).toHaveLength(users.length);
|
2019-12-03 13:06:49 -05:00
|
|
|
expect(wrapper.find('.user-list-more').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows sorted assignee where "can merge" users are sorted first', () => {
|
|
|
|
const users = UsersMockHelper.createNumberRandomUsers(3);
|
|
|
|
users[0].can_merge = false;
|
|
|
|
users[1].can_merge = false;
|
|
|
|
users[2].can_merge = true;
|
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.sortedAssigness[0].can_merge).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the sorted assignees to the uncollapsed-assignee-list', () => {
|
|
|
|
const users = UsersMockHelper.createNumberRandomUsers(3);
|
|
|
|
users[0].can_merge = false;
|
|
|
|
users[1].can_merge = false;
|
|
|
|
users[2].can_merge = true;
|
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
2021-10-04 23:11:53 -04:00
|
|
|
const userItems = findAllAvatarLinks();
|
2019-12-03 13:06:49 -05:00
|
|
|
|
2021-10-04 23:11:53 -04:00
|
|
|
expect(userItems).toHaveLength(3);
|
2019-12-20 13:07:53 -05:00
|
|
|
expect(userItems.at(0).attributes('title')).toBe(users[2].name);
|
2019-12-03 13:06:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the sorted assignees to the collapsed-assignee-list', () => {
|
|
|
|
const users = UsersMockHelper.createNumberRandomUsers(3);
|
|
|
|
users[0].can_merge = false;
|
|
|
|
users[1].can_merge = false;
|
|
|
|
users[2].can_merge = true;
|
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedButton = wrapper.find('.sidebar-collapsed-user button');
|
|
|
|
|
|
|
|
expect(trimText(collapsedButton.text())).toBe(users[2].name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|