2018-03-17 18:26:18 +05:30
|
|
|
import GroupsStore from '~/groups/store/groups_store';
|
|
|
|
import {
|
2018-12-13 13:39:08 +05:30
|
|
|
mockGroups,
|
|
|
|
mockSearchedGroups,
|
|
|
|
mockParentGroupItem,
|
|
|
|
mockRawChildren,
|
2018-03-17 18:26:18 +05:30
|
|
|
mockRawPageInfo,
|
|
|
|
} from '../mock_data';
|
|
|
|
|
|
|
|
describe('ProjectsStore', () => {
|
|
|
|
describe('constructor', () => {
|
|
|
|
it('should initialize default state', () => {
|
|
|
|
let store;
|
|
|
|
|
|
|
|
store = new GroupsStore();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(Object.keys(store.state).length).toBe(2);
|
|
|
|
expect(Array.isArray(store.state.groups)).toBeTruthy();
|
|
|
|
expect(Object.keys(store.state.pageInfo).length).toBe(0);
|
|
|
|
expect(store.hideProjects).not.toBeDefined();
|
|
|
|
|
|
|
|
store = new GroupsStore(true);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.hideProjects).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setGroups', () => {
|
|
|
|
it('should set groups to state', () => {
|
|
|
|
const store = new GroupsStore();
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(store, 'formatGroupItem');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
store.setGroups(mockGroups);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.state.groups.length).toBe(mockGroups.length);
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.formatGroupItem).toHaveBeenCalledWith(expect.any(Object));
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setSearchedGroups', () => {
|
|
|
|
it('should set searched groups to state', () => {
|
|
|
|
const store = new GroupsStore();
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(store, 'formatGroupItem');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
store.setSearchedGroups(mockSearchedGroups);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.state.groups.length).toBe(mockSearchedGroups.length);
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.formatGroupItem).toHaveBeenCalledWith(expect.any(Object));
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1);
|
|
|
|
expect(Object.keys(store.state.groups[0].children[0]).indexOf('fullName')).toBeGreaterThan(
|
|
|
|
-1,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setGroupChildren', () => {
|
|
|
|
it('should set children to group item in state', () => {
|
|
|
|
const store = new GroupsStore();
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(store, 'formatGroupItem');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
store.setGroupChildren(mockParentGroupItem, mockRawChildren);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.formatGroupItem).toHaveBeenCalledWith(expect.any(Object));
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(mockParentGroupItem.children.length).toBe(1);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(Object.keys(mockParentGroupItem.children[0]).indexOf('fullName')).toBeGreaterThan(-1);
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(mockParentGroupItem.isOpen).toBeTruthy();
|
|
|
|
expect(mockParentGroupItem.isChildrenLoading).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setPaginationInfo', () => {
|
|
|
|
it('should parse and set pagination info in state', () => {
|
|
|
|
const store = new GroupsStore();
|
|
|
|
|
|
|
|
store.setPaginationInfo(mockRawPageInfo);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.state.pageInfo.perPage).toBe(10);
|
|
|
|
expect(store.state.pageInfo.page).toBe(10);
|
|
|
|
expect(store.state.pageInfo.total).toBe(10);
|
|
|
|
expect(store.state.pageInfo.totalPages).toBe(10);
|
|
|
|
expect(store.state.pageInfo.nextPage).toBe(10);
|
|
|
|
expect(store.state.pageInfo.previousPage).toBe(10);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('formatGroupItem', () => {
|
|
|
|
it('should parse group item object and return updated object', () => {
|
|
|
|
let store;
|
|
|
|
let updatedGroupItem;
|
|
|
|
|
|
|
|
store = new GroupsStore();
|
|
|
|
updatedGroupItem = store.formatGroupItem(mockRawChildren[0]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1);
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].children_count);
|
|
|
|
expect(updatedGroupItem.isChildrenLoading).toBe(false);
|
|
|
|
expect(updatedGroupItem.isBeingRemoved).toBe(false);
|
|
|
|
|
|
|
|
store = new GroupsStore(true);
|
|
|
|
updatedGroupItem = store.formatGroupItem(mockRawChildren[0]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1);
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].subgroup_count);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeGroup', () => {
|
|
|
|
it('should remove children from group item in state', () => {
|
|
|
|
const store = new GroupsStore();
|
2020-05-24 23:13:21 +05:30
|
|
|
const rawParentGroup = { ...mockGroups[0] };
|
|
|
|
const rawChildGroup = { ...mockGroups[1] };
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
store.setGroups([rawParentGroup]);
|
|
|
|
store.setGroupChildren(store.state.groups[0], [rawChildGroup]);
|
|
|
|
const childItem = store.state.groups[0].children[0];
|
|
|
|
|
|
|
|
store.removeGroup(childItem, store.state.groups[0]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.state.groups[0].children.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|