debian-mirror-gitlab/spec/frontend/vue_shared/components/issue/issue_assignees_spec.js

131 lines
4.1 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { shallowMount } from '@vue/test-utils';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2019-02-15 15:39:39 +05:30
import IssueAssignees from '~/vue_shared/components/issue/issue_assignees.vue';
2019-07-31 22:56:46 +05:30
import { mockAssigneesList } from '../../../../javascripts/boards/mock_data';
2019-02-15 15:39:39 +05:30
2019-12-26 22:10:19 +05:30
const TEST_CSS_CLASSES = 'test-classes';
const TEST_MAX_VISIBLE = 4;
const TEST_ICON_SIZE = 16;
2019-02-15 15:39:39 +05:30
describe('IssueAssigneesComponent', () => {
2019-12-26 22:10:19 +05:30
let wrapper;
2019-02-15 15:39:39 +05:30
let vm;
2019-12-26 22:10:19 +05:30
const factory = props => {
wrapper = shallowMount(IssueAssignees, {
propsData: {
assignees: mockAssigneesList,
...props,
},
sync: false,
2020-01-01 13:55:28 +05:30
attachToDocument: true,
2019-02-15 15:39:39 +05:30
});
2019-12-26 22:10:19 +05:30
vm = wrapper.vm; // eslint-disable-line
};
const findTooltipText = () => wrapper.find('.js-assignee-tooltip').text();
const findAvatars = () => wrapper.findAll(UserAvatarLink);
const findOverflowCounter = () => wrapper.find('.avatar-counter');
it('returns default data props', () => {
factory({ assignees: mockAssigneesList });
expect(vm.iconSize).toBe(24);
expect(vm.maxVisible).toBe(3);
expect(vm.maxAssignees).toBe(99);
2019-02-15 15:39:39 +05:30
});
2019-12-26 22:10:19 +05:30
describe.each`
numAssignees | maxVisible | expectedShown | expectedHidden
${0} | ${3} | ${0} | ${''}
${1} | ${3} | ${1} | ${''}
${2} | ${3} | ${2} | ${''}
${3} | ${3} | ${3} | ${''}
${4} | ${3} | ${2} | ${'+2'}
${5} | ${2} | ${1} | ${'+4'}
${1000} | ${5} | ${4} | ${'99+'}
`(
'with assignees ($numAssignees) and maxVisible ($maxVisible)',
({ numAssignees, maxVisible, expectedShown, expectedHidden }) => {
beforeEach(() => {
factory({ assignees: Array(numAssignees).fill({}), maxVisible });
2019-02-15 15:39:39 +05:30
});
2019-12-26 22:10:19 +05:30
if (expectedShown) {
it('shows assignee avatars', () => {
expect(findAvatars().length).toEqual(expectedShown);
});
} else {
it('does not show assignee avatars', () => {
expect(findAvatars().length).toEqual(0);
});
}
if (expectedHidden) {
it('shows overflow counter', () => {
const hiddenCount = numAssignees - expectedShown;
expect(findOverflowCounter().exists()).toBe(true);
expect(findOverflowCounter().text()).toEqual(expectedHidden.toString());
expect(findOverflowCounter().attributes('data-original-title')).toEqual(
`${hiddenCount} more assignees`,
);
});
} else {
it('does not show overflow counter', () => {
expect(findOverflowCounter().exists()).toBe(false);
});
}
},
);
describe('when mounted', () => {
beforeEach(() => {
factory({
imgCssClasses: TEST_CSS_CLASSES,
maxVisible: TEST_MAX_VISIBLE,
iconSize: TEST_ICON_SIZE,
2019-02-15 15:39:39 +05:30
});
});
2019-12-26 22:10:19 +05:30
it('computes alt text for assignee avatar', () => {
expect(vm.avatarUrlTitle(mockAssigneesList[0])).toBe('Avatar for Terrell Graham');
2019-02-15 15:39:39 +05:30
});
it('renders component root element with class `issue-assignees`', () => {
2019-12-26 22:10:19 +05:30
expect(wrapper.element.classList.contains('issue-assignees')).toBe(true);
2019-02-15 15:39:39 +05:30
});
2019-12-26 22:10:19 +05:30
it('renders assignee', () => {
const data = findAvatars().wrappers.map(x => ({
...x.props(),
}));
const expected = mockAssigneesList.slice(0, TEST_MAX_VISIBLE - 1).map(x =>
expect.objectContaining({
linkHref: x.web_url,
imgAlt: `Avatar for ${x.name}`,
imgCssClasses: TEST_CSS_CLASSES,
imgSrc: x.avatar_url,
imgSize: TEST_ICON_SIZE,
}),
);
expect(data).toEqual(expected);
2019-02-15 15:39:39 +05:30
});
2019-12-26 22:10:19 +05:30
describe('assignee tooltips', () => {
it('renders "Assignee" header', () => {
expect(findTooltipText()).toContain('Assignee');
});
2019-02-15 15:39:39 +05:30
2019-12-26 22:10:19 +05:30
it('renders assignee name', () => {
expect(findTooltipText()).toContain('Terrell Graham');
});
2019-02-15 15:39:39 +05:30
2019-12-26 22:10:19 +05:30
it('renders assignee @username', () => {
expect(findTooltipText()).toContain('@monserrate.gleichner');
});
2019-02-15 15:39:39 +05:30
});
});
});