2022-07-05 08:09:46 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import GroupFolder from '~/groups/components/group_folder.vue';
|
|
|
|
import GroupItem from '~/groups/components/group_item.vue';
|
|
|
|
import { MAX_CHILDREN_COUNT } from '~/groups/constants';
|
2017-10-04 10:10:24 -04:00
|
|
|
import { mockGroups, mockParentGroupItem } from '../mock_data';
|
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
describe('GroupFolder component', () => {
|
|
|
|
let wrapper;
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
Vue.component('GroupItem', GroupItem);
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
const findLink = () => wrapper.find('a');
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
const createComponent = ({ groups = mockGroups, parentGroup = mockParentGroupItem } = {}) =>
|
|
|
|
shallowMount(GroupFolder, {
|
|
|
|
propsData: {
|
|
|
|
groups,
|
|
|
|
parentGroup,
|
|
|
|
},
|
|
|
|
});
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
afterEach(() => {
|
2022-07-05 08:09:46 -04:00
|
|
|
wrapper.destroy();
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
it('does not render more children stats link when children count of group is under limit', () => {
|
|
|
|
wrapper = createComponent();
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
expect(findLink().exists()).toBe(false);
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
it('renders text of count of excess children when children count of group is over limit', () => {
|
|
|
|
const childrenCount = MAX_CHILDREN_COUNT + 1;
|
|
|
|
wrapper = createComponent({
|
|
|
|
parentGroup: {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
childrenCount,
|
|
|
|
},
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
expect(findLink().text()).toBe(`${childrenCount} more items`);
|
|
|
|
});
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
it('renders group items', () => {
|
|
|
|
wrapper = createComponent();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2022-07-05 08:09:46 -04:00
|
|
|
expect(wrapper.findAllComponents(GroupItem)).toHaveLength(7);
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
});
|