2019-11-06 21:06:44 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-08-17 21:09:56 +00:00
|
|
|
import { mockAssigneesList } from 'jest/boards/mock_data';
|
2021-12-17 12:16:21 +00:00
|
|
|
import IssueAssignees from '~/issuable/components/issue_assignees.vue';
|
2021-02-14 18:09:20 +00:00
|
|
|
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
|
2018-12-08 09:58:45 +00:00
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
const TEST_CSS_CLASSES = 'test-classes';
|
|
|
|
const TEST_MAX_VISIBLE = 4;
|
|
|
|
const TEST_ICON_SIZE = 16;
|
2018-12-08 09:58:45 +00:00
|
|
|
|
|
|
|
describe('IssueAssigneesComponent', () => {
|
2019-11-06 21:06:44 +00:00
|
|
|
let wrapper;
|
2018-12-08 09:58:45 +00:00
|
|
|
let vm;
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const factory = (props) => {
|
2019-11-06 21:06:44 +00:00
|
|
|
wrapper = shallowMount(IssueAssignees, {
|
|
|
|
propsData: {
|
|
|
|
assignees: mockAssigneesList,
|
|
|
|
...props,
|
|
|
|
},
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
2020-02-18 09:09:24 +00:00
|
|
|
vm = wrapper.vm;
|
2019-11-06 21:06:44 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 12:09:59 +00:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
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);
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
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 });
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
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());
|
2019-12-20 18:07:53 +00:00
|
|
|
expect(findOverflowCounter().attributes('title')).toEqual(
|
2019-11-06 21:06:44 +00:00
|
|
|
`${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,
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
it('computes alt text for assignee avatar', () => {
|
2021-05-24 18:10:28 +00:00
|
|
|
expect(vm.avatarUrlTitle(mockAssigneesList[0])).toBe('Assigned to Terrell Graham');
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
it('renders assignee', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
const data = findAvatars().wrappers.map((x) => ({
|
2019-11-06 21:06:44 +00:00
|
|
|
...x.props(),
|
|
|
|
}));
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const expected = mockAssigneesList.slice(0, TEST_MAX_VISIBLE - 1).map((x) =>
|
2019-11-06 21:06:44 +00:00
|
|
|
expect.objectContaining({
|
|
|
|
linkHref: x.web_url,
|
2021-05-24 18:10:28 +00:00
|
|
|
imgAlt: `Assigned to ${x.name}`,
|
2019-11-06 21:06:44 +00:00
|
|
|
imgCssClasses: TEST_CSS_CLASSES,
|
|
|
|
imgSrc: x.avatar_url,
|
|
|
|
imgSize: TEST_ICON_SIZE,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(data).toEqual(expected);
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
describe('assignee tooltips', () => {
|
|
|
|
it('renders "Assignee" header', () => {
|
|
|
|
expect(findTooltipText()).toContain('Assignee');
|
|
|
|
});
|
2018-12-08 09:58:45 +00:00
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
it('renders assignee name', () => {
|
|
|
|
expect(findTooltipText()).toContain('Terrell Graham');
|
|
|
|
});
|
2018-12-08 09:58:45 +00:00
|
|
|
|
2019-11-06 21:06:44 +00:00
|
|
|
it('renders assignee @username', () => {
|
|
|
|
expect(findTooltipText()).toContain('@monserrate.gleichner');
|
|
|
|
});
|
2020-08-06 12:09:59 +00:00
|
|
|
|
|
|
|
it('does not render `@` when username not available', () => {
|
|
|
|
const userName = 'User without username';
|
|
|
|
factory({
|
|
|
|
assignees: [
|
|
|
|
{
|
|
|
|
name: userName,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const tooltipText = findTooltipText();
|
|
|
|
|
|
|
|
expect(tooltipText).toContain(userName);
|
|
|
|
expect(tooltipText).not.toContain('@');
|
|
|
|
});
|
2018-12-08 09:58:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|