2021-03-11 19:13:27 +05:30
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { trimText } from 'helpers/text_helper';
|
2022-08-27 11:52:29 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2021-01-03 14:25:43 +05:30
|
|
|
import Reviewer from '~/sidebar/components/reviewers/reviewers.vue';
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
const usersMock = (id = 1) => ({
|
|
|
|
id,
|
|
|
|
name: 'Root',
|
|
|
|
state: 'active',
|
|
|
|
username: 'root',
|
|
|
|
webUrl: `${TEST_HOST}/root`,
|
|
|
|
avatarUrl: `${TEST_HOST}/avatar/root.png`,
|
|
|
|
mergeRequestInteraction: {
|
|
|
|
canMerge: true,
|
|
|
|
canUpdate: true,
|
|
|
|
reviewed: true,
|
|
|
|
approved: false,
|
|
|
|
},
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('Reviewer component', () => {
|
|
|
|
const getDefaultProps = () => ({
|
|
|
|
rootPath: 'http://localhost:3000',
|
|
|
|
users: [],
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createWrapper = (propsData = getDefaultProps()) => {
|
|
|
|
wrapper = mount(Reviewer, {
|
|
|
|
propsData,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findCollapsedChildren = () => wrapper.findAll('.sidebar-collapsed-icon > *');
|
|
|
|
|
|
|
|
describe('No reviewers/users', () => {
|
|
|
|
it('displays no reviewer icon when collapsed', () => {
|
|
|
|
createWrapper();
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
2022-11-25 23:54:43 +05:30
|
|
|
const userIcon = collapsedChildren.at(0).findComponent(GlIcon);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(1);
|
|
|
|
expect(collapsedChildren.at(0).attributes('aria-label')).toBe('None');
|
|
|
|
expect(userIcon.exists()).toBe(true);
|
|
|
|
expect(userIcon.props('name')).toBe('user');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('One reviewer/user', () => {
|
|
|
|
it('displays one reviewer icon when collapsed', () => {
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
2022-08-27 11:52:29 +05:30
|
|
|
users: [usersMock()],
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
|
|
|
const reviewer = collapsedChildren.at(0);
|
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(1);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(reviewer.find('.avatar').attributes('src')).toContain('avatar/root.png');
|
|
|
|
expect(reviewer.find('.avatar').attributes('alt')).toBe(`Root's avatar`);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(trimText(reviewer.find('.author').text())).toBe('Root');
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Two or more reviewers/users', () => {
|
|
|
|
it('displays two reviewer icons when collapsed', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const users = [usersMock(), usersMock(2)];
|
2021-01-03 14:25:43 +05:30
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(2);
|
|
|
|
|
|
|
|
const first = collapsedChildren.at(0);
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(first.find('.avatar').attributes('src')).toBe(users[0].avatarUrl);
|
2021-01-03 14:25:43 +05:30
|
|
|
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);
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(second.find('.avatar').attributes('src')).toBe(users[1].avatarUrl);
|
2021-01-03 14:25:43 +05:30
|
|
|
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 reviewer icon and counter when collapsed', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const users = [usersMock(), usersMock(2), usersMock(3)];
|
2021-01-03 14:25:43 +05:30
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedChildren = findCollapsedChildren();
|
|
|
|
|
|
|
|
expect(collapsedChildren.length).toBe(2);
|
|
|
|
|
|
|
|
const first = collapsedChildren.at(0);
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(first.find('.avatar').attributes('src')).toBe(users[0].avatarUrl);
|
2021-01-03 14:25:43 +05:30
|
|
|
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 reviewers', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const users = [usersMock(), usersMock(2)];
|
2021-01-03 14:25:43 +05:30
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(wrapper.findAll('[data-testid="reviewer"]').length).toBe(users.length);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows sorted reviewer where "can merge" users are sorted first', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const users = [usersMock(), usersMock(2), usersMock(3)];
|
|
|
|
users[0].mergeRequestInteraction.canMerge = false;
|
|
|
|
users[1].mergeRequestInteraction.canMerge = false;
|
|
|
|
users[2].mergeRequestInteraction.canMerge = true;
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.vm.sortedReviewers[0].mergeRequestInteraction.canMerge).toBe(true);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the sorted reviewers to the uncollapsed-reviewer-list', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const users = [usersMock(), usersMock(2), usersMock(3)];
|
|
|
|
users[0].mergeRequestInteraction.canMerge = false;
|
|
|
|
users[1].mergeRequestInteraction.canMerge = false;
|
|
|
|
users[2].mergeRequestInteraction.canMerge = true;
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
const userItems = wrapper.findAll('[data-testid="reviewer"]');
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(userItems.length).toBe(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the sorted reviewers to the collapsed-reviewer-list', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const users = [usersMock(), usersMock(2), usersMock(3)];
|
|
|
|
users[0].mergeRequestInteraction.canMerge = false;
|
|
|
|
users[1].mergeRequestInteraction.canMerge = false;
|
|
|
|
users[2].mergeRequestInteraction.canMerge = true;
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
...getDefaultProps(),
|
|
|
|
users,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsedButton = wrapper.find('.sidebar-collapsed-user button');
|
|
|
|
|
|
|
|
expect(trimText(collapsedButton.text())).toBe(users[2].name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|