2021-04-29 21:17:54 +05:30
|
|
|
import { GlSearchBoxByType, GlDropdown } from '@gitlab/ui';
|
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import { nextTick } from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { IssuableType } from '~/issue_show/constants';
|
|
|
|
import SidebarAssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
|
|
|
|
import IssuableAssignees from '~/sidebar/components/assignees/issuable_assignees.vue';
|
|
|
|
import SidebarAssigneesWidget from '~/sidebar/components/assignees/sidebar_assignees_widget.vue';
|
|
|
|
import SidebarInviteMembers from '~/sidebar/components/assignees/sidebar_invite_members.vue';
|
|
|
|
import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
import getIssueAssigneesQuery from '~/vue_shared/components/sidebar/queries/get_issue_assignees.query.graphql';
|
2021-04-29 21:17:54 +05:30
|
|
|
import updateIssueAssigneesMutation from '~/vue_shared/components/sidebar/queries/update_issue_assignees.mutation.graphql';
|
2021-06-08 01:23:25 +05:30
|
|
|
import UserSelect from '~/vue_shared/components/user_select/user_select.vue';
|
|
|
|
import { issuableQueryResponse, updateIssueAssigneesMutationResponse } from '../../mock_data';
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
jest.mock('~/flash');
|
|
|
|
|
|
|
|
const updateIssueAssigneesMutationSuccess = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(updateIssueAssigneesMutationResponse);
|
|
|
|
const mockError = jest.fn().mockRejectedValue('Error!');
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(VueApollo);
|
|
|
|
|
|
|
|
const initialAssignees = [
|
|
|
|
{
|
|
|
|
id: 'some-user',
|
|
|
|
avatarUrl: 'some-user-avatar',
|
|
|
|
name: 'test',
|
|
|
|
username: 'test',
|
|
|
|
webUrl: '/test',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('Sidebar assignees widget', () => {
|
|
|
|
let wrapper;
|
|
|
|
let fakeApollo;
|
|
|
|
|
|
|
|
const findAssignees = () => wrapper.findComponent(IssuableAssignees);
|
|
|
|
const findRealtimeAssignees = () => wrapper.findComponent(SidebarAssigneesRealtime);
|
|
|
|
const findEditableItem = () => wrapper.findComponent(SidebarEditableItem);
|
|
|
|
const findInviteMembersLink = () => wrapper.findComponent(SidebarInviteMembers);
|
2021-06-08 01:23:25 +05:30
|
|
|
const findUserSelect = () => wrapper.findComponent(UserSelect);
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
const expandDropdown = () => wrapper.vm.$refs.toggle.expand();
|
|
|
|
|
|
|
|
const createComponent = ({
|
|
|
|
issuableQueryHandler = jest.fn().mockResolvedValue(issuableQueryResponse),
|
|
|
|
updateIssueAssigneesMutationHandler = updateIssueAssigneesMutationSuccess,
|
|
|
|
props = {},
|
|
|
|
provide = {},
|
|
|
|
} = {}) => {
|
|
|
|
fakeApollo = createMockApollo([
|
2021-06-08 01:23:25 +05:30
|
|
|
[getIssueAssigneesQuery, issuableQueryHandler],
|
2021-04-29 21:17:54 +05:30
|
|
|
[updateIssueAssigneesMutation, updateIssueAssigneesMutationHandler],
|
|
|
|
]);
|
|
|
|
wrapper = shallowMount(SidebarAssigneesWidget, {
|
|
|
|
localVue,
|
|
|
|
apolloProvider: fakeApollo,
|
|
|
|
propsData: {
|
|
|
|
iid: '1',
|
2021-06-08 01:23:25 +05:30
|
|
|
issuableId: 0,
|
2021-04-29 21:17:54 +05:30
|
|
|
fullPath: '/mygroup/myProject',
|
2021-06-08 01:23:25 +05:30
|
|
|
allowMultipleAssignees: true,
|
2021-04-29 21:17:54 +05:30
|
|
|
...props,
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
canUpdate: true,
|
|
|
|
rootPath: '/',
|
|
|
|
...provide,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
SidebarEditableItem,
|
2021-06-08 01:23:25 +05:30
|
|
|
UserSelect,
|
2021-04-29 21:17:54 +05:30
|
|
|
GlSearchBoxByType,
|
|
|
|
GlDropdown,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.current_username = 'root';
|
|
|
|
gon.current_user_fullname = 'Administrator';
|
|
|
|
gon.current_user_avatar_url = '/root';
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
fakeApollo = null;
|
|
|
|
delete gon.current_username;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with passed initial assignees', () => {
|
|
|
|
it('passes `initialLoading` as false to editable item', () => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
initialAssignees,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findEditableItem().props('initialLoading')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an initial assignees list with initialAssignees prop', () => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
initialAssignees,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findAssignees().props('users')).toEqual(initialAssignees);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a collapsible item title calculated with initial assignees length', () => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
initialAssignees,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findEditableItem().props('title')).toBe('Assignee');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without passed initial assignees', () => {
|
|
|
|
it('passes `initialLoading` as true to editable item', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findEditableItem().props('initialLoading')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders assignees list from API response when resolved', async () => {
|
|
|
|
createComponent();
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(findAssignees().props('users')).toEqual(
|
|
|
|
issuableQueryResponse.data.workspace.issuable.assignees.nodes,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an error when issuable query is rejected', async () => {
|
|
|
|
createComponent({
|
|
|
|
issuableQueryHandler: mockError,
|
|
|
|
});
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: 'An error occurred while fetching participants.',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('assigns current user when clicking `Assign self`', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
findAssignees().vm.$emit('assign-self');
|
|
|
|
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
|
2021-06-08 01:23:25 +05:30
|
|
|
assigneeUsernames: ['root'],
|
2021-04-29 21:17:54 +05:30
|
|
|
fullPath: '/mygroup/myProject',
|
|
|
|
iid: '1',
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
findAssignees()
|
|
|
|
.props('users')
|
|
|
|
.some((user) => user.username === 'root'),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('emits an event with assignees list and issuable id on successful mutation', async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
findAssignees().vm.$emit('assign-self');
|
|
|
|
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
|
2021-06-08 01:23:25 +05:30
|
|
|
assigneeUsernames: ['root'],
|
2021-04-29 21:17:54 +05:30
|
|
|
fullPath: '/mygroup/myProject',
|
|
|
|
iid: '1',
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.emitted('assignees-updated')).toEqual([
|
|
|
|
[
|
2021-09-30 23:02:18 +05:30
|
|
|
{
|
|
|
|
assignees: [
|
|
|
|
{
|
|
|
|
__typename: 'User',
|
|
|
|
avatarUrl:
|
|
|
|
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
|
|
|
|
id: 'gid://gitlab/User/1',
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
webUrl: '/root',
|
|
|
|
status: null,
|
|
|
|
},
|
|
|
|
],
|
2021-11-11 11:23:49 +05:30
|
|
|
id: 'gid://gitlab/Issue/1',
|
2021-09-30 23:02:18 +05:30
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('does not trigger mutation or fire event when editing and exiting without making changes', async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
createComponent();
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
findEditableItem().vm.$emit('open');
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
findEditableItem().vm.$emit('close');
|
|
|
|
|
|
|
|
expect(findEditableItem().props('isDirty')).toBe(false);
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledTimes(0);
|
|
|
|
expect(wrapper.emitted('assignees-updated')).toBe(undefined);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when expanded', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
createComponent();
|
|
|
|
await waitForPromises();
|
|
|
|
expandDropdown();
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('collapses the widget on user select toggle event', async () => {
|
|
|
|
findUserSelect().vm.$emit('toggle');
|
2021-04-29 21:17:54 +05:30
|
|
|
await nextTick();
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findUserSelect().isVisible()).toBe(false);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('calls an update mutation with correct variables on User Select input event', () => {
|
|
|
|
findUserSelect().vm.$emit('input', [{ username: 'root' }]);
|
2021-04-29 21:17:54 +05:30
|
|
|
findEditableItem().vm.$emit('close');
|
|
|
|
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
|
2021-06-08 01:23:25 +05:30
|
|
|
assigneeUsernames: ['root'],
|
2021-04-29 21:17:54 +05:30
|
|
|
fullPath: '/mygroup/myProject',
|
|
|
|
iid: '1',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when multiselect is disabled', () => {
|
|
|
|
beforeEach(async () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({ props: { allowMultipleAssignees: false } });
|
2021-04-29 21:17:54 +05:30
|
|
|
await waitForPromises();
|
|
|
|
expandDropdown();
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('closes a dropdown after User Select input event', async () => {
|
|
|
|
findUserSelect().vm.$emit('input', [{ username: 'root' }]);
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
|
|
|
|
assigneeUsernames: ['root'],
|
|
|
|
fullPath: '/mygroup/myProject',
|
|
|
|
iid: '1',
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
await waitForPromises();
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findUserSelect().isVisible()).toBe(false);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when multiselect is enabled', () => {
|
|
|
|
beforeEach(async () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({ props: { allowMultipleAssignees: true } });
|
2021-04-29 21:17:54 +05:30
|
|
|
await waitForPromises();
|
|
|
|
expandDropdown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not call a mutation when clicking on participants until dropdown is closed', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
findUserSelect().vm.$emit('input', [{ username: 'root' }]);
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).not.toHaveBeenCalled();
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findUserSelect().isVisible()).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
it('calls the mutation old issuable id if `iid` prop was changed', async () => {
|
|
|
|
findUserSelect().vm.$emit('input', [{ username: 'francina.skiles' }]);
|
|
|
|
wrapper.setProps({
|
|
|
|
iid: '2',
|
|
|
|
});
|
|
|
|
await nextTick();
|
|
|
|
findEditableItem().vm.$emit('close');
|
|
|
|
|
|
|
|
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
|
|
|
|
assigneeUsernames: ['francina.skiles'],
|
|
|
|
fullPath: '/mygroup/myProject',
|
|
|
|
iid: '1',
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an error if update assignees mutation is rejected', async () => {
|
|
|
|
createComponent({ updateIssueAssigneesMutationHandler: mockError });
|
|
|
|
await waitForPromises();
|
|
|
|
expandDropdown();
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
findUserSelect().vm.$emit('input', []);
|
2021-04-29 21:17:54 +05:30
|
|
|
findEditableItem().vm.$emit('close');
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: 'An error occurred while updating assignees.',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when user is not signed in', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.current_username = undefined;
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes signedIn prop as false to IssuableAssignees', () => {
|
|
|
|
expect(findAssignees().props('signedIn')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when realtime feature flag is disabled', async () => {
|
|
|
|
createComponent();
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findRealtimeAssignees().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when realtime feature flag is enabled', async () => {
|
|
|
|
createComponent({
|
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
realTimeIssueSidebar: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findRealtimeAssignees().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when making changes to participants list', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes falsy `isDirty` prop to editable item if no changes to selected users were made', () => {
|
|
|
|
expandDropdown();
|
|
|
|
expect(findEditableItem().props('isDirty')).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('passes truthy `isDirty` prop after User Select component emitted an input event', async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
expandDropdown();
|
|
|
|
expect(findEditableItem().props('isDirty')).toBe(false);
|
2021-06-08 01:23:25 +05:30
|
|
|
findUserSelect().vm.$emit('input', []);
|
2021-04-29 21:17:54 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findEditableItem().props('isDirty')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes falsy `isDirty` prop after dropdown is closed', async () => {
|
|
|
|
expandDropdown();
|
2021-06-08 01:23:25 +05:30
|
|
|
findUserSelect().vm.$emit('input', []);
|
2021-04-29 21:17:54 +05:30
|
|
|
findEditableItem().vm.$emit('close');
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findEditableItem().props('isDirty')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render invite members link on non-issue sidebar', async () => {
|
|
|
|
createComponent({ props: { issuableType: IssuableType.MergeRequest } });
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findInviteMembersLink().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('does not render invite members link if `directlyInviteMembers` was not passed', async () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
createComponent();
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findInviteMembersLink().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders invite members link if `directlyInviteMembers` is true', async () => {
|
|
|
|
createComponent({
|
|
|
|
provide: {
|
|
|
|
directlyInviteMembers: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await waitForPromises();
|
|
|
|
expect(findInviteMembersLink().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|