2021-01-29 00:20:46 +05:30
|
|
|
import { GlModal, GlLoadingIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2020-05-24 23:13:21 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2018-03-17 18:26:18 +05:30
|
|
|
import appComponent from '~/groups/components/app.vue';
|
|
|
|
import groupFolderComponent from '~/groups/components/group_folder.vue';
|
|
|
|
import groupItemComponent from '~/groups/components/group_item.vue';
|
|
|
|
import eventHub from '~/groups/event_hub';
|
|
|
|
import GroupsService from '~/groups/service/groups_service';
|
2021-03-11 19:13:27 +05:30
|
|
|
import GroupsStore from '~/groups/store/groups_store';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
import {
|
|
|
|
HTTP_STATUS_BAD_REQUEST,
|
|
|
|
HTTP_STATUS_FORBIDDEN,
|
|
|
|
HTTP_STATUS_INTERNAL_SERVER_ERROR,
|
|
|
|
HTTP_STATUS_OK,
|
|
|
|
} from '~/lib/utils/http_status';
|
2020-05-24 23:13:21 +05:30
|
|
|
import * as urlUtilities from '~/lib/utils/url_utility';
|
2022-07-23 23:45:48 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
import {
|
2018-11-20 20:47:30 +05:30
|
|
|
mockEndpoint,
|
|
|
|
mockGroups,
|
|
|
|
mockSearchedGroups,
|
|
|
|
mockRawPageInfo,
|
|
|
|
mockParentGroupItem,
|
|
|
|
mockRawChildren,
|
|
|
|
mockChildren,
|
|
|
|
mockPageInfo,
|
2018-03-17 18:26:18 +05:30
|
|
|
} from '../mock_data';
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const $toast = {
|
|
|
|
show: jest.fn(),
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
2023-05-27 22:25:52 +05:30
|
|
|
jest.mock('~/alert');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('AppComponent', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
let wrapper;
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
2020-05-24 23:13:21 +05:30
|
|
|
let mock;
|
|
|
|
let getGroupsSpy;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const store = new GroupsStore({ hideProjects: false });
|
2021-01-29 00:20:46 +05:30
|
|
|
const service = new GroupsService(mockEndpoint);
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const createShallowComponent = ({ propsData = {} } = {}) => {
|
2021-01-29 00:20:46 +05:30
|
|
|
store.state.pageInfo = mockPageInfo;
|
2023-03-04 22:38:38 +05:30
|
|
|
wrapper = shallowMountExtended(appComponent, {
|
2021-01-29 00:20:46 +05:30
|
|
|
propsData: {
|
|
|
|
store,
|
|
|
|
service,
|
2022-07-23 23:45:48 +05:30
|
|
|
hideProjects: false,
|
|
|
|
containerId: 'js-groups-tree',
|
|
|
|
...propsData,
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
2023-03-04 22:38:38 +05:30
|
|
|
scopedSlots: {
|
|
|
|
'empty-state': '<div data-testid="empty-state" />',
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
mocks: {
|
|
|
|
$toast,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
vm = wrapper.vm;
|
|
|
|
};
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
mock = new AxiosMockAdapter(axios);
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet('/dashboard/groups.json').reply(HTTP_STATUS_OK, mockGroups);
|
2021-03-11 19:13:27 +05:30
|
|
|
Vue.component('GroupFolder', groupFolderComponent);
|
|
|
|
Vue.component('GroupItem', groupItemComponent);
|
2023-03-04 22:38:38 +05:30
|
|
|
setWindowLocation('?filter=foobar');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
document.body.innerHTML = `
|
|
|
|
<div id="js-groups-tree">
|
|
|
|
<div class="empty-state hidden" data-testid="legacy-empty-state">
|
|
|
|
<p>There are no projects shared with this group yet</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
createShallowComponent();
|
2020-05-24 23:13:21 +05:30
|
|
|
getGroupsSpy = jest.spyOn(vm.service, 'getGroups');
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('fetchGroups', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should call `getGroups` with all the params provided', () => {
|
|
|
|
return vm
|
|
|
|
.fetchGroups({
|
|
|
|
parentId: 1,
|
|
|
|
page: 2,
|
|
|
|
filterGroupsBy: 'git',
|
|
|
|
sortBy: 'created_desc',
|
|
|
|
archived: true,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(getGroupsSpy).toHaveBeenCalledWith(1, 2, 'git', 'created_desc', true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set headers to store for building pagination info when called with `updatePagination`', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet('/dashboard/groups.json').reply(HTTP_STATUS_OK, { headers: mockRawPageInfo });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
jest.spyOn(vm, 'updatePagination').mockImplementation(() => {});
|
|
|
|
|
|
|
|
return vm.fetchGroups({ updatePagination: true }).then(() => {
|
|
|
|
expect(getGroupsSpy).toHaveBeenCalled();
|
|
|
|
expect(vm.updatePagination).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('should show an alert when request fails', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet('/dashboard/groups.json').reply(HTTP_STATUS_BAD_REQUEST);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.fetchGroups({}).then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isLoading).toBe(false);
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'smooth', top: 0 });
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(createAlert).toHaveBeenCalledWith({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: 'An error occurred. Please try again.',
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchAllGroups', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(vm, 'fetchGroups');
|
|
|
|
jest.spyOn(vm, 'updateGroups');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should fetch default set of groups', () => {
|
|
|
|
jest.spyOn(vm, 'updatePagination');
|
|
|
|
|
|
|
|
const fetchPromise = vm.fetchAllGroups();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isLoading).toBe(true);
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
return fetchPromise.then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isLoading).toBe(false);
|
|
|
|
expect(vm.updateGroups).toHaveBeenCalled();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should fetch matching set of groups when app is loaded with search query', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet('/dashboard/groups.json').reply(HTTP_STATUS_OK, mockSearchedGroups);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const fetchPromise = vm.fetchAllGroups();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.fetchGroups).toHaveBeenCalledWith({
|
|
|
|
page: null,
|
2023-03-04 22:38:38 +05:30
|
|
|
filterGroupsBy: 'foobar',
|
2018-03-17 18:26:18 +05:30
|
|
|
sortBy: null,
|
|
|
|
updatePagination: true,
|
|
|
|
archived: null,
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
return fetchPromise.then(() => {
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(vm.updateGroups).toHaveBeenCalledWith(mockSearchedGroups, true);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchPage', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(vm, 'fetchGroups');
|
|
|
|
jest.spyOn(vm, 'updateGroups');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should fetch groups for provided page details and update window state', () => {
|
|
|
|
jest.spyOn(urlUtilities, 'mergeUrlParams');
|
|
|
|
jest.spyOn(window.history, 'replaceState').mockImplementation(() => {});
|
2021-03-08 18:12:59 +05:30
|
|
|
jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
const fetchPagePromise = vm.fetchPage({
|
|
|
|
page: 2,
|
|
|
|
filterGroupsBy: null,
|
|
|
|
sortBy: null,
|
|
|
|
archived: true,
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isLoading).toBe(true);
|
|
|
|
expect(vm.fetchGroups).toHaveBeenCalledWith({
|
|
|
|
page: 2,
|
|
|
|
filterGroupsBy: null,
|
|
|
|
sortBy: null,
|
|
|
|
updatePagination: true,
|
|
|
|
archived: true,
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
return fetchPagePromise.then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isLoading).toBe(false);
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'smooth', top: 0 });
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(urlUtilities.mergeUrlParams).toHaveBeenCalledWith({ page: 2 }, expect.any(String));
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(window.history.replaceState).toHaveBeenCalledWith(
|
|
|
|
{
|
2020-05-24 23:13:21 +05:30
|
|
|
page: expect.any(String),
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
expect.any(String),
|
|
|
|
expect.any(String),
|
2018-11-20 20:47:30 +05:30
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.updateGroups).toHaveBeenCalled();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleChildren', () => {
|
|
|
|
let groupItem;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
groupItem = { ...mockParentGroupItem };
|
2018-03-17 18:26:18 +05:30
|
|
|
groupItem.isOpen = false;
|
|
|
|
groupItem.isChildrenLoading = false;
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should fetch children of given group and expand it if group is collapsed and children are not loaded', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet('/dashboard/groups.json').reply(HTTP_STATUS_OK, mockRawChildren);
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'fetchGroups');
|
|
|
|
jest.spyOn(vm.store, 'setGroupChildren').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.toggleChildren(groupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(groupItem.isChildrenLoading).toBe(true);
|
|
|
|
expect(vm.fetchGroups).toHaveBeenCalledWith({
|
|
|
|
parentId: groupItem.id,
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
return waitForPromises().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.setGroupChildren).toHaveBeenCalled();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should skip network request while expanding group if children are already loaded', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'fetchGroups');
|
2018-03-17 18:26:18 +05:30
|
|
|
groupItem.children = mockRawChildren;
|
|
|
|
|
|
|
|
vm.toggleChildren(groupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.fetchGroups).not.toHaveBeenCalled();
|
|
|
|
expect(groupItem.isOpen).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should collapse group if it is already expanded', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'fetchGroups');
|
2018-03-17 18:26:18 +05:30
|
|
|
groupItem.isOpen = true;
|
|
|
|
|
|
|
|
vm.toggleChildren(groupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.fetchGroups).not.toHaveBeenCalled();
|
|
|
|
expect(groupItem.isOpen).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should set `isChildrenLoading` back to `false` if load request fails', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet('/dashboard/groups.json').reply(HTTP_STATUS_BAD_REQUEST);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.toggleChildren(groupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(groupItem.isChildrenLoading).toBe(true);
|
2020-05-24 23:13:21 +05:30
|
|
|
return waitForPromises().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(groupItem.isChildrenLoading).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showLeaveGroupModal', () => {
|
|
|
|
it('caches candidate group (as props) which is to be left', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const group = { ...mockParentGroupItem };
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup).toBe(null);
|
|
|
|
expect(vm.targetParentGroup).toBe(null);
|
|
|
|
vm.showLeaveGroupModal(group, mockParentGroupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(vm.isModalVisible).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup).not.toBe(null);
|
|
|
|
expect(vm.targetParentGroup).not.toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates props which show modal confirmation dialog', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const group = { ...mockParentGroupItem };
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.groupLeaveConfirmationMessage).toBe('');
|
|
|
|
vm.showLeaveGroupModal(group, mockParentGroupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(vm.isModalVisible).toBe(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(vm.groupLeaveConfirmationMessage).toBe(
|
|
|
|
`Are you sure you want to leave the "${group.fullName}" group?`,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('leaveGroup', () => {
|
|
|
|
let groupItem;
|
|
|
|
let childGroupItem;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
groupItem = { ...mockParentGroupItem };
|
2018-03-17 18:26:18 +05:30
|
|
|
groupItem.children = mockChildren;
|
2018-11-08 19:23:39 +05:30
|
|
|
[childGroupItem] = groupItem.children;
|
2018-03-17 18:26:18 +05:30
|
|
|
groupItem.isChildrenLoading = false;
|
|
|
|
vm.targetGroup = childGroupItem;
|
|
|
|
vm.targetParentGroup = groupItem;
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('hides modal confirmation leave group and remove group item from tree', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const notice = `You left the "${childGroupItem.fullName}" group.`;
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.service, 'leaveGroup').mockResolvedValue({ data: { notice } });
|
|
|
|
jest.spyOn(vm.store, 'removeGroup');
|
2021-03-08 18:12:59 +05:30
|
|
|
jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.leaveGroup();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup.isBeingRemoved).toBe(true);
|
|
|
|
expect(vm.service.leaveGroup).toHaveBeenCalledWith(vm.targetGroup.leavePath);
|
2020-05-24 23:13:21 +05:30
|
|
|
return waitForPromises().then(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'smooth', top: 0 });
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.removeGroup).toHaveBeenCalledWith(vm.targetGroup, vm.targetParentGroup);
|
2021-01-29 00:20:46 +05:30
|
|
|
expect($toast.show).toHaveBeenCalledWith(notice);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('should show error alert if request failed to leave group', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const message = 'An error occurred. Please try again.';
|
2023-04-23 21:23:45 +05:30
|
|
|
jest
|
|
|
|
.spyOn(vm.service, 'leaveGroup')
|
|
|
|
.mockRejectedValue({ status: HTTP_STATUS_INTERNAL_SERVER_ERROR });
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'removeGroup');
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.leaveGroup();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup.isBeingRemoved).toBe(true);
|
|
|
|
expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath);
|
2020-05-24 23:13:21 +05:30
|
|
|
return waitForPromises().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.removeGroup).not.toHaveBeenCalled();
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(createAlert).toHaveBeenCalledWith({ message });
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup.isBeingRemoved).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('shows appropriate error alert if request forbids to leave group', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const message = 'Failed to leave the group. Please make sure you are not the only owner.';
|
2023-04-23 21:23:45 +05:30
|
|
|
jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: HTTP_STATUS_FORBIDDEN });
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'removeGroup');
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.leaveGroup(childGroupItem, groupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup.isBeingRemoved).toBe(true);
|
|
|
|
expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath);
|
2020-05-24 23:13:21 +05:30
|
|
|
return waitForPromises().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.removeGroup).not.toHaveBeenCalled();
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(createAlert).toHaveBeenCalledWith({ message });
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.targetGroup.isBeingRemoved).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updatePagination', () => {
|
|
|
|
it('should set pagination info to store from provided headers', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'setPaginationInfo').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.updatePagination(mockRawPageInfo);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.setPaginationInfo).toHaveBeenCalledWith(mockRawPageInfo);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateGroups', () => {
|
|
|
|
it('should call setGroups on store if method was called directly', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'setGroups').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.updateGroups(mockGroups);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.setGroups).toHaveBeenCalledWith(mockGroups);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call setSearchedGroups on store if method was called with fromSearch param', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'setSearchedGroups').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.updateGroups(mockGroups, true);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.setSearchedGroups).toHaveBeenCalledWith(mockGroups);
|
|
|
|
});
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
describe.each`
|
2023-03-04 22:38:38 +05:30
|
|
|
groups | fromSearch | shouldRenderEmptyState | shouldRenderSearchEmptyState
|
|
|
|
${[]} | ${false} | ${true} | ${false}
|
|
|
|
${mockGroups} | ${false} | ${false} | ${false}
|
|
|
|
${[]} | ${true} | ${false} | ${true}
|
2022-07-23 23:45:48 +05:30
|
|
|
`(
|
2023-03-04 22:38:38 +05:30
|
|
|
'when `groups` is $groups, and `fromSearch` is $fromSearch',
|
|
|
|
({ groups, fromSearch, shouldRenderEmptyState, shouldRenderSearchEmptyState }) => {
|
2022-11-25 23:54:43 +05:30
|
|
|
it(`${shouldRenderEmptyState ? 'renders' : 'does not render'} empty state`, async () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
createShallowComponent();
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
vm.updateGroups(groups, fromSearch);
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(wrapper.findByTestId('empty-state').exists()).toBe(shouldRenderEmptyState);
|
|
|
|
expect(wrapper.findByTestId('search-empty-state').exists()).toBe(
|
|
|
|
shouldRenderSearchEmptyState,
|
|
|
|
);
|
2022-07-23 23:45:48 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('created', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should bind event listeners on eventHub', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(eventHub, '$on').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
createShallowComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith('fetchPage', expect.any(Function));
|
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith('toggleChildren', expect.any(Function));
|
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith('showLeaveGroupModal', expect.any(Function));
|
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith('updatePagination', expect.any(Function));
|
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith('updateGroups', expect.any(Function));
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith(
|
|
|
|
'fetchFilteredAndSortedGroups',
|
|
|
|
expect.any(Function),
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('beforeDestroy', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should unbind event listeners on eventHub', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(eventHub, '$off').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
createShallowComponent();
|
|
|
|
wrapper.destroy();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith('fetchPage', expect.any(Function));
|
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith('toggleChildren', expect.any(Function));
|
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith('showLeaveGroupModal', expect.any(Function));
|
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith('updatePagination', expect.any(Function));
|
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith('updateGroups', expect.any(Function));
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith(
|
|
|
|
'fetchFilteredAndSortedGroups',
|
|
|
|
expect.any(Function),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when `fetchFilteredAndSortedGroups` event is emitted', () => {
|
|
|
|
const search = 'Foo bar';
|
|
|
|
const sort = 'created_asc';
|
|
|
|
const emitFetchFilteredAndSortedGroups = () => {
|
|
|
|
eventHub.$emit('fetchFilteredAndSortedGroups', {
|
|
|
|
filterGroupsBy: search,
|
|
|
|
sortBy: sort,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
let setPaginationInfoSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setPaginationInfoSpy = jest.spyOn(GroupsStore.prototype, 'setPaginationInfo');
|
|
|
|
createShallowComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading icon', async () => {
|
|
|
|
emitFetchFilteredAndSortedGroups();
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls API with expected params', () => {
|
|
|
|
emitFetchFilteredAndSortedGroups();
|
|
|
|
|
|
|
|
expect(getGroupsSpy).toHaveBeenCalledWith(undefined, undefined, search, sort, undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates pagination', () => {
|
|
|
|
emitFetchFilteredAndSortedGroups();
|
|
|
|
|
|
|
|
expect(setPaginationInfoSpy).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should render loading icon', async () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.isLoading = true;
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should render groups tree', async () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.store.state.groups = [mockParentGroupItem];
|
|
|
|
vm.isLoading = false;
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(vm.$el.querySelector('.groups-list-tree-container')).toBeDefined();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('renders modal confirmation dialog', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
createShallowComponent();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findGlModal = wrapper.findComponent(GlModal);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(findGlModal.exists()).toBe(true);
|
|
|
|
expect(findGlModal.attributes('title')).toBe('Are you sure?');
|
|
|
|
expect(findGlModal.props('actionPrimary').text).toBe('Leave group');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|