2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
import groupFolderComponent from '~/groups/components/group_folder.vue';
|
|
|
|
import groupItemComponent from '~/groups/components/group_item.vue';
|
|
|
|
import { mockGroups, mockParentGroupItem } from '../mock_data';
|
|
|
|
|
|
|
|
const createComponent = (groups = mockGroups, parentGroup = mockParentGroupItem) => {
|
|
|
|
const Component = Vue.extend(groupFolderComponent);
|
|
|
|
|
|
|
|
return new Component({
|
|
|
|
propsData: {
|
|
|
|
groups,
|
|
|
|
parentGroup,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('GroupFolderComponent', () => {
|
|
|
|
let vm;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
Vue.component('GroupItem', groupItemComponent);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm = createComponent();
|
|
|
|
vm.$mount();
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
describe('hasMoreChildren', () => {
|
|
|
|
it('should return false when childrenCount of group is less than MAX_CHILDREN_COUNT', () => {
|
|
|
|
expect(vm.hasMoreChildren).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('moreChildrenStats', () => {
|
|
|
|
it('should return message with count of excess children over MAX_CHILDREN_COUNT limit', () => {
|
|
|
|
expect(vm.moreChildrenStats).toBe('3 more items');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should render component template correctly', () => {
|
|
|
|
expect(vm.$el.classList.contains('group-list-tree')).toBeTruthy();
|
|
|
|
expect(vm.$el.querySelectorAll('li.group-row').length).toBe(7);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render more children link when groups list has children over MAX_CHILDREN_COUNT limit', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const parentGroup = { ...mockParentGroupItem };
|
2018-03-17 18:26:18 +05:30
|
|
|
parentGroup.childrenCount = 21;
|
|
|
|
|
|
|
|
const newVm = createComponent(mockGroups, parentGroup);
|
|
|
|
newVm.$mount();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(newVm.$el.querySelector('li.group-row a.has-more-items')).toBeDefined();
|
|
|
|
newVm.$destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|