2019-12-04 20:38:33 +05:30
|
|
|
import '~/flash';
|
2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-10-24 23:57:45 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
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 GroupsStore from '~/groups/store/groups_store';
|
|
|
|
import GroupsService from '~/groups/service/groups_service';
|
2020-05-24 23:13:21 +05:30
|
|
|
import * as urlUtilities from '~/lib/utils/url_utility';
|
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';
|
|
|
|
|
|
|
|
const createComponent = (hideProjects = false) => {
|
|
|
|
const Component = Vue.extend(appComponent);
|
|
|
|
const store = new GroupsStore(false);
|
|
|
|
const service = new GroupsService(mockEndpoint);
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
store.state.pageInfo = mockPageInfo;
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return new Component({
|
|
|
|
propsData: {
|
|
|
|
store,
|
|
|
|
service,
|
|
|
|
hideProjects,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('AppComponent', () => {
|
|
|
|
let vm;
|
2020-05-24 23:13:21 +05:30
|
|
|
let mock;
|
|
|
|
let getGroupsSpy;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mock = new AxiosMockAdapter(axios);
|
|
|
|
mock.onGet('/dashboard/groups.json').reply(200, mockGroups);
|
2018-03-17 18:26:18 +05:30
|
|
|
Vue.component('group-folder', groupFolderComponent);
|
|
|
|
Vue.component('group-item', groupItemComponent);
|
|
|
|
|
|
|
|
vm = createComponent();
|
2020-05-24 23:13:21 +05:30
|
|
|
getGroupsSpy = jest.spyOn(vm.service, 'getGroups');
|
|
|
|
return vm.$nextTick();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('groups', () => {
|
|
|
|
it('should return list of groups from store', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'getGroups').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
const { groups } = vm;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.getGroups).toHaveBeenCalled();
|
|
|
|
expect(groups).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('pageInfo', () => {
|
|
|
|
it('should return pagination info from store', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.store, 'getPaginationInfo').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
const { pageInfo } = vm;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.store.getPaginationInfo).toHaveBeenCalled();
|
|
|
|
expect(pageInfo).not.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
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`', () => {
|
|
|
|
mock.onGet('/dashboard/groups.json').reply(200, { headers: mockRawPageInfo });
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should show flash error when request fails', () => {
|
|
|
|
mock.onGet('/dashboard/groups.json').reply(400);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn($, 'scrollTo').mockImplementation(() => {});
|
|
|
|
jest.spyOn(window, 'Flash').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
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);
|
|
|
|
expect($.scrollTo).toHaveBeenCalledWith(0);
|
|
|
|
expect(window.Flash).toHaveBeenCalledWith('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', () => {
|
|
|
|
mock.onGet('/dashboard/groups.json').reply(200, 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,
|
|
|
|
filterGroupsBy: null,
|
|
|
|
sortBy: null,
|
|
|
|
updatePagination: true,
|
|
|
|
archived: null,
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
return fetchPromise.then(() => {
|
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('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(() => {});
|
|
|
|
jest.spyOn($, 'scrollTo').mockImplementation(() => {});
|
|
|
|
|
|
|
|
const fetchPagePromise = vm.fetchPage(2, null, null, 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);
|
|
|
|
expect($.scrollTo).toHaveBeenCalledWith(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', () => {
|
|
|
|
mock.onGet('/dashboard/groups.json').reply(200, mockRawChildren);
|
|
|
|
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', () => {
|
|
|
|
mock.onGet('/dashboard/groups.json').reply(400);
|
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
|
|
|
|
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.showModal).toBe(false);
|
|
|
|
expect(vm.groupLeaveConfirmationMessage).toBe('');
|
|
|
|
vm.showLeaveGroupModal(group, mockParentGroupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.showModal).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('hideLeaveGroupModal', () => {
|
|
|
|
it('hides modal confirmation which is shown before leaving the group', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const group = { ...mockParentGroupItem };
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.showLeaveGroupModal(group, mockParentGroupItem);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.showModal).toBe(true);
|
|
|
|
vm.hideLeaveGroupModal();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.showModal).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
jest.spyOn(window, 'Flash').mockImplementation(() => {});
|
|
|
|
jest.spyOn($, '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.showModal).toBe(false);
|
|
|
|
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(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect($.scrollTo).toHaveBeenCalledWith(0);
|
|
|
|
expect(vm.store.removeGroup).toHaveBeenCalledWith(vm.targetGroup, vm.targetParentGroup);
|
|
|
|
expect(window.Flash).toHaveBeenCalledWith(notice, 'notice');
|
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 show error flash message if request failed to leave group', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const message = 'An error occurred. Please try again.';
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: 500 });
|
|
|
|
jest.spyOn(vm.store, 'removeGroup');
|
|
|
|
jest.spyOn(window, 'Flash').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(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();
|
|
|
|
expect(window.Flash).toHaveBeenCalledWith(message);
|
|
|
|
expect(vm.targetGroup.isBeingRemoved).toBe(false);
|
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 show appropriate error flash message 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.';
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm.service, 'leaveGroup').mockRejectedValue({ status: 403 });
|
|
|
|
jest.spyOn(vm.store, 'removeGroup');
|
|
|
|
jest.spyOn(window, 'Flash').mockImplementation(() => {});
|
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();
|
|
|
|
expect(window.Flash).toHaveBeenCalledWith(message);
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set `isSearchEmpty` prop based on groups count', () => {
|
|
|
|
vm.updateGroups(mockGroups);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isSearchEmpty).toBe(false);
|
|
|
|
|
|
|
|
vm.updateGroups([]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isSearchEmpty).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('created', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should bind event listeners on eventHub', () => {
|
|
|
|
jest.spyOn(eventHub, '$on').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const newVm = createComponent();
|
|
|
|
newVm.$mount();
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
|
|
|
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));
|
2018-03-17 18:26:18 +05:30
|
|
|
newVm.$destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should initialize `searchEmptyMessage` prop with correct string when `hideProjects` is `false`', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const newVm = createComponent();
|
|
|
|
newVm.$mount();
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(newVm.searchEmptyMessage).toBe('No groups or projects matched your search');
|
2018-03-17 18:26:18 +05:30
|
|
|
newVm.$destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should initialize `searchEmptyMessage` prop with correct string when `hideProjects` is `true`', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const newVm = createComponent(true);
|
|
|
|
newVm.$mount();
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(newVm.searchEmptyMessage).toBe('No groups matched your search');
|
2018-03-17 18:26:18 +05:30
|
|
|
newVm.$destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('beforeDestroy', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should unbind event listeners on eventHub', () => {
|
|
|
|
jest.spyOn(eventHub, '$off').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const newVm = createComponent();
|
|
|
|
newVm.$mount();
|
|
|
|
newVm.$destroy();
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
|
|
|
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));
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should render loading icon', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.isLoading = true;
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.$el.querySelector('.loading-animation')).toBeDefined();
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(vm.$el.querySelector('span').getAttribute('aria-label')).toBe('Loading groups');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should render groups tree', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.store.state.groups = [mockParentGroupItem];
|
|
|
|
vm.isLoading = false;
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.$el.querySelector('.groups-list-tree-container')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('renders modal confirmation dialog', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.groupLeaveConfirmationMessage = 'Are you sure you want to leave the "foo" group?';
|
|
|
|
vm.showModal = true;
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const modalDialogEl = vm.$el.querySelector('.modal');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(modalDialogEl).not.toBe(null);
|
|
|
|
expect(modalDialogEl.querySelector('.modal-title').innerText.trim()).toBe('Are you sure?');
|
|
|
|
expect(modalDialogEl.querySelector('.btn.btn-warning').innerText.trim()).toBe('Leave');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|